Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ WSARecv在socket程序MNG windows中执行大约需要3秒钟?_C++ - Fatal编程技术网

C++ WSARecv在socket程序MNG windows中执行大约需要3秒钟?

C++ WSARecv在socket程序MNG windows中执行大约需要3秒钟?,c++,C++,如何提高WSARecv的性能以尽快完成。它使用重叠和阻塞套接字。 代码如下 WSARecv(*socket, &Buffer, 1, &RecvCount, &Flag, NULL, NULL); 由于套接字被阻塞,我猜远端没有发送任何东西,而WSARecv在等待数据到达时被阻塞 哦,从手册页面: If both lpOverlapped and lpCompletionRoutine are NULL, the socket in this function will

如何提高WSARecv的性能以尽快完成。它使用重叠和阻塞套接字。 代码如下

WSARecv(*socket, &Buffer, 1, &RecvCount, &Flag, NULL, NULL);

由于套接字被阻塞,我猜远端没有发送任何东西,而
WSARecv
在等待数据到达时被阻塞

哦,从手册页面:

If both lpOverlapped and lpCompletionRoutine are NULL, the socket in this
function will be treated as a nonoverlapped socket.

这意味着,虽然套接字可能重叠,但此调用不会将其视为重叠,因为这两个指针都为NULL。您可以使用非阻塞套接字,也可以使用重叠套接字,但不能同时使用两者。

好的,如果我将套接字设置为非阻塞套接字,发送和接收会有问题吗?@Ershad编辑了我的答案。我建议您阅读参考手册页面,正确使用重叠插座,这样通话就不会阻塞了。对不起,我现在知道了。让我检查一下。@Ershad错误为WSAEWOULDBLOCK,这意味着调用将被阻塞,您应该稍后再试。链接在我的答案中。