I have a multithreaded SSL server written in C, whose behavior is as follows:
- Main thread waits for client requests (
epoll), accepts them and spawns a detached thread for each client socket - Each thread does
SSL_acceptseparately. After successful SSL handshake, the thread receives messages from the client and responds back with a message for eachSSL_read. - Client threads exit when clients close socket or any error occurs.
I tried simulating concurrent client connections to test the server.
During one such simulation, my server exited with SIGPIPE signal.
Is there a way to catch and handle SIGPIPE at thread level? I want the respective thread to handle the signal instead of the entire process exiting.
Initially I tried signal(SIGPIPE,SIG_IGN), but signal(2) man says:
The effects of signal() in a multithreaded process are unspecified.
Can signalfd be used to handle such SIGPIPEs?
Or are there other solutions?
Note:Server runs on Ubuntu 12.04 and I can't use MSG_NOSIGNAL on send since I am using the OpenSSL as library directly (no source code)
Thanks in advance.