zoukankan      html  css  js  c++  java
  • 第十四章 高级I/O函数

    //1.recv 的最后一个参数:
    MSG_WAITALL:
    The receive request will complete only when one of the following events occurs:
    (A):The buffer supplied by the caller is completely full.
    (B):The connection has been closed.
    (C):The request has been canceled or an error occurred.
    Note that if the underlying transport does not support MSG_WAITALL, or if the socket is in a non-blocking mode, 
    then this call will fail with WSAEOPNOTSUPP. Also, if MSG_WAITALL is specified along with MSG_OOB, MSG_PEEK, or MSG_PARTIAL, 
    then this call will fail with WSAEOPNOTSUPP. This flag is not supported on datagram sockets or message-oriented sockets.
    
    MSG_OOB:
    Processes Out Of Band (OOB) data.
    
    MSG_PEEK:
    Peeks at the incoming data. The data is copied into the buffer, but is not removed from the input queue. 
    The function subsequently returns the amount of data that can be read in a single call to the recv (or recvfrom) function,
    which may not be the same as the total amount of data queued on the socket.
    The amount of data that can actually be read in a single call to the recv 
    (or recvfrom) function is limited to the data size written in the send or sendto function call.
    
    MSG_DONTWAIT:
    windows并没有定义此选项
    
    
    //2.send 的最后一个参数
    MSG_DONTROUTE
    Specifies that the data should not be subject to routing. A Windows Sockets service provider can choose to ignore this flag
    
    MSG_OOB
    Sends OOB data (stream-style socket such as SOCK_STREAM only.
    
    
    参考资料:
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms740121(v=vs.85).aspx
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms740149(v=vs.85).aspx
    
    
    //3.accept 的一个注意点
    当 select 应用于 accept 时,客户端在建立连接后立刻响应一个 RST ,并且此时服务端刚好进入 accept 的 select 并且尚未调用 accept 
    对于以上情况,服务端就可能会因为 这个已完成的连接被服务器驱除出队列 而产生阻塞。经测试, windows 下这种情况 accept 也不会被阻塞,
    但是,出于以上考虑,最好对于 监听的 SOCKET 将其设为非阻塞,并在调用 accept 后获取当前错误码进行判断
    

      

  • 相关阅读:
    Java删除文件夹下所有文件
    Java写入文件的几种方法小结
    字符串String数据类型的探讨
    Java把数字格式化为货币字符串
    java.utilDate和java.sql.Date
    Java最小二乘法线性回归函数编码实现
    寄存器
    GCC
    linux zip
    缓存
  • 原文地址:https://www.cnblogs.com/szn409/p/8034997.html
Copyright © 2011-2022 走看看