📄 subject_15574.htm
字号:
<p>
序号:15574 发表者:daibo 发表日期:2002-09-19 13:56:52
<br>主题:send函数问题(急)
<br>内容:TCP协议,调用SEND返回值经常为10035,意思为“无法立即完成一个非阻挡性套接字操作。”请问怎样造成的,怎样解决?谢谢!<BR>一定给分!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:sxho 回复日期:2002-09-19 14:42:36
<br>内容:非阻塞调用。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:Aikoc 回复日期:2002-09-19 19:18:42
<br>内容:10035 即WSAEWOULDBLOCK The socket is marked as nonblocking and the requested operation would block <BR>主要因为你使用的是non-blocking socket.<BR>当你发送数据时因为socket的buffer不够,就会返回此errcode<BR>你只有等socket通知你可以重发数据或你自己检测到socket<BR>可写时,继续发送你的数据.<BR><BR>当你发送大文件时<BR><BR>a.)如果是blocking的socket,你要循环检测每次发送了多少,<BR>并继续发送直至完成<BR><BR>b.)如果是non-blocking,情况比较不同,你要正确处理WSAEWOULDBLOCK<BR><BR>应为socket的内部Buffer有制,所以如果你发大文件需要分多次发。<BR>举个WSAEventSelect的例子,<BR>socket会接受你的data直到Buffer不能处理,此时会发出WSAEWOULDBLOCK.<BR>等socket处理后,socket会通知你可再次发送.<BR>所以你可以使用send发送data,遇到SOCKET_ERROR时要判断一下是不是WSAEWOULDBLOCK,如果是WSAEWOULDBLOCK,等write的Event触发后继续发送<BR>一般使用WSAWaitForMultipleEvents来处理各种socket及自己定义的Event<BR><BR>参看MSDN<BR><BR>==================================================================<BR>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. <BR><BR>The successful completion of a send does not indicate that the data was successfully delivered.<BR><BR>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. On nonblocking stream oriented sockets, the number of bytes written can be between 1 and the requested length, depending on buffer availability on both client and server machines. The select, WSAAsyncSelect or WSAEventSelect functions can be used to determine when it is possible to send more data.<BR>==================================================================<BR>如果用CAsyncSocket可以<BR>CYourAsyncSocket::OnSend( int nErrorCode )<BR>{<BR>...<BR>// 继续发送数据<BR>while(...)<BR>{<BR>result=Send(...);<BR>if (result == SOCKET_ERROR)<BR>{<BR> err = GetLastError();<BR> if(err != WSAEWOULDBLOCK)<BR> OnClose(); //发生错误<BR> else<BR> break;//错误为WSAEWOULDBLOCK时,系统会自动重新SEND()的.<BR>}<BR>}<BR>}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:r0 回复日期:2002-09-19 20:00:11
<br>内容:正常<BR>发而立即发送成功的情况少见,这也是异步 i/o 的一个特征
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:daibo 回复日期:2002-09-20 17:34:40
<br>内容:谢谢 Aikoc 的关于SEND函数返回10035的回复。我已经同意并结贴乐。<BR>但我没有办法解决老是返回这个错误的问题。<BR>因为我的数据是实时生成的,我不能控制这个数据的产生,如果我延迟一段时间再发送,就会造成数据在发送端累积,后面就更容易造成10035的错误。<BR>难道TCP关于这种大量数据的传送阻塞问题没有办法吗?<BR>希望能得到您的指导和帮助。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Aikoc 回复日期:2002-09-20 19:13:05
<br>内容:我已经回信,8-)
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -