如何减少TCP connect()系统调用超时? [英] How to decrease TCP connect() system call timeout?
问题描述
在下面的命令中,我启用文件/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屋!