From 209e9dcd7b2f23b68ff93bf20fad025bc03219ac Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Thu, 14 Aug 2014 23:06:11 +0530 Subject: socket: Add Support for TCP keep alive variables The tcp keep alive variables now can be configured via conf parameter. Follwing variables are now supported by this patch. tcp_keepalive_intvl: The number of seconds between TCP keep-alive probes tcp_keepalive_probes: The maximum number of TCP keep-alive probes to send before giving up and killing the connection if no response is obtained from the other end. tcp_keepalive_time: The number of seconds a connection needs to be idle before TCP begins sending out keep-alive probes. --- src/core/socket.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/core/socket.c') diff --git a/src/core/socket.c b/src/core/socket.c index 5af15964ff..d6d9821f57 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -462,6 +462,7 @@ _const_ static const char* listen_lookup(int family, int type) { } static void socket_dump(Unit *u, FILE *f, const char *prefix) { + char time_string[FORMAT_TIMESPAN_MAX]; SocketExecCommand c; Socket *s = SOCKET(u); SocketPort *p; @@ -595,6 +596,23 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) { prefix, strna(s->user), prefix, strna(s->group)); + if(s->keep_alive_time) + fprintf(f, + "%sKeepAliveTime: %s\n", + prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, + s->keep_alive_time, USEC_PER_SEC)); + + if(s->keep_alive_interval) + fprintf(f, + "%sKeepAliveInterval: %s\n", + prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, + s->keep_alive_interval, USEC_PER_SEC)); + + if(s->keep_alive_cnt) + fprintf(f, + "%sKeepAliveProbes: %u\n", + prefix, s->keep_alive_cnt); + LIST_FOREACH(port, p, s->ports) { if (p->type == SOCKET_SOCKET) { @@ -792,6 +810,24 @@ static void socket_apply_socket_options(Socket *s, int fd) { log_warning_unit(UNIT(s)->id, "SO_KEEPALIVE failed: %m"); } + if (s->keep_alive_time) { + int value = s->keep_alive_time / USEC_PER_SEC; + if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &value, sizeof(value)) < 0) + log_warning_unit(UNIT(s)->id, "TCP_KEEPIDLE failed: %m"); + } + + if (s->keep_alive_interval) { + int value = s->keep_alive_interval / USEC_PER_SEC; + if (setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &value, sizeof(value)) < 0) + log_warning_unit(UNIT(s)->id, "TCP_KEEPINTVL failed: %m"); + } + + if (s->keep_alive_cnt) { + int value = s->keep_alive_cnt; + if (setsockopt(fd, SOL_SOCKET, TCP_KEEPCNT, &value, sizeof(value)) < 0) + log_warning_unit(UNIT(s)->id, "TCP_KEEPCNT failed: %m"); + } + if (s->no_delay) { int b = s->no_delay; if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &b, sizeof(b)) < 0) -- cgit v1.2.3-54-g00ecf