[#12773] 为 socketInput 添加 TCP_NODELAY 和 SO_REUSEADDR
变更摘要
为命令套接字添加
setReuseAddress(true)和setTcpNoDelay(true)配置。防止快速重启时因套接字处于 TIME_WAIT 状态引发BindException,并禁用 Nagle 算法以消除每次响应高达 40ms 的延迟。
状态 Open · 目标 master ← fix-socketInput
文件 1 · 代码变化 +2 / -0
类型 网络优化 · 错误修复 · 性能提升
主要变更
在
ServerSocket绑定前设置setReuseAddress(true)以防止BindException。在接收客户端连接后设置
setTcpNoDelay(true)以禁用 Nagle 算法。消除命令套接字每次响应高达 40ms 的延迟。
影响范围
服务器控制
命令套接字
网络通信
可能影响
防止快速重启时出现绑定异常
降低命令套接字响应延迟
符合交互式 TCP 命令服务器的标准做法
以上影响分析根据 PR 描述及代码修改推断,不代表维护者正式结论。
重点文件
server/src/mindustry/server/ServerControl.java
修改 · +2 / -0
在
toggleSocket方法中,为serverSocket添加setReuseAddress(true)配置。在接收客户端
Socket后,添加client.setTcpNoDelay(true)配置。
作者说明
setReuseAddress(true)可防止快速重启时(套接字处于 TIME_WAIT 状态)出现BindException。setTcpNoDelay(true)禁用命令套接字上的 Nagle 算法,消除每次响应高达 40ms 的延迟。
交互式 TCP 命令服务器的标准做法。除此之外无其他行为更改。
此修复已在公共服务器上使用,并在更新 website 上的统计数据时应用。
如果您的 pull request 不是与翻译相关的,请阅读以下要求列表并勾选每个复选框:
GitHub 原文
setReuseAddress(true) prevents BindException on quick restarts (socket in TIME_WAIT state)
setTcpNoDelay(true) disables Nagle's algorithm on the command socket, removing up to 40ms of latency per response
Standard practice for interactive TCP command servers. No behavior change otherwise.
This fix is used on the public server and is applied when updating the statistics on the website.
If your pull request is not translation-related, read the list of requirements below and check each box:
I have read the contribution guidelines.
I have ensured that any new features or fixes in this PR function correctly in-game, if applicable.
I affirm that this code follows Mindustry's AI policy.
由 MDT GitHub 同步机器人自动同步。中文翻译、摘要及代码影响分析由 AI 生成,仅供参考。