Network Programming (5)-SIGPIPE

Transfer: https://blog.csdn.net/u010821666/article/details/81841755
Insert picture description here

Reasons for SIGPIPE

The reason for the SIGPIPE signal:
Simply put, the client program sends a message to the server program, and then closes the client. When the server returns a message, it will receive the SIGPIPE signal from the kernel.
TCP's full-duplex channel is actually two simplex channels. When the client side calls close, although the original intention is to close the two channels, in fact, it can only close the simplex channel that it sends, and it can still receive data. The server side It is still possible to send data without knowing that the client has been completely closed.
The following is a reference:
"'Call the read method on a socket that has received a FIN packet. If the receiving buffer is empty, it returns 0, which is often said to indicate that the connection is closed. But when the write method is called for the first time, if The sending buffer is no problem, and it will return correctly written (sent). But the sent message will cause the opposite end to send an RST message, because the socket of the opposite end has called close and is completely closed, neither sending nor receiving data. So , The write method is called for the second time (assuming after receiving the RST), a SIGPIPE signal will be generated, causing the process to exit."'
Insert picture description here

Guess you like

Origin blog.csdn.net/chengcheng1024/article/details/114965251