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

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

问题描述

我想我理解选项的正式含义.在我现在处理的一些遗留代码中,使用了该选项.客户抱怨 RST 作为从其一侧关闭连接时对 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天全站免登陆