From 471b3d33fd35cee57dccb7b513bb0fd1c39b9e8f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 25 Apr 2013 13:33:17 -0500 Subject: [PATCH] add tcp keepalive where possible --- .../libsofia-sip-ua/tport/tport_type_tcp.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tcp.c b/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tcp.c index 062af6e019..1e9d9eb14f 100644 --- a/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tcp.c +++ b/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tcp.c @@ -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);