如何减少 TCP connect() 系统调用超时? [英] How to decrease TCP connect() system call timeout?

查看:42
本文介绍了如何减少 TCP connect() 系统调用超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的命令中,我启用文件 /dev/tcp/10.10.10.1/80 进行读写并将其与文件描述符 3 关联:

In command below I enable file /dev/tcp/10.10.10.1/80 both for reading and writing and associate it with file descriptor 3:

$ time exec 3<>/dev/tcp/10.10.10.1/80
bash: connect: Operation timed out
bash: /dev/tcp/10.10.10.1/80: Operation timed out

real    1m15.151s
user    0m0.000s
sys     0m0.000s

这会自动尝试执行 TCP 三向握手.如果 10.10.10.1 如上例所示无法访问,则 connect 系统调用会尝试连接 75 秒.这个 75 秒超时是否由 bash 决定?还是这个系统默认的?最后但并非最不重要的是,有没有办法减少这个超时值?

This automatically tries to perform TCP three-way handshake. If 10.10.10.1 is not reachable as in example above, then connect system call tries to connect for 75 seconds. Is this 75 second timeout determined by bash? Or is this system default? Last but not least, is there a way to decrease this timeout value?

推荐答案

由 TCP 决定.可以通过应用程序代码在每个套接字的基础上减少.

It is determined by TCP. It can be decreased on a per-socket basis by application code.

NB 超时只有在完全没有响应时才生效.如果出现连接拒绝,则立即发生错误.

NB The timeout only takes effect if there is no response at all. If there is a connection refusal, the error occurs immediately.

这篇关于如何减少 TCP connect() 系统调用超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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