本文介绍了我可以得到什么套接字错误时,TCP保持活动中断连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有保活(间隔1分钟),由环(选择读)。
I have a set of TCP sockets with keep-alive (interval 1 min), controlled by a select(2)
loop (selecting for read).
- 威尔
选择(2)
返回一个错误,如果保持活动超时已经发生了? 在设定的插口内 - 哪些错误会
阅读(2)
返回?
- Will
select(2)
return an error if keep-alive timeout has happened for one of the sockets in the set? - Which error will
read(2)
return?
推荐答案
-
选择()
本身是否发出错误信号为它选择为的插口内不会返回一个错误。 [事实上,API无法表示每插槽错误这种方式,因为两个不同的插槽可以每个的单一通话过程中获得挂起的错误选择()
。哪一个会选择()
返回?] - 在
选择()
循环的每次迭代后,您而是使用FD_ISSET宏来尝试阅读()
每个插槽上标示的可读性。 - 任何时候,一个插座有一个挂起的错误集,其读取事件(写事件)的信号,而
选择()
的回报,让你拿起timed-出错误,由于保活立即生效。请注意,选择标记为读套接字并不表示有数据要读取,只对读的尝试将不阻塞。如果插座有一个挂起的错误进行检索,阅读不会阻止。无论阅读(2)
和写(2)
第一,甚至试图以处理任何之前获取套接字上任何挂起的错误数据。select()
itself does not return an error if an error is signalled for one of the sockets it is selecting for. [Indeed, the API can't indicate per-socket errors this way, because two different sockets could each acquire a pending error during a single call ofselect()
. Which one wouldselect()
return?]- After each iteration of the
select()
loop, you instead use the FD_ISSET macro to attempt aread()
on each socket marked readable. - Any time a socket has a pending error set, its read event (and write event) are signalled, and
select()
returns, allowing you to pick up timed-out errors due to keep-alive immediately. Note that select marking a socket for read does not indicate that there is data to read, only that an attempt to read will not block. If the socket has a pending error to retrieve, reading will not block. Bothread(2)
andwrite(2)
first retrieve any pending error on the socket before even attempting to handle any data.一个描述符应阅读时要输入函数的调用与O_NONBLOCK明确不会阻止,该功能是否会成功传输的数据被认为是准备好了。 (该函数可能返回数据,结束文件的指示,或多于一个指示它被阻止其它错误,并且在每一种情况下的描述应被视为准备读数。)[]
- 最后,返回什么错误?重要的是,这取决于如何保活失败。你会得到
ETIMEDOUT
如果另一端完全消失。如果发生数据包传送错误,你会得到通过,而不是(所以如果保留的数据包得到一个ICMP错误回复,如主机不可达,您将有EHOSTUNREACH
交付)。 [有关这些案件的更多详细信息,请参阅史蒂文斯,UNIX网络编程,第1卷。]
这篇关于我可以得到什么套接字错误时,TCP保持活动中断连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!