TCP-caused exception shutdown means that the normal method for terminating a connection is to send FIN. All queued data in the sending buffer is sent before sending FIN. Normally, no data is lost. However, sometimes we may send an RST packet segment instead of FIN to close a connection. This is called an exception closure. By default, the process closes the socket normally. If you need to disable it abnormally, use the SO_LINGER option to control it. Disabling an abnormal connection has two advantages for the Application: (1) discard any meaningless data to be sent and immediately send the RST packet segment; (2) the receiver of the RST uses the close method to identify whether the other end performs abnormal close or normal close. It is worth noting that the RST packet segment will not cause any response from the other end, and the other end will not be confirmed at all. The party receiving the RST will terminate the connection. The program behavior is as follows:
In the blocking model, the kernel cannot actively notify the application layer of errors. Only when the application layer actively calls IO system calls such as read () or write, the kernel sends an error to the application-layer peer RST. In a non-blocking model, select or epoll returns sockfd readable. When the application layer reads it, read () reports an error in RST. This option is used in the implementation of haproxy.