linux socket keepalive
原文链接: linux socket keepalive
// int keepalive = 1; // 开启keepalive属性
// int keepidle = 60; // 如该连接在60秒内没有任何数据往来,则进行探测
// int keepinterval = 5; // 探测时发包的时间间隔为5 秒
// int keepcount = 3; // 探测尝试的次数.如果第1次探测包就收到响应了,则后2次的不再发.
// setsockopt(rs, SOL_SOCKET, SO_KEEPALIVE, (void )&keepalive , sizeof(keepalive ));
// setsockopt(rs, SOL_TCP, TCP_KEEPIDLE, (void)&keepidle , sizeof(keepidle ));
// setsockopt(rs, SOL_TCP, TCP_KEEPINTVL, (void *)&keepinterval , sizeof(keepinterval ));
// setsockopt(rs, SOL_TCP, TCP_KEEPCNT, (void *)&keepcount , sizeof(keepcount ));