]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add tcp keepalive where possible
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 25 Apr 2013 18:33:17 +0000 (13:33 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 25 Apr 2013 17:15:30 +0000 (12:15 -0500)
libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tcp.c

index 062af6e0195c7020b5ddebfbc761d85e0de59e13..1e9d9eb14f70ae48810be886e0e70d1d04f2f044 100644 (file)
@@ -184,13 +184,24 @@ int tport_tcp_init_client(tport_primary_t *pri,
 int tport_tcp_init_secondary(tport_t *self, int socket, int accepted,
                             char const **return_reason)
 {
-  int one = 1;
+  int val = 1;
 
   self->tp_has_connection = 1;
 
-  if (setsockopt(socket, SOL_TCP, TCP_NODELAY, (void *)&one, sizeof one) == -1)
+  if (setsockopt(socket, SOL_TCP, TCP_NODELAY, (void *)&val, sizeof val) == -1)
     return *return_reason = "TCP_NODELAY", -1;
 
+#if defined(SO_KEEPALIVE)
+  setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, (void *)&val, sizeof val);
+#endif
+  val = 30;
+#if defined(TCP_KEEPIDLE)
+  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);
+#endif
+
   if (!accepted)
     tport_tcp_setsndbuf(socket, 64 * 1024);