这个设置超时时间折腾了我几个小时,真是在尝试中找到的。
首先,我们看一段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_INIT, TCPTV_KEEP_IDLE, TCPTV_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_IDLE,TCPTV_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分钟了,也符合目标了。
到这里,终于搞定,感觉要尝试很多,呵呵。
积极学习,大胆假设,加油啊!