出于某种原因,当我调用WSARecvFrom时,函数在收到函数之前不会返回。
_socket = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, NULL, WS_OVERLAPPED);
...
sockaddr_in addr = ...
if(bind(_socket, (const sockaddr*)&addr, sizeof(addr)) != EXIT_SUCCESS) { ... }
...
HANDLE _handle = CreateIoCompletionPort((HANDLE)_socket, _ioHandle, NULL, NULL);
...
_recvOverlap->OVERLAP.hEvent = WSACreateEvent();
DWORD sz = 0, flag = 0;
return WSARecvFrom(_socket, _recvBuf, 1, &sz, &flag, (sockaddr*)_recvAddr, &_recvAddrSz, (LPWSAOVERLAPPED)_recvOverlap, NULL);
答案 0 :(得分:2)
将WS_OVERLAPPED
(值为0)更改为WSA_FLAG_OVERLAPPED
(其值为1)。您没有正确创建重叠的套接字,因此_recvOverlap
忽略了WSARecvFrom()
。