TCP close/shutdown for network programming socket

Source: Internet
Author: User

Close:

When the socket reference count is 0, the TCP termination sequence of the four groups of connections is triggered;

 

Shutdown:

The normal TCP connection termination sequence is triggered without the reference count of the socket;


Here is a so_linger socket option

Struct linger {

Int l_onoff;/* 0 = OFF, nozero = on */

Int l_linger;/* Linger time, POSIX specifies units as seconds */

};


Shutdown: shut_rd

When the read half of the connection is closed, the process cannot call any read operations on such sockets;

The process can still send data to the socket. The socket receives all data in the buffer zone and then receives any data from the TCP, it has no effect on the socket sending buffer;


Shutdown: shut_wr

Close the write half of the connection, and the process can no longer call any write operations on such sockets;

The process can still receive data from the socket, and the content in the socket sending buffer is sent to the peer end, followed by the normal TCP connection termination sequence (that is, sending fin ), it has no effect on the socket receiving buffer;


Shutdown: shut_rdwr

Disable read and write of connections;


Close: l_onoff = 0 (default ):

No more sending or receiving requests can be sent on the socket. The content in the socket sending buffer is sent to the peer end. If the reference count of the descriptor changes to 0, after the data in the sending buffer is sent, the content in the socket receiving buffer is discarded in the following sequence of TCP connection termination (that is, sending fin;


Close: l_onoff = 1, l_linger = 0:

No more sending or receiving requests can be sent on the socket. If the reference count of the descriptor changes to 0, RST is sent to the peer end, and the connection status is set to closed (no time_wait status ), contents in the socket sending buffer and receiving buffer are discarded;


Close: l_onoff = 1, l_linger! = 0:

No more sending or receiving requests can be sent on the socket. The content in the socket sending buffer is sent to the peer end. If the reference count of the descriptor changes to 0, after the data in the sending buffer is sent, with the normal TCP connection termination sequence (sending fin), the content in the socket receiving buffer is discarded. If the delay time before the connection changes to the closed status is reached, the ewouldblock error is returned;


To be continued ......


Refer:

UNIX Network programmingvolume 1, third edition: thesockets networking API


TCP close/shutdown for network programming socket

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.