send() always interrupted by EPIPE

Posted by Manuel Abeledo on Stack Overflow See other posts from Stack Overflow or by Manuel Abeledo
Published on 2010-04-08T08:34:24Z Indexed on 2010/04/08 8:43 UTC
Read the original article Hit count: 180

Filed under:
|

I've this weird behaviour in a multithreaded server programmed in C under GNU/Linux. While it's sending data, eventually will be interrupted by SIGPIPE. I managed to ignore signals in send() and treat errno after each action because of it.

So, it has two individual sending methods, one that sends a large amount of data at once (or at least tries to), and another that sends a nearly similar amount and slices it in little chunks. Finally, I tried with this to keep it sending data.

do
{
    total_bytes_sent += send(client_sd, output_buf + total_bytes_sent,
                             output_buf_len - total_bytes_sent, MSG_NOSIGNAL);
}
while ((total_bytes_sent < output_buf_len) && (errno != EPIPE));

This ugly piece of code does its work in certain situations, but not always.

I'm pretty sure it's not a hardware or ISP problem, as this server is running in six european servers, four in Germany and two in France.

Any ideas?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about c

    Related posts about linux