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