result = ::send(s, buf, length, flag)
最终会发送多少数据?当我得到 result == SOCKET_ERROR
和 WSAGetLastError () == WSA_IO_PENDING
buf
的length
字节最终会全部发送吗?
或者我需要再次尝试重新发送相同的 buf 数据?
另一方面
WSA_IO_PENDING
Overlapped operations will complete later.
The application has initiated an overlapped operation that cannot be completed immediately. A completion indication will be given later when the operation has been completed....
在我看来,发送操作将在稍后完成....
UPDATE: the further question is asked here Unexpected WSA_IO_PENDING from blocking (overlapped I/O) Winsock2 calls
最佳答案
从您链接的文档页面:
If no error occurs, send returns the total number of bytes sent, which can be less than the number requested to be sent in the len parameter. Otherwise, a value of SOCKET_ERROR is returned
也就是说,如果 result == SOCKET_ERROR
那么什么都没有发送。
至于WSA_IO_PENDING
,如果您使用异步 io,它可能会发生,例如 WSASend
.在这种情况下,实际发送的字节数需要稍后检索,可能使用 io 完成例程。
关于c++ - 处理 socket::send 的 WSA_IO_PENDING,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51763378/