I am using a socket library found on the net, but it sometimes crashes due to signal 13...

Why ? What is signal 13 ?


int setIgnoreSignalIfDefault(int inSignalToIgnore)
{
struct sigaction action ;

if (sigaction(inSignalToIgnore, (struct sigaction *)NULL, &action) < 0)
return -1 ;

if (action.sa_handler == SIG_DFL) {
action. sa_handler = SIG_IGN ;
if (sigaction(inSignalToIgnore, &action, (struct sigaction *)NULL) < 0)
return -1 ;
}
return 0 ;
}

return 1 ;
}
setIgnoreSignalIfDefault
will set the signal handler to ignore the signal (SIG_IGN) if the current handler is the default one (SIG_DFL). Returns 0 if successful, 1 if the current handler is not SIG_DFL and -1 in case of error (errno contains the real error number).
int r = setIgnoreSignalIfDefault(SIG_PIPE) ;
if (r < 0) {
NSLog(@"Error %d setting SIG_PIPE to SIG_IGN",errno);
return ;
}

if (r > 0) {
NSLog(@"SIG_PIPE handler already set to something");
return ;
}
Signal 13 is SIGPIPE and this signal is sent to a process when it tries to write to a broken pipe. A broken pipe being a connection closed by the other end.
The only way to prevent the crash is to catch the signal with an handler of yours or just to tell the OS to ignore this particular signal.