TCP长连接。
设置:
- TCP_KEEPIDLE: The tcp_keepidle parameter specifies the interval of inactivity that causes TCP to generate a KEEPALIVE transmission for an application that requests them. tcp_keepidle defaults to 14400 (two hours)
- TCP_KEEPINTVL: The tcp_keepintvl parameter specifies the interval between the nine retries that are attempted if a KEEPALIVE transmission is not acknowledged. tcp_keepintvl defaults to 150 (75 seconds)
- TCP_KEEPCNT: The tcp_keepcnt option specifies the maximum number of keepalive probes to be sent. The value of TCP_KEEPCNT is an integer value between 1 and n, where n is the value of the systemwide tcp_keepcnt parameter.
void set_keepalive(int fd)
{
int keep_alive = 1;
int keep_idle = 1000;
int keep_interval = 10;
int keep_count