I have the following function for configuring TCP Keepalive for a socket:
int configure_tcp_keepalive(int fd)
{
int opt_val = 1;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &opt_val, sizeof(opt_val)) == -1)
return -1;
int keepcnt = 9; //default value on Linux
if (setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &keepcnt, sizeof(keepcnt)) == -1)
return -1;
int keepidle = 30;
if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &keepidle, sizeof(keepidle)) == -1)
return -1;
int keepintvl = 30;
if (setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &keepintvl, sizeof(keepintvl)) == -1)
return -1;
}
If I call this function on the server fd, will it affect every accept()'d client (i.e. will accept()'d clients inherit these socket options and thus be configured for TCP Keepalive)? I'd rather not have to call this function for every client, in order to minimize overhead. Thanks.