Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sender check for the sendmsg call #2694

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion srtcore/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,32 @@ int srt::CChannel::sendto(const sockaddr_any& addr, CPacket& packet, const socka
}
mh.msg_flags = 0;

const int res = (int)::sendmsg(m_iSocket, &mh, 0);
int res = -1;

// Make sure that the socket is writable. Wait up to 200ms. Exit with error if still not.
fd_set wset;
timeval tv;
FD_ZERO(&wset);
FD_SET(m_iSocket, &wset);
tv.tv_sec = 0;
tv.tv_usec = 200000;
const int select_ret = ::select((int)m_iSocket + 1, NULL, &wset, &wset, &tv);
if (select_ret <= 0)
{
char msg[1024];
LOGC(kslog.Error, log << "CChannel::sendto: select error: "
<< (select_ret ? SysStrError(NET_ERROR, msg, 1024) : "socket not write-ready in 200ms"));
res = -1;
}
else
{
res = (int)::sendmsg(m_iSocket, &mh, 0);
if (res == -1)
{
char msg[1024];
LOGC(kslog.Error, log << "CChannel::sendto: sendmsg error: " << SysStrError(NET_ERROR, msg, 1024));
}
}
#else
DWORD size = (DWORD)(CPacket::HDR_SIZE + packet.getLength());
int addrsize = addr.size();
Expand Down