From cc567c9beace114554f7e7f50c3a5181cc44a07d Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Thu, 14 Aug 2014 23:06:12 +0530 Subject: socket: Add support for TCP defer accept TCP_DEFER_ACCEPT Allow a listener to be awakened only when data arrives on the socket. If TCP_DEFER_ACCEPT set on a server-side listening socket, the TCP/IP stack will not to wait for the final ACK packet and not to initiate the process until the first packet of real data has arrived. After sending the SYN/ACK, the server will then wait for a data packet from a client. Now, only three packets will be sent over the network, and the connection establishment delay will be significantly reduced. --- src/core/socket.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/core/socket.c') diff --git a/src/core/socket.c b/src/core/socket.c index d6d9821f57..a16b20d739 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -613,6 +613,12 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) { "%sKeepAliveProbes: %u\n", prefix, s->keep_alive_cnt); + if(s->defer_accept) + fprintf(f, + "%sDeferAccept: %s\n", + prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, + s->defer_accept, USEC_PER_SEC)); + LIST_FOREACH(port, p, s->ports) { if (p->type == SOCKET_SOCKET) { @@ -828,6 +834,12 @@ static void socket_apply_socket_options(Socket *s, int fd) { log_warning_unit(UNIT(s)->id, "TCP_KEEPCNT failed: %m"); } + if (s->defer_accept) { + int value = s->defer_accept / USEC_PER_SEC; + if (setsockopt(fd, SOL_TCP, TCP_DEFER_ACCEPT, &value, sizeof(value)) < 0) + log_warning_unit(UNIT(s)->id, "TCP_DEFER_ACCEPT 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