summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2012-10-04 15:19:40 +0200
committerFelix Fietkau <nbd@openwrt.org>2012-10-04 15:32:10 +0200
commitef06b4d6de2b04c8d09f7962acfa4cd125a3a47f (patch)
tree8cfffac7d1babcefa875ea9d62cc0fa5ba14bf32
parent1bf5ab5aafe6c0da71eef9ad21bc129caa439599 (diff)
downloaduhttpd-ef06b4d6de2b04c8d09f7962acfa4cd125a3a47f.tar.gz
#ifdef linux-specific tcp keepalive options
-rw-r--r--uhttpd.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/uhttpd.c b/uhttpd.c
index 397d071..0242000 100644
--- a/uhttpd.c
+++ b/uhttpd.c
@@ -133,7 +133,9 @@ static int uh_socket_bind(const char *host, const char *port,
int status;
int bound = 0;
+#ifdef linux
int tcp_ka_idl, tcp_ka_int, tcp_ka_cnt;
+#endif
struct listener *l = NULL;
struct addrinfo *addrs = NULL, *p = NULL;
@@ -163,14 +165,19 @@ static int uh_socket_bind(const char *host, const char *port,
/* TCP keep-alive */
if (conf->tcp_keepalive > 0)
{
+#ifdef linux
tcp_ka_idl = 1;
tcp_ka_cnt = 3;
tcp_ka_int = conf->tcp_keepalive;
+#endif
- if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes)) ||
- setsockopt(sock, SOL_TCP, TCP_KEEPIDLE, &tcp_ka_idl, sizeof(tcp_ka_idl)) ||
- setsockopt(sock, SOL_TCP, TCP_KEEPINTVL, &tcp_ka_int, sizeof(tcp_ka_int)) ||
- setsockopt(sock, SOL_TCP, TCP_KEEPCNT, &tcp_ka_cnt, sizeof(tcp_ka_cnt)))
+ if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes))
+#ifdef linux
+ || setsockopt(sock, SOL_TCP, TCP_KEEPIDLE, &tcp_ka_idl, sizeof(tcp_ka_idl))
+ || setsockopt(sock, SOL_TCP, TCP_KEEPINTVL, &tcp_ka_int, sizeof(tcp_ka_int))
+ || setsockopt(sock, SOL_TCP, TCP_KEEPCNT, &tcp_ka_cnt, sizeof(tcp_ka_cnt))
+#endif
+ )
{
fprintf(stderr, "Notice: Unable to enable TCP keep-alive: %s\n",
strerror(errno));