]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Handle Linux TCP keepalives better in Sofia
authorTravis Cross <tc@traviscross.com>
Fri, 17 Jan 2014 07:05:17 +0000 (07:05 +0000)
committerTravis Cross <tc@traviscross.com>
Sat, 18 Jan 2014 15:46:56 +0000 (15:46 +0000)
Sofia accepts a value for the TCP keepalive timeout interval via
TPTAG_KEEPALIVE, however it fails to use this value for the Linux
keepalive socket options TCP_KEEPIDLE and TCP_KEEPINTVL.  In fact, on
Linux it enables the sending of TCP keepalives even if tpp_keepalive
is set to zero which would disable Sofia's internal keepalive
mechanisms.  Sofia then uses a hard coded value of 30 seconds for
these keepalive intervals which affects battery life on mobile
devices.

With this commit we harmonize the sending of TCP keepalives on Linux
with other platforms by using the value from TPTAG_KEEPALIVE and not
enabling the sending of TCP keepalives at all if the value of the
parameter is zero.

FS-6104 --resolve

libs/sofia-sip/.update
libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tcp.c

index f36394da877c4f92e775aab2c0e524b7d352289f..69ff5167a324ab53fd08868abb908bf3d16709c6 100644 (file)
@@ -1 +1 @@
-Wed Nov 27 10:20:13 CST 2013
+Fri Jan 17 06:55:06 UTC 2014
index 7196955e2764dfb58cf1bb38c1d96bd5c8bd8ed5..70cf64385beed16b312183a18392e1c4da2f66c9 100644 (file)
@@ -196,12 +196,14 @@ int tport_tcp_init_secondary(tport_t *self, int socket, int accepted,
 #if defined(SO_KEEPALIVE)
   setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, (void *)&val, sizeof val);
 #endif
-  val = 30;
+  val = (int)(self->tp_params->tpp_keepalive);
 #if defined(TCP_KEEPIDLE)
-  setsockopt(socket, SOL_TCP, TCP_KEEPIDLE, (void *)&val, sizeof val);
+  if (val != 0 && val != UINT_MAX)
+    setsockopt(socket, SOL_TCP, TCP_KEEPIDLE, (void *)&val, sizeof val);
 #endif
 #if defined(TCP_KEEPINTVL)
-  setsockopt(socket, SOL_TCP, TCP_KEEPINTVL, (void *)&val, sizeof val);
+  if (val != 0 && val != UINT_MAX)
+    setsockopt(socket, SOL_TCP, TCP_KEEPINTVL, (void *)&val, sizeof val);
 #endif
 
   if (!accepted)