Shutdown and Close of TCP on Linux

Source: Internet
Author: User
For details about TCP Shutdown and Close-Linux Enterprise Application-Linux server application on Linux, see the following. The Linux version is kernel-2.6.21:

1. As long as there is still unread (read) data in the read buffer of the TCP stack, the RST will be sent directly to the peer end when the close call is made.

2. shutdown has nothing to do with the socket descriptor. Even if shutdown (fd, SHUT_RDWR) is called, The fd will not be closed. In the end, close (fd) is required ).

3. It can be considered that shutdown (fd, SHUT_RD) is a null operation, because data can be read from the socket after shutdown, which may need further confirmation.

4. write this socket descriptor after the FIN package has been sent will cause EPIPE/SIGPIPE.

5. When multiple socket descriptors direct to the same socket object, when you call close, the reference count of the object will be decreased first. If the count is 0, the FIN packet will be sent to end the TCP connection. If shutdown is different, the FIN package is sent if it is called in SHUT_WR/SHUT_RDWR mode.

6. SO_LINGER and close. When the SO_LINGER option is enabled but the timeout value is 0, call close to directly send the RST (this can avoid entering the TIME_WAIT status, however, the normal working mode of the TCP protocol is damaged. SO_LINGER has no effect on shutdown.

7. There is no direct relationship between the RST and the possible TIME_WAIT status in the TCP connection. The active FIN package will inevitably enter the TIME_WAIT status, unless the FIN is not sent and the RST is sent directly to end the connection.
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.