• 第十四章 高级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 后获取当前错误码进行判断
    

      

  • 相关阅读:
    切换某个窗口为当前窗口并显示在最前面---非置顶
    C语言算法-求两直线夹角计算公式
    Qt编译时MinGW去掉对gcc动态库的依赖
    解决不能从 WTL::CString 转换为 ATL::CSimpleString & 的问题
    gcc编译器对宽字符的识别
    4月10日学习笔记——jQuery选择器
    HTML5
    4月8日学习笔记(js基础)
    网站易用性2
    网站易用性
  • 原文地址:https://www.cnblogs.com/szn409/p/8034997.html
Copyright © 2020-2023  润新知