+ -
当前位置:首页 → 问答吧 → TCP timer 的问题

TCP timer 的问题

时间:2010-08-24

来源:互联网

这里想说的是 TCP keepalive time 和 syn ack timer。
我的版本是 2.6.24的内核,keepalive timer 的定义如下:
  1. static void tcp_keepalive_timer (unsigned long data)
  2. {
  3.         struct sock *sk = (struct sock *) data;
  4.         struct inet_connection_sock *icsk = inet_csk(sk);
  5.         struct tcp_sock *tp = tcp_sk(sk);
  6.         __u32 elapsed;

  7.         /* Only process if socket is not in use. */
  8.         bh_lock_sock(sk);
  9.         if (sock_owned_by_user(sk)) {
  10.                 /* Try again later. */
  11.                 inet_csk_reset_keepalive_timer (sk, HZ/20);
  12.                 goto out;
  13.         }

  14.         if (sk->sk_state == TCP_LISTEN) {
  15.                 tcp_synack_timer(sk);
  16.                 goto out;
  17.         }

  18.         if (sk->sk_state == TCP_FIN_WAIT2 && sock_flag(sk, SOCK_DEAD)) {
  19.                 if (tp->linger2 >= 0) {
  20.                         const int tmo = tcp_fin_time(sk) - TCP_TIMEWAIT_LEN;

  21.                         if (tmo > 0) {
  22.                                 tcp_time_wait(sk, TCP_FIN_WAIT2, tmo);
  23.                                 goto out;
  24.                         }
  25.                 }
  26.                 tcp_send_active_reset(sk, GFP_ATOMIC);
  27.                 goto death;
  28.         }
复制代码
从上面代码16~19行中可以看出,tcp_synack_timer 是在tcp_keepalive_timer中调用的。但是tcp_keepalive_timer的启用是需要应用层socket设置 KEEPALIVE选项的。这样的话,tcp_synack_timer的工作不是受限了吗?
而且,内核代码中没有其他位置调用tcp_synack_timer 。

熟悉的朋友指点一下我是不是那里理解错误了?

作者: Godbach   发布时间: 2010-08-24

你再往下面看代码,这句:
  1. if (!sock_flag(sk, SOCK_KEEPOPEN) || sk->sk_state == TCP_CLOSE)  
  2.         goto out;
复制代码
这个才是判断是否有开启keepalive的.没有开启则直接退出,而此时synack的定时器已经处理了。

作者: simohayha_cu   发布时间: 2010-08-24