为 socket ::send 处理 WSA_IO_PENDING
handling WSA_IO_PENDING for socket ::send
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
来自您链接的文档页面:
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 完成例程。
经过一些研究和实验..
这是一些事实。
::socket 将启用隐式重叠属性。
可以通过 ::WSASocket or via setsocketopt / SO_OPENTYPE 创建套接字 w/o 重叠属性 WSA_FLAG_OVERLAPPED
,但是超时功能(例如 SO_RCVTIMEO
)需要重叠属性。
使用 ::send ::recv a WSA_IO_PENDING error is possible and should be handled with WSAGetOverlappedResult 时(我从 Windows 10 开始观察到这种行为)
或者,使用 ::WSARecv 或 ::WSASend。
还有未解决的问题:
UPDATE: the further question is asked here
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
来自您链接的文档页面:
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 完成例程。
经过一些研究和实验.. 这是一些事实。
::socket 将启用隐式重叠属性。
可以通过 ::WSASocket or via setsocketopt / SO_OPENTYPE 创建套接字 w/o 重叠属性 WSA_FLAG_OVERLAPPED
,但是超时功能(例如 SO_RCVTIMEO
)需要重叠属性。
使用 ::send ::recv a WSA_IO_PENDING error is possible and should be handled with WSAGetOverlappedResult 时(我从 Windows 10 开始观察到这种行为)
或者,使用 ::WSARecv 或 ::WSASend。
还有未解决的问题:
UPDATE: the further question is asked here