- 论坛徽章:
- 1
|
回复 3# chaohona
下面是我摘出来的一些代码,,,,透过楼上几位的回答是不是代表 检测单边理论上就可以完成? 而不需要双向设置
另外请看下 我这么设置 是否存在问题
- #define SOL_TCP 6
- #define TCP_KEEPIDLE 4
- #define TCP_KEEPINTVL 5
- #define TCP_KEEPCNT 6
- int keepalive = 1;
- int keepidle = 6;
- int keepintvl = 5;
- int keepcnt = 3;
- if (setsockopt (fd,SOL_SOCKET, SO_KEEPALIVE, (void *)&keepalive, sizeof (keepalive)) < 0 )
- ........
- if (setsockopt (fd,SOL_TCP, SO_KEEPIDLE (void *)&keepidle, sizeof (keepidle)) < 0 )
- .....
- if (setsockopt (fd,SOL_TCP, SO_KEEPINTVL, (void *)&keepinvl, sizeof (keepinval)) < 0 )
- ....
- if (setsockopt (fd,SOL_TCP, SO_KEEPCNT, (void *)&keepcnt, sizeof (keepcnt)) < 0 )
- ....
复制代码 |
|