Vxworks中TCP服务器端的SO_KEEPALIVE的超时设置

 本文转自: http://blog.csdn.net/zhaozh2000/article/details/6297706

 

这个设置超时时间折腾了我几个小时,真是在尝试中找到的。

 

首先,我们看一段help里的话,我用的是tornado2.2的。

The ETIMEDOUT timeout can happen in two ways. If the connection is not yet established, the KEEPALIVE timer expires after idling for TCPTV_KEEP_INIT. If the connection is established, the KEEPALIVE timer starts up when there is no traffic for TCPTV_KEEP_IDLE. If no response is received from the peer after sending the KEEPALIVE segmentTCPTV_KEEPCNT times with interval TCPTV_KEEPINTVL, TCP assumes that the connection is invalid. The TCPTV_KEEP_INITTCPTV_KEEP_IDLETCPTV_KEEPCNT, andTCPTV_KEEPINTVL parameters are defined in the file target/h/netinet/tcp_timer.h.

 

我们可以见到上面的几个宏很重要的,我们修改也和它们有关。我分了三步修改才成功。

1.我修改vxworks的内核组件:

   在 network components-->networking protocols-->core TCP/IP components-->TCPv4中的Params中,修改

   TCP_CON_TIMEO_DFLT,TCP_IDLE_TIMEO_DFLT,TCP_MAX_PROBE_DFLT,修改后,实验,发现不成功,结果是

   在5分钟后断开,无论我改成多少值。

2.修改tcp_timer.h里的TCPTV_KEEP_IDLETCPTV_KEEPCNT,andTCPTV_KEEPINTVL 这几个宏的值,改小之后实验,

   仍然不行,依旧是5分钟

3.在tcp_timer.h里发现有这样一段:

   #ifndef VIRTUAL_STACK

   extern int tcp_keepidle;                /* time before keepalive probes begin */

   extern int tcp_keepintvl;               /* time between keepalive probes */

   extern int tcp_maxidle;                 /* time to drop after starting probes */

   #endif

   迫于无奈,我便在自己的程序里,修改了它们的值,如下:

   tcp_keepidle = 10;

   tcp_keepintvl = 20;

   tcp_maxidle = 3;

   if (setsockopt(x.tcplistenfd,SOL_SOCKET,SO_KEEPALIVE,(char *)&keepalive,sizeof(keepalive))<0)

  {

    fprintf(stderr,"SO_KEEPALIVE error:%s/n",strerror(errno));

    return;

  }

 

  发现终于不是5分钟了,也符合目标了。

到这里,终于搞定,感觉要尝试很多,呵呵。

积极学习,大胆假设,加油啊!

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值