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/options.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/options.cpp') diff --git a/src/options.cpp b/src/options.cpp index 2b123c2..07d3752 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -45,6 +45,7 @@ xs::options_t::options_t () : rcvtimeo (-1), sndtimeo (-1), ipv4only (1), + keepalive (0), delay_on_close (true), delay_on_disconnect (true), filter (false), @@ -216,6 +217,21 @@ int xs::options_t::setsockopt (int option_, const void *optval_, return 0; } + case XS_KEEPALIVE: + { + if (optvallen_ != sizeof (int)) { + errno = EINVAL; + return -1; + } + int val = *((int*) optval_); + if (val != 0 && val != 1) { + errno = EINVAL; + return -1; + } + keepalive = val; + return 0; + } + } errno = EINVAL; @@ -388,6 +404,15 @@ int xs::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) *optvallen_ = sizeof (int); return 0; + case XS_KEEPALIVE: + if (*optvallen_ < sizeof (int)) { + errno = EINVAL; + return -1; + } + *((int*) optval_) = keepalive; + *optvallen_ = sizeof (int); + return 0; + } errno = EINVAL; -- cgit v1.2.3