Linux Tcp连接,拔掉网线后 仍然ESTIBLISHED
Linux Tcp连接,拔掉网线后 仍然ESTIBLISHED
这个该怎么解决?
实际网线已经拔掉了,这个状态仍会持续5分钟左右,需要怎么设置?求大神解惑
靜靜D藍調
11 years, 4 months ago
Answers
服务器通过设置select检查频率改小点,可以解决该问题。
fd_set ifds;
struct timeval to = { 300, 0 }; // timeout on 5 minutes.
int sret;
FD_ZERO(&ifds);
FD_SET(connfd, &ifds);
sret = select(connfd + 1, &ifds, NULL, NULL, &to);
if (!sret)
{
LogAppend(WARN_LEVEL, "Client does not have any actions,disconnect.");
}
Mr.Neko
answered 11 years, 4 months ago