在阻塞模式下send函数的返回值是不是永远都不会小于buffer的长度(即传入send的第3个参数)?MSDN里面的“If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.”这句话没看懂,请前辈给解释解释。还有 using getsockopt() to retrieve the value of socket option SO_MAX_MSG_SIZE.——不是说SO_MAX_MSG_SIZE只对UDP有效吗?我做过试验在tcp socket里总是返回0——对吗?请前辈指点,谢谢!

解决方案 »

  1.   

    If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode如果没有可利用的缓冲区为系统传递数据,发送将被阻塞除非Socket是非阻塞模式。
      

  2.   

    1、“If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.”如果在传输系统没有可利用的缓冲区来传递数据,
    则发送将一直被阻塞,直到Socket被设置为非阻塞模式。// 从这个意思看来,你可以在这个过程中设置Socket为非阻塞模式来解决这个问题
    2、using getsockopt() to retrieve the value of socket option SO_MAX_MSG_SIZE.——不是说SO_MAX_MSG_SIZE只对UDP有效吗?//msdn上的原话:
    The send function is used to write outgoing data on a connected socket. For message-oriented sockets, care must be taken not to exceed the maximum packet size of the underlying provider, which can be obtained by using getsockopt to retrieve the value of socket option SO_MAX_MSG_SIZE. If the data is too long to pass atomically through the underlying protocol, the error WSAEMSGSIZE is returned, and no data is transmitted.//这上面好像并没有说明只针对UDP吧!或许有,我没有看到!
      

  3.   

    如果在传输系统没有可利用的“缓冲区”来传递数据,则发送将一直被阻塞,直到Socket被设置为非阻塞模式。——这里所说的“缓冲区”是程序员传递给send函数的第2个参数的哪个buffer还是windows系统提内部供给tcp/ip协议的缓冲区?我做过试验对tcp socket的SO_MAX_MSG_SIZE调用getsockopt() 总是返回0,别人的windows系统也返回0吗?是不是对tcp socket就永远返回0?再请前辈指点,谢谢!
      

  4.   

    Re:——这里所说的“缓冲区”是程序员传递给send函数的第2个参数的哪个buffer还是windows系统提内部供给tcp/ip协议的缓冲区?这里说的“缓冲区”指的是tcp/ip协议栈的缓冲区