gpt4 book ai didi

c++ - WSARecvFrom 阻塞

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:44:25 25 4
gpt4 key购买 nike

由于某些原因,当我调用 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);

最佳答案

WS_OVERLAPPED(值为 0)更改为 WSA_FLAG_OVERLAPPED(值为 1)。您没有正确创建重叠套接字,因此 _recvOverlapWSARecvFrom() 忽略。

关于c++ - WSARecvFrom 阻塞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23795252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com