Linux:network:tcp: socket option: TCP_USER_TIMEOUT (since Linux 2.6.37);

return setsockopt(sockfd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout, sizeof(timeout));
是无符号整型数据作为参数。如果值大于0,也就是当传输的数据在一定的时间(单位为毫秒)内没有得到回复,就会强制关闭链接,并且返回ETIMEOUT错误给英语。如果是0,就是要系统默认的值。
增加这个值,可以将TCP链接额外存活一段时间,即使没有端到端的链接。减小这个值,可以运行应用更快的感知错误的发生,如果确实是有错误的情况下。如果不设置此值,失败的链接一般需要20多分钟才能真正断掉,根据一般WAN的环境而且是默认值的情况下。
在TCP链接的任何状态都可以设置此值。but is effective only during the synchronized states of a connection (ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, and LAST-ACK). Moreover, when used with the TCP keepalive (SO_KEEPALIVE) option, TCP_USER_TIMEOUT will override keepalive to determine when to close a connection dueto keepalive failure.
当包发生重传的时候,此值无效,当一个keepalive的探测发出去后,此值也不生效。

This option, like many others, will be inherited by the socket returned by accept(2), if it was set on the listening socket. 在accept调用时,这个参数会被继承。

这个超时时,不会向外发送

猜你喜欢

转载自blog.csdn.net/qq_36428903/article/details/131609972