c++ - 处理 socket::send 的 WSA_IO_PENDING

标签 c++ windows sockets winsock2

result = ::send(s, buf, length, flag)

最终会发送多少数据?当我得到 result == SOCKET_ERRORWSAGetLastError () == WSA_IO_PENDING buflength字节最终会全部发送吗?

或者我需要再次尝试重新发送相同的 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/

相关文章:

c - TCP/IP 客户端发送

java - DataInputStream.read 返回小于 len

没有功能头文件的 C++ 程序编译

c - 在 Windows 上嵌入带有 tkinter 支持的 Python 3.5

c++ - 如何在exe文件中构建C++项目嵌入所有动态链接库?

c++ - 为什么汉字经过编译器会变成乱码?

c - 如何将客户端重新连接到服务器?

c++ - 取决于静态参数包字段的返回类型

c++ - 如何确保在 notify_one 之前调用 wait_for

c++ - 写入和显示图像 OpenCV