You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为socat设置无限超时?尝试-T -1未生效求解

Socat 实现无限超时的正确方法

手册中的tail-f风格示例

socat -u \
       /tmp/readdata,seek-end=0,ignoreeof \
       STDIO

该示例用于单向数据传输(-u):socat从/tmp/readdata文件(隐式采用GOPEN地址类型)的当前末尾开始读取数据(seek-end=0),并以类似tail -f的模式持续监听(ignoreeof)。此处的“文件”也可以是处于监听状态的UNIX域套接字(这种场景下不要使用seek相关选项)。

遇到的超时问题

运行上述命令后,程序会很快因无活动超时终止——刚切换到另一终端准备向/tmp/readdata写入内容,socat就已退出。

-T超时选项的手册说明

-T<timeout>
       Total inactivity timeout: when socat is already in the transfer loop and nothing
       has happened for <timeout> [timeval] seconds (no data arrived, no interrupt
       occurred...) then it terminates. Up to version 1.8.0.0 "0" meant "infinite";
       since version 1.8.0.1 "0" means 0 and values <0 mean infinite.
       Useful with protocols like UDP that cannot transfer EOF.

翻译:
总无活动超时:当socat进入传输循环后,若在<timeout>秒内无任何操作(无数据到达、无中断触发等),程序将终止。在1.8.0.0及更早版本中,0表示无限超时;从1.8.0.1版本开始,0代表0秒超时,负数表示无限超时。该选项适用于UDP这类无法传递EOF的协议。

问题分析与解决

测试验证socat -T10 -u /tmp/readdata,seek-end=0,ignoreeof STDIO会在10秒无活动后正常终止,但使用-T -1时未生效——原因是选项格式错误。

手册中明确-T的格式为-T<timeout>,即选项与参数之间不能有空格。正确的无限超时命令应为:

socat -T-1 -u /tmp/readdata,seek-end=0,ignoreeof STDIO

内容的提问来源于stack exchange,提问作者Enlico

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 02:32:01