[C++] Cannot catch SIGPIPE signal
I have a Socket library, written in C++, in which the method used to send data never has the opportunity to handle an errno of SIGPIPE. Thus I thought perhaps I should setup a signal handler to receive the signal, but this too is not being called.
Is there something that I am missing or doing that is completely wrong? Below is the relevant code. Note that a SIGPIPE signal is generated when the Server is unable to send data to the Client (e.g. the client has terminated). Server code: Code:
#include <TCPServerSocket.hpp> Code:
TCPSocket::TCPSocket(int domain, int type, int protocol) Code:
TCPSocket& P.S. I assume it is a SIGPIPE signal that is killing my Server, because that is what gdb reported when I was debugging via ddd. |
Never mind -- I figured out the issue. I had failed to notice that there are two variants of the TCPSocket constructor; of course I failed to setup the signal handler within the constructor that was actually being called by the accept() method.
Also, I found out that it was not necessary to throw an exception from within the signal handler. Once the signal is properly handled (in my case, with a "no-op"), execution returns to the send() method where the return value and errno are examined. Thus a more useful exception is thrown when the error is detected. |
All times are GMT -5. The time now is 01:16 AM. |