]> 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:27:20 +0000 (06:27 +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 a0e9639a1f38f26a5dc586d386ae044ba82e0137 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 62193e9135b821f90b6e8d1a99fcc0d7352c5c65..dd9c40c8020c6111b2ff357f9e9161913b010f6e 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;
@@ -1218,6 +1219,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),
@@ -1283,6 +1285,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 5deac55268dca914646ad3a37fdf346deaa8e82e..f18fc93911a558c82f47e0d18d341ef8c3e4f60d 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",