I'm currently using a kqueue to handle multiple Clients per Thread in a Serverprocess so I don't want the thread to be terminated when the Signal SIGPIPE appears, i would just like to remove the according socked id from the kqueue. So My question is: Is there a way to get the according socketid inside a Signalhandle and parse it back to the Process to remove it from the event kqueue or would i have jsut to SIG_IGN the SIGPIPE and handle the remove by returning of -1 from send? and would it return the -1 value after a timeout time or returns send -1 instantly?
And finally, if the signal ignore is my solution: where id have to put the declaration of the
typedef void (*sig_t) (int);
sig_t
signal(int sig, sig_t func);
Would it have to be in the main function? or in the beginning of the corresponding thread? or just as global element?
I can't think of an easy way for the signal handler to come to know the current socket being processed unless you are setting some global state each time you do a socket operation.
You can ignore
SIGPIPE
from main. You do not define your own handler, instead you useSIG_IGN
.Or, if you are using
sigaction
:Alternatively, you can issue the
MSG_NOSIGNAL
flag when you call send. This will suppress the generation ofSIGPIPE
, and instead generate anEPIPE
error (which is what would happen if you ignoredSIGPIPE
):'signal( ...' code should be in 'main'.