Analysis and processing of sigpipe signals in IOS development __c language

Source: Internet
Author: User

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));

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.