Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions otsdaq/NetworkUtilities/TCPTransmitterSocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,22 @@ void TCPTransmitterSocket::send(char const* buffer,
<< std::endl;
return;
}
std::size_t sentBytes = ::send(getSocketId(), buffer, size, MSG_NOSIGNAL);
if(sentBytes == static_cast<std::size_t>(-1))
std::size_t totalSent = 0;
while(totalSent < size)
{
ssize_t sentBytes =
::send(getSocketId(), buffer + totalSent, size - totalSent, MSG_NOSIGNAL);
if(sentBytes > 0)
{
totalSent += static_cast<std::size_t>(sentBytes);
continue;
}

if(sentBytes == 0)
{
throw std::runtime_error("Write: returned 0 bytes, connection may be closed");
}

switch(errno)
{
// case EINVAL:
Expand All @@ -62,14 +75,11 @@ void TCPTransmitterSocket::send(char const* buffer,
strerror(errno));
}
case EINTR:
// TODO: Check for user interrupt flags.
// Beyond the scope of this project
// so continue normal operations.
case EAGAIN: {
// Temporary error.
throw std::runtime_error(std::string("Write: temporary error: ") +
strerror(errno));
}
// Interrupted by signal; retry send.
continue;
case EAGAIN:
// Temporary back-pressure; retry send.
continue;
default: {
throw std::runtime_error(std::string("Write: returned -1: ") +
strerror(errno));
Expand Down