views:

60

answers:

1

I am facing a problem in my C++ server program. The request XML comes from the front end (Java) and the back end server (C++) process the request and returns the reply XML.

As part of testing after submitting the request to back-end we killed the Tomcat server. The back-end application (threaded server application) after processing the request failed to sent the response as the Tomcat server was down. The server terminated by throwing the error "received untrapped signal [13] - [SIGPIPE]". We have implemented the sigalrm and sigterm functions.

The above signal error is not captured. Will implementing sigaction help? Also, once the signal is captured what needs to be done to return back to the main loop where the server is listening?

Edit:

We have found that the send() function is having a parameter MSG_NOSIGNAL. On passing this parameter the send function will not thrown the SIGPIPE signal if the connection terminates.

+2  A: 

The easiest thing to do is just ignore the signal:

struct sigaction new_action, old_action;

/* Set up the structure to specify the new action. */
new_action.sa_handler = SIG_IGN;
sigemptyset (&new_action.sa_mask);
new_action.sa_flags = 0;

sigaction(SIGPIPE, &new_action, &old_action);

Once you do this, the read or write call that was causing the signal, it now going to return with an error and your code needs to be prepared to handle that.

R Samuel Klatchko