diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2021-04-22 12:20:48 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2021-04-22 12:24:42 +0200 |
commit | 3b1f2c293f5f71468dc7c5cfd876e2a53f869d46 (patch) | |
tree | 4c7b5022775bd7c2f7e10f8d1477a497d6e59787 /src/core.c | |
parent | 29e7641e910901e813f5682da677f767a2aea5cc (diff) |
#980 Broken TCP connection times out after 120 seconds through keepalive
Enable TCP keepalive to detect if the ogClient is gone (hard reset). If no reply
after 120 seconds, then release the connection to the client.
Diffstat (limited to 'src/core.c')
-rw-r--r-- | src/core.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -19,6 +19,7 @@ #include <ifaddrs.h> #include <sys/types.h> #include <sys/stat.h> +#include <netinet/tcp.h> #include <fcntl.h> #include <jansson.h> #include <time.h> @@ -313,10 +314,16 @@ static void og_agent_send_refresh(struct og_client *cli) /* Agent client operation might take longer, shut down after 30 seconds. */ #define OG_AGENT_CLIENT_TIMEOUT 30 +#define OG_TCP_KEEPALIVE_IDLE 60 +#define OG_TCP_KEEPALIVE_INTL 30 +#define OG_TCP_KEEPALIVE_CNT 4 + int socket_rest, socket_agent_rest; void og_server_accept_cb(struct ev_loop *loop, struct ev_io *io, int events) { + int intl = OG_TCP_KEEPALIVE_INTL, cnt = OG_TCP_KEEPALIVE_CNT; + int on = 1, idle = OG_TCP_KEEPALIVE_IDLE; struct sockaddr_in client_addr; socklen_t addrlen = sizeof(client_addr); struct og_client *cli; @@ -331,6 +338,11 @@ void og_server_accept_cb(struct ev_loop *loop, struct ev_io *io, int events) return; } + setsockopt(client_sd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(int)); + setsockopt(client_sd, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(int)); + setsockopt(client_sd, IPPROTO_TCP, TCP_KEEPINTVL, &intl, sizeof(int)); + setsockopt(client_sd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(int)); + cli = (struct og_client *)calloc(1, sizeof(struct og_client)); if (!cli) { close(client_sd); |