- 論壇徽章:
- 0
|
本帖最后由 digdeep126 于 2012-02-27 16:17 編輯
To understand the second reason for the TIME_WAIT state, assume we have a TCP connection between 12.106.32.254 port 1500 and 206.168.112.219 port 21. This connection is closed and then sometime later, we establish another connection between the same IP addresses and ports: 12.106.32.254 port 1500 and 206.168.112.219 port 21. This latter connection is called an incarnation of the previous connection since the IP addresses and ports are the same. TCP must prevent old duplicates from a connection from reappearing at some later time and being misinterpreted as belonging to a new incarnation of the same connection. To do this, TCP will not initiate a new incarnation of a connection that is currently in the TIME_WAIT state. Since the duration of the TIME_WAIT state is twice the MSL, this allows MSL seconds for a packet in one direction to be lost, and another MSL seconds for the reply to be lost. By enforcing this rule, we are guaranteed that when we successfully establish a TCP connection, all old duplicates from previous incarnations of the connection have expired in the network.
There is an exception to this rule. Berkeley-derived implementations will initiate a new incarnation of a connection that is currently in the TIME_WAIT state if the arriving SYN has a sequence number that is "greater than" the ending sequence number from the previous incarnation. Pages 958–959 of TCPv2 talk about this in more detail. This requires the server to perform the active close, since the TIME_WAIT state must exist on the end that receives the next SYN. This capability is used by the rsh command. RFC 1185 [Jacobson, Braden, and Zhang 1990] talks about some pitfalls in doing this.
當(dāng)處于TIME_WAIT狀態(tài)時(shí),不能建立一個(gè)“化身”(也就是與前一個(gè)TCP連接的兩個(gè)IP地址、兩個(gè)端口完全一樣的新的TCP連接)。但是有一個(gè)特例:在BSD實(shí)現(xiàn)的TCP中,如果來(lái)connect() “化身”的第一個(gè)同步 SYN J,它的 J 大于前一個(gè)TCP(也即處于TIME_WAIT的TCP)的序列號(hào)時(shí),即使還處于TIME_WAIT,在這種特殊的情況下還是能夠建立新的“化身”的(也就是不用再TIME_WAIT下去了,而是立刻建立新的TCP連接)。
但是:這種特殊的情況只能是在服務(wù)器端主動(dòng)關(guān)閉時(shí),才可能出現(xiàn),因?yàn)橹挥蟹⻊?wù)器主動(dòng)關(guān)閉,服務(wù)器才能有 TIME_WAIT狀態(tài),而被動(dòng)關(guān)閉是不會(huì)有TIME_WAIT狀態(tài)的。(僅僅是個(gè)人的理解)
|
|