]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Rework handling of Linux TCP keepalives in Sofia
authorTravis Cross <tc@traviscross.com>
Tue, 11 Feb 2014 06:26:01 +0000 (06:26 +0000)
committerTravis Cross <tc@traviscross.com>
Tue, 11 Feb 2014 06:39:50 +0000 (06:39 +0000)
This separates out the Linux socket TCP keepalive timeout interval
from Sofia's internal mechanisms.  Earlier we tied these together.  In
retrospect this seems improper.

These two values can now be set separately.

You might, for example, want to keep the Sofia internal mechanism
disabled completely while enabling the platform-based mechanism if
your platform supports it.

We also here reform the default value of the socket TCP keepalive
parameter to 30 seconds.

This is what commit 1bf17857c9a322df50305606ca41203053001818 should
have been.

FS-6104

libs/sofia-sip/libsofia-sip-ua/tport/sofia-sip/tport_tag.h
libs/sofia-sip/libsofia-sip-ua/tport/tport.c
libs/sofia-sip/libsofia-sip-ua/tport/tport_internal.h
libs/sofia-sip/libsofia-sip-ua/tport/tport_tag.c
libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tcp.c

index 6e0ef165d0e4e99d75f3e53a0e4d8a028ed34daa..de96fca3d8da711277e072f7956ac8c4a3bc71b8 100644 (file)
@@ -142,6 +142,12 @@ TPORT_DLL extern tag_typedef_t tptag_timeout;
 TPORT_DLL extern tag_typedef_t tptag_timeout_ref;
 #define TPTAG_TIMEOUT_REF(x) tptag_timeout_ref, tag_uint_vr(&(x))
 
+TPORT_DLL extern tag_typedef_t tptag_socket_keepalive;
+#define TPTAG_SOCKET_KEEPALIVE(x) tptag_socket_keepalive, tag_uint_v((x))
+
+TPORT_DLL extern tag_typedef_t tptag_socket_keepalive_ref;
+#define TPTAG_SOCKET_KEEPALIVE_REF(x) tptag_socket_keepalive_ref, tag_uint_vr(&(x))
+
 TPORT_DLL extern tag_typedef_t tptag_keepalive;
 #define TPTAG_KEEPALIVE(x) tptag_keepalive, tag_uint_v((x))
 
index 228f7f8d834e5b8c07135196d145f37fb0b535b1..c91bd5d8e06e9931d804a56f47ed1a2bc1412f48 100644 (file)
@@ -520,6 +520,7 @@ tport_t *tport_tcreate(tp_stack_t *stack,
   tpp->tpp_idle = UINT_MAX;
   tpp->tpp_timeout = UINT_MAX;
   tpp->tpp_sigcomp_lifetime = UINT_MAX;
+  tpp->tpp_socket_keepalive = 30;
   tpp->tpp_keepalive = 0;
   tpp->tpp_pingpong = 0;
   tpp->tpp_pong2ping = 0;
@@ -1215,6 +1216,7 @@ int tport_get_params(tport_t const *self,
               TPTAG_QUEUESIZE(tpp->tpp_qsize),
               TPTAG_IDLE(tpp->tpp_idle),
               TPTAG_TIMEOUT(tpp->tpp_timeout),
+              TPTAG_SOCKET_KEEPALIVE(tpp->tpp_socket_keepalive),
               TPTAG_KEEPALIVE(tpp->tpp_keepalive),
               TPTAG_PINGPONG(tpp->tpp_pingpong),
               TPTAG_PONG2PING(tpp->tpp_pong2ping),
@@ -1280,6 +1282,7 @@ int tport_set_params(tport_t *self,
              TAG_IF(!self->tp_queue, TPTAG_QUEUESIZE_REF(tpp->tpp_qsize)),
              TPTAG_IDLE_REF(tpp->tpp_idle),
              TPTAG_TIMEOUT_REF(tpp->tpp_timeout),
+             TPTAG_SOCKET_KEEPALIVE_REF(tpp->tpp_socket_keepalive),
              TPTAG_KEEPALIVE_REF(tpp->tpp_keepalive),
              TPTAG_PINGPONG_REF(tpp->tpp_pingpong),
              TPTAG_PONG2PING_REF(pong2ping),
index d4693ad167b1728466ec3c7c8d4f28b2bb297dd0..ac59f26af2daabb8e723f41ba2a25897c77f623a 100644 (file)
@@ -106,6 +106,7 @@ typedef struct {
   unsigned tpp_mtu;            /**< Maximum packet size */
   unsigned tpp_idle;           /**< Allowed connection idle time. */
   unsigned tpp_timeout;                /**< Allowed idle time for message. */
+  unsigned tpp_socket_keepalive;/**< Socket keepalive interval */
   unsigned tpp_keepalive;      /**< Keepalive PING interval */
   unsigned tpp_pingpong;       /**< PONG-to-PING interval */
 
index 59feeeceeee1008b4b0c499dda6b60225506d5b0..35262f4fe99bea30689031f7a931d5e1b2b73a9c 100644 (file)
@@ -179,6 +179,14 @@ tag_typedef_t tptag_idle = UINTTAG_TYPEDEF(idle);
  */
 tag_typedef_t tptag_timeout = UINTTAG_TYPEDEF(timeout);
 
+/**@def TPTAG_SOCKET_KEEPALIVE(x)
+ *
+ * Keepalive interval set on socket (where supported) in seconds.
+ *
+ * If 0 or UINT_MAX, do not use keepalives. Default value is 30.
+ */
+tag_typedef_t tptag_socket_keepalive = UINTTAG_TYPEDEF(socket_keepalive);
+
 /**@def TPTAG_KEEPALIVE(x)
  *
  * Keepalive interval in milliseconds.
index d42547c5821f2a8582689cfe6e3305088a242745..9b700dc1a20976a5b1e284d1e68c36579031d8be 100644 (file)
@@ -196,11 +196,7 @@ 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 = (int)(self->tp_params->tpp_keepalive / 1000);
-  if (!val && (self->tp_params->tpp_keepalive > 0))
-    SU_DEBUG_1(("%s(%p): Ignoring TCP keepalive value %u (<1000)\n",
-                __func__, (void *)self,
-               self->tp_params->tpp_keepalive));
+  val = (int)(self->tp_params->tpp_socket_keepalive);
 #if defined(TCP_KEEPIDLE)
   if (val != 0 && val != UINT_MAX) {
     SU_DEBUG_3(("%s(%p): Setting TCP_KEEPIDLE to %d\n",