什么时候需要TCP选项SO_LINGER(0)? [英] When is TCP option SO_LINGER (0) required?

查看:266
本文介绍了什么时候需要TCP选项SO_LINGER(0)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我了解该选项的正式含义.在我现在处理的一些旧代码中,使用了该选项.客户抱怨RST是从侧面对FIN的响应,是对FIN的响应.

I think I understand the formal meaning of the option. In some legacy code I'm handling now, the option is used. The customer complains about RST as response to FIN from its side on connection close from its side.

我不确定我可以安全地删除它,因为我不知道何时应该使用它.

I am not sure I can remove it safely, since I don't understand when it should be used.

能否请您举例说明何时需要使用该选项?

Can you please give an example of when the option would be required?

推荐答案

SO_LINGER超时设置为零的典型原因是为了避免大量处于TIME_WAIT状态的连接占用所有可用资源在服务器上.

The typical reason to set a SO_LINGER timeout of zero is to avoid large numbers of connections sitting in the TIME_WAIT state, tying up all the available resources on a server.

当TCP连接被完全关闭时,发起关闭的那一端(活动关闭")结束,该连接位于TIME_WAIT中几分钟.因此,如果您的协议是服务器发起关闭连接的协议,并且涉及大量短期连接,那么它很可能会遇到此问题.

When a TCP connection is closed cleanly, the end that initiated the close ("active close") ends up with the connection sitting in TIME_WAIT for several minutes. So if your protocol is one where the server initiates the connection close, and involves very large numbers of short-lived connections, then it might be susceptible to this problem.

这不是一个好主意-尽管TIME_WAIT存在是有原因的(以确保来自旧连接的杂散数据包不会干扰新连接).如果可能的话,最好将协议重新设计为客户端发起连接关闭的协议.

This isn't a good idea, though - TIME_WAIT exists for a reason (to ensure that stray packets from old connections don't interfere with new connections). It's a better idea to redesign your protocol to one where the client initiates the connection close, if possible.

这篇关于什么时候需要TCP选项SO_LINGER(0)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆