1

I have been trying to implement the TCP_KEEPALIVE parameter for a C server socket and I can't seem to figure out how to check if the socket is marked as broken. I followed this tutorial for configuring the socket to do the keep alive but it says that "If no ACK response is received for nine consecutive times, the connection is marked as broken". My question is, how do I know the socket is marked as broken?

Tutorial: http://tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/

4

2 回答 2

2

从套接字读取()。

如果套接字已损坏, read 将返回 -1。

于 2010-09-15T18:10:50.463 回答
1

如果内核决定连接断开,当您尝试发送到套接字或从套接字接收时,您会收到错误消息。您应该已经对发送和接收进行了适当的错误处理,以处理对等方自发终止连接的“正常”情况。因此,不需要“额外的”错误处理代码。

于 2010-09-15T18:16:54.090 回答