Skip to content

Commit

Permalink
[core] Use overlapped WSASendTo to avoid UDP sending losses.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Jan 26, 2023
1 parent 64dedef commit 6db27db
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 @@ -769,8 +769,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 && WSA_IO_PENDING == NET_ERROR)
{
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 6db27db

Please sign in to comment.