From a47865fa19db62f577be1cf6dedd4208e675b457 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sun, 10 Feb 2013 09:39:47 +0800 Subject: [PATCH] dont try set per socket keepalive timing on bsds As per http://libwebsockets.org/trac/ticket/10 BSD doesn't support setting keepalive info per-socket Signed-off-by: Andy Green --- README.coding | 4 ++++ changelog | 11 +++++++---- lib/libwebsockets.c | 9 +++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.coding b/README.coding index 7c9d631f..4f4c27a5 100644 --- a/README.coding +++ b/README.coding @@ -184,3 +184,7 @@ stimulate a response from the peer without affecting link traffic. If the response is not coming, the socket will announce an error at poll() forcing a close. +Note that BSDs don't support keepalive time / probes / inteveral per-socket +like Linux does. On those systems you can enable keepalive by a nonzero +value in ka_time, but the systemwide kernel settings for the time / probes/ +interval are used, regardless of what nonzero value is in ka_time. diff --git a/changelog b/changelog index fcf091d5..77d7f8bb 100644 --- a/changelog +++ b/changelog @@ -10,10 +10,13 @@ User api additions "1.1 9e7f737", representing the library version from configure.ac and the git HEAD hash the library was built from - - TCP Keepalive can now optionally be applied to all lws sockets, with - controllable timeout, number of probes and probe interval. This - enables detection of idle connections which are logically okay, but - are in fact dead, due to network connectivity issues at the server, + - TCP Keepalive can now optionally be applied to all lws sockets, on Linux + also with controllable timeout, number of probes and probe interval. + (On BSD type OS, you can only use system default settings for the + timing and retries, although enabling it is supported by setting + ka_time to nonzero, the exact value has no meaning.) + This enables detection of idle connections which are logically okay, + but are in fact dead, due to network connectivity issues at the server, client, or any intermediary. By default it's not enabled, but you can enable it by setting a non-zero timeout (in seconds) at the new ka_time member at context creation time. diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index dd58ff12..f5dfcebe 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -537,6 +537,14 @@ int lws_set_socket_options(struct libwebsocket_context *context, int fd) (const void *)&optval, optlen) < 0) return 1; +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) + + /* + * didn't find a way to set these per-socket, need to + * tune kernel systemwide values + */ + +#else /* set the keepalive conditions we want on it too */ optval = context->ka_time; if (setsockopt(fd, IPPROTO_IP, TCP_KEEPIDLE, @@ -552,6 +560,7 @@ int lws_set_socket_options(struct libwebsocket_context *context, int fd) if (setsockopt(fd, IPPROTO_IP, TCP_KEEPCNT, (const void *)&optval, optlen) < 0) return 1; +#endif } /* Disable Nagle */