From 9c7e081f51063b6cdb4674f4d2e6c4eab502a327 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Wed, 28 Mar 2012 09:20:38 +0200 Subject: XS_KEEPALIVE options added This option allows to turn on TCP keepalives on the underlying connections. Signed-off-by: Martin Sustrik --- src/ip.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/ip.cpp') diff --git a/src/ip.cpp b/src/ip.cpp index 1eca352..bae8d7e 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -60,7 +60,7 @@ xs::fd_t xs::open_socket (int domain_, int type_, int protocol_) return s; } -void xs::tune_tcp_socket (fd_t s_) +void xs::tune_tcp_socket (fd_t s_, bool keepalive_) { // Disable Nagle's algorithm. We are doing data batching on Crossroads // level, so using Nagle wouldn't improve throughput in anyway, but it @@ -81,6 +81,17 @@ void xs::tune_tcp_socket (fd_t s_) sizeof (int)); errno_assert (rc != SOCKET_ERROR); #endif + + if (keepalive_) { + int keepalive = 1; + int rc = setsockopt (s_, SOL_SOCKET, SO_KEEPALIVE, (char*) &keepalive, + sizeof (int)); +#ifdef XS_HAVE_WINDOWS + wsa_assert (rc != SOCKET_ERROR); +#else + errno_assert (rc == 0); +#endif + } } void xs::unblock_socket (fd_t s_) -- cgit v1.2.3