Reprint: http://blog.csdn.net/chensichensi/article/details/5263132
Regarding the time-wait state only the party initiating the active shutdown enters this state. The exception is that both sides are closed at the same time, and then all go into this state in this state is 2MSL,MSL defined as 30 seconds to 2 minutes, the Linux definition is 30 seconds, so stay 1 minutes if there is data reached in this state, reset the timer.
Time-wait State under the power of the other side closed the connection, there will be no data coming.
Here is the need for the existence of time-wait: for the active shutdown side, the last to send an ACK to the other side to confirm the closure. And this ACK packet is likely to be lost, so set a wait time, if the other side retransmission fin packet can also be sent ACK packet confirmation; Due to the existence of network delay, it is possible for packets to arrive after they have been retransmission packets. At this point, if the connection is closed and the two sides have established a connection with the same address, the packet may be considered as the packet of the connection. With the time-wait, the old connection in this kind of packet disappears in the network predecessor, so it does not occur before the disturbance of the new connection is described.
Time-wait accident (not until the time is forced to end)
RFC793 when the connection is in the Time-wait state, TCP should immediately close the connection if the RST message is accepted.
RFC1337 describes the problem, and the Linux solution is to ignore the RST if you set the Enable rfc1337.
Otherwise, close the connection.
if (Th->rst) {
/* This is time_wait assassination two flavors.
* Oh ... nobody has a sufficient solution to this
* Protocol bug yet.
*/
if (sysctl_tcp_rfc1337 = = 0) {
Kill
Inet_twsk_deschedule (TW, &tcp_death_row);
Inet_twsk_put (TW);
return tcp_tw_success;
}
}
Another occurrence of the scene is man-made, for the so_linger socket option, if set to open linger, and set
Linger time is 0, the RST will occur to time-wait state. Therefore, you must not set this option when you use it.