3

I am using write() on a opened data socket in FTP implementation to send the file out. But after writing some data it is hanging for some time; and after that it is returning with Broken pipe error. any help in this will greatly appreciated. My process reads packets from one buff and writes in to the socket. I noticed this problem with increased bandwidth. If i increased number of packets to be processed then the problem is coming. i am using FreeBSD.

I am using two threads one reads packets and writes in to a buffer ... second thread reads these packets from buffer and writes in to socket.

Thanks For your help Alexander

4
  • You haven't given enough information to diagnose the problem. A good starting point is a minimum compilable piece of code that demonstrates the problem. Aug 12, 2010 at 15:57
  • I am using two threads one reads packets and writes in to a buffer ... second thread reads these packets from buffer and writes in to socket.
    – alexander
    Aug 12, 2010 at 16:25
  • 1
    I have to wonder why you are using threads? Usually programs just read and write, using non-blocking IO and poll or select. Threads will work but introduce so many chances for races and weird bugs...
    – Zan Lynx
    Aug 12, 2010 at 22:03
  • 1
    I am working on multi-threaded real time environment where each thread is a hardware thread. so i have no other choice.
    – alexander
    Sep 17, 2010 at 14:52

2 Answers 2

7

SIGPIPE is sent to your process by the kernel when attempt to write data to a broken pipe is detected. This might happen, for example, if receiving side has closed the socket while you writing, or if socket is accidentally closed from another thread, etc. There are a lot of possible reasons for that. Most applications tend to ignore this signal and handle errors basing on "write" return code because there is nothing reasonable you can do in SIGPIPE signal processing handler. Basically, set SIGPIPE handler to SIG_IGN in order to ignore it and look at a list of possible return codes from "write" system call and handle them accordingly.

4

EPIPE may be set as an error code, and/or SIGPIPE raised (depending on flags), when you attempt to write to a file descriptor that has closed. It is likely that the remote endpoint of your connection has closed, and you've not checked for the close/EOF event (typically returned via the read event when poll/selecting, or a return value of zero from read/recv).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.