Skip to content

Commit

Permalink
Changed writev to sendmsg to prevent SIGPIPE errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidvanErkelens committed Jul 6, 2016
1 parent aad09a1 commit ad9171f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/tcpoutbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,28 @@ class TcpOutBuffer
// update counter for next iteration
if (++index >= 64) break;
}


// create the message header
struct msghdr header;

// make sure the members of the header are empty
memset(&header, 0, sizeof(header));

// save the buffers in the message header
header.msg_iov = buffer;
header.msg_iovlen = index;

// send the data
// @todo use sendmsg() with a MSG_NOSIG flag
auto result = writev(socket, (const struct iovec *)&buffer, index);
auto result = sendmsg(socket, &header, MSG_NOSIGNAL);

// skip on error, or when nothing was written
if (result <= 0) return total > 0 ? total : result;

// shrink the buffer
shrink(result);

// update total number of bytes written
total += 0;
total += result;
}

// done
Expand Down

0 comments on commit ad9171f

Please sign in to comment.