[英]What socket error do I get when TCP keep-alive breaks the connection?
I have a set of TCP sockets with keep-alive (interval 1 min), controlled by a select(2)
loop (selecting for read). 我有一组带有保持活动的TCP套接字(间隔1分钟),由
select(2)
循环控制(选择读取)。
select(2)
return an error if keep-alive timeout has happened for one of the sockets in the set? select(2)
返回错误吗? read(2)
return? read(2)
返回? select()
itself does not return an error if an error is signalled for one of the sockets it is selecting for. select()
本身不会返回错误。 [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 of select()
. select()
期间,两个不同的套接字都可以获取挂起错误。 Which one would select()
return?] select()
返回?] select()
loop, you instead use the FD_ISSET macro to attempt a read()
on each socket marked readable. select()
循环之后,您改为使用FD_ISSET宏在每个标记为可读的套接字上尝试read()
。 select()
returns, allowing you to pick up timed-out errors due to keep-alive immediately. select()
返回,这样您就可以立即获取由于保持活动而导致的超时错误。 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. read(2)
and write(2)
first retrieve any pending error on the socket before even attempting to handle any data. read(2)
和write(2)
都会在尝试处理任何数据之前首先检索套接字上的任何挂起错误。
A descriptor shall be considered ready for reading when a call to an input function with O_NONBLOCK clear would not block, whether or not the function would transfer data successfully.
当对具有O_NONBLOCK clear的输入函数的调用不会阻塞时,该函数将成功传输数据时,应认为描述符已准备好读取。 (The function might return data, an end-of-file indication, or an error other than one indicating that it is blocked, and in each of these cases the descriptor shall be considered ready for reading.) [ POSIX:select() ]
(该函数可能返回数据,文件结束指示或除了表示被阻止的错误之外的错误,并且在每种情况下,描述符都应被视为已准备好进行读取。)[ POSIX:select() ]
ETIMEDOUT
if the other end vanishes totally. ETIMEDOUT
。 If a packet delivery error occurs, you'll get that through instead (so if the keep-alive packet gets an ICMP error reply, like "host unreachable", you'll have EHOSTUNREACH
delivered). EHOSTUNREACH
发送EHOSTUNREACH
)。 [For more details on these cases, see Stevens, "Unix Network Programming, vol 1".]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.