Socket programming-sigpipe Signal Processing

Source: Internet
Author: User

Socket programming problems

Sigpipe signal problem ============================

When the server closes a connection, if the client sends data. According to the TCP protocol, an rst response is received. When the client sends data to the server, the system sends a sigpipe signal to the process, telling the process that the connection has been disconnected, do not write any more.
According to the default signal processing rules, the default operation of the sigpipe signal is terminate (termination, exit), so the client will exit. If you do not want the client to exit, set sigpipe to sig_ign.

For example, signal (sigpipe, sig_ign );
At this time, sigpipe is handed over to the system for processing.

If fork is used on the server, it is necessary to collect the garbage process to prevent the generation of the zombie process. You can handle it like this:
Signal (sigchld, sig_ign); hand it to the system init for recycling.
Here, sub-processes will not generate zombie processes.

Another processing method: sigpipe Signal Processing

Signal (sigpipe, handle_omsignal );

Void handle_omsignal (
Int number)
{
Switch (number)
{
Default:
{
Break;
}
Case sigpipe:
{
Om_alog (error, "omagentd", "% s", "network error! ");
Break;
}
}
}

Of course, this will not happen if the client is not connected to the server.

========================================================== ==========

Processes and threads

: A thread is an execution process of a process. multiple threads run on the process's Resource Platform. If the process is dead, the thread will die.

Socket programming problems

Sigpipe signal problem ============================

When the server closes a connection, if the client sends data. According to the TCP protocol, an rst response is received. When the client sends data to the server, the system sends a sigpipe signal to the process, telling the process that the connection has been disconnected, do not write any more.
According to the default signal processing rules, the default operation of the sigpipe signal is terminate (termination, exit), so the client will exit. If you do not want the client to exit, set sigpipe to sig_ign.

For example, signal (sigpipe, sig_ign );
At this time, sigpipe is handed over to the system for processing.

If fork is used on the server, it is necessary to collect the garbage process to prevent the generation of the zombie process. You can handle it like this:
Signal (sigchld, sig_ign); hand it to the system init for recycling.
Here, sub-processes will not generate zombie processes.

Another processing method: sigpipe Signal Processing

Signal (sigpipe, handle_omsignal );

Void handle_omsignal (
Int number)
{
Switch (number)
{
Default:
{
Break;
}
Case sigpipe:
{
Om_alog (error, "omagentd", "% s", "network error! ");
Break;
}
}
}

Of course, this will not happen if the client is not connected to the server.

========================================================== ==========

Processes and threads

: A thread is an execution process of a process. multiple threads run on the process's Resource Platform. If the process is dead, the thread will die.

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.