- 论坛徽章:
- 15
|
linux_26 发表于 2013-11-07 00:16 ![]()
理论上,在tcp_established状态下,通过tcp_send_fin()向对方发送FIN段后,TCP会立即进入TCP_FIN_WAIT1状态 ...
tcp_shutdown->tcp_close_state
在tcp_close_state函数中:
static int tcp_close_state(struct sock *sk)
{
int next = (int)new_state[sk->sk_state];
int ns = next & TCP_STATE_MASK;
tcp_set_state(sk, ns);
return next & TCP_ACTION_FIN;
}
其中new_state变量
static unsigned char new_state[16] = {
/* current state: new state: action: */
/* (Invalid) */ TCP_CLOSE,
/* TCP_ESTABLISHED */ TCP_FIN_WAIT1 | TCP_ACTION_FIN,
/* TCP_SYN_SENT */ TCP_CLOSE,
/* TCP_SYN_RECV */ TCP_FIN_WAIT1 | TCP_ACTION_FIN,
/* TCP_FIN_WAIT1 */ TCP_FIN_WAIT1,
/* TCP_FIN_WAIT2 */ TCP_FIN_WAIT2,
/* TCP_TIME_WAIT */ TCP_CLOSE,
/* TCP_CLOSE */ TCP_CLOSE,
/* TCP_CLOSE_WAIT */ TCP_LAST_ACK | TCP_ACTION_FIN,
/* TCP_LAST_ACK */ TCP_LAST_ACK,
/* TCP_LISTEN */ TCP_CLOSE,
/* TCP_CLOSING */ TCP_CLOSING,
如果sk->sk_state为1、3、4,则next和ns中都会有TCP_FIN_WAIT1 标记,最后再调用tcp_set_state(sk, ns);
标记就打上了。
|
|