Skip to content

Commit

Permalink
[core] Use overlapped WSASendTo to avoid loss in UDP sending (#2632).
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko authored Jun 29, 2023
1 parent 10e71a6 commit 61c7bed
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions srtcore/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,19 @@ int srt::CChannel::sendto(const sockaddr_any& addr, CPacket& packet, const socka
#else
DWORD size = (DWORD)(CPacket::HDR_SIZE + packet.getLength());
int addrsize = addr.size();
int res = ::WSASendTo(m_iSocket, (LPWSABUF)packet.m_PacketVector, 2, &size, 0, addr.get(), addrsize, NULL, NULL);
res = (0 == res) ? size : -1;
WSAOVERLAPPED overlapped;
SecureZeroMemory((PVOID)&overlapped, sizeof(WSAOVERLAPPED));
int res = ::WSASendTo(m_iSocket, (LPWSABUF)packet.m_PacketVector, 2, &size, 0, addr.get(), addrsize, &overlapped, NULL);

if (res == SOCKET_ERROR && NET_ERROR == WSA_IO_PENDING)
{
DWORD dwFlags = 0;
const bool bCompleted = WSAGetOverlappedResult(m_iSocket, &overlapped, &size, true, &dwFlags);
WSACloseEvent(overlapped.hEvent);
res = bCompleted ? 0 : -1;
}

res = (0 == res) ? size : -1;
#endif

packet.toHL();
Expand Down

0 comments on commit 61c7bed

Please sign in to comment.