Yesterday, there is a program in addition to the problem, debugging when found to be in the socket communication when the other closed the connection occurred broken pipe error. Search on the internet for a while, others explain the reason is to have closed the socket pipe to write data caused by, but my program is closed when the other side continue to recv, Recv will also write to the pipeline data, this question later study it.
It's good to know the problem. Unix system is using signaling mechanism to inform the process of this system error, the default operation of Sigpipe is exit, so in the program to write a signal processing function, do not let the process exit on OK. However, it is noteworthy that after the interception of a signal, the system will signal processing back to the default state, so need to set again. In addition, for multithreading, I was in the main thread to do the signal processing, other threads did not do, but I understand the signal is sent to the process, so it should be only one thread processing the signal can be.
Source:
void initsignal (void);
void handle_signal (int s);
/* when initialized and every time the processing is finished call * *
void initsignal (void)
{
Signal (sigpipe,handle_signal);
}
/* Signal processing function * *
void handle_signal (int s)
{
Initsignal ();
}