The following sections come from network collection. I summed up the content of this blog to make the need for future browsing.
Signal 13 corresponds to Sigpipe, the online interpretation of this signal is this:
The pipe is broken. This signal usually occurs during interprocess communication, such as two processes using FIFO (pipe) communication, the read pipe is not opened or accidentally terminated to the pipeline, write process will receive sigpipe signal. In addition, with socket communication two processes, write process in the write socket, the read process has been terminated.
The internet learned that the use of the socket when the general will receive this sigpipe signal, processing methods are mostly ignored.
We need to detect that the server has turned off the connection and reconnected when send. Normally the Send function returns-1 for sending fails, but sigpipe terminates the process before send returns on iOS, so we need to ignore Sigpipe, let send return normally-1, and then reconnect to the server.
The solution generally has 3
1. is to set up your own handle handler function
2. is directly called signal (Sigpipe, sig_ign) or
struct Sigaction sa;
Sa.sa_handler = sig_ign;
Sigaction (sigpipe, &sa, 0);
to ignore this signal.
3. Socket Ignore Sigpipe
int set = 1; setsockopt (SD, Sol_socket, So_nosigpipe, (void *) &set, sizeof(int));