Support keepalive for TCP connections

This commit is contained in:
lazio579 2019-04-11 11:16:40 +08:00
parent af01f4adff
commit 21a36691eb

View File

@ -283,6 +283,18 @@ network_socket_connect_setopts(network_socket *sock)
if (setsockopt(sock->fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) != 0) {
g_critical("%s: setsockopt SO_KEEPALIVE failed: %s (%d)", G_STRLOC, g_strerror(errno), errno);
}
val = 30;
if (setsockopt(sock->fd, SOL_TCP, TCP_KEEPIDLE, &val, sizeof(val)) != 0) {
g_critical("%s: setsockopt TCP_KEEPIDLE failed: %s (%d)", G_STRLOC, g_strerror(errno), errno);
}
val = 5;
if (setsockopt(sock->fd, SOL_TCP, TCP_KEEPINTVL, &val, sizeof(val)) != 0) {
g_critical("%s: setsockopt TCP_KEEPINTVL failed: %s (%d)", G_STRLOC, g_strerror(errno), errno);
}
val = 3;
if (setsockopt(sock->fd, SOL_TCP, TCP_KEEPCNT, &val, sizeof(val)) != 0) {
g_critical("%s: setsockopt TCP_KEEPCNT failed: %s (%d)", G_STRLOC, g_strerror(errno), errno);
}
/*
* the listening side may be INADDR_ANY,