From f4a04e65f28a3f93d585dfb28dacf19ca8407a5f Mon Sep 17 00:00:00 2001 From: Brian West Date: Fri, 22 Aug 2014 16:39:45 -0500 Subject: [PATCH] FS-6735 --- src/include/switch_apr.h | 2 ++ .../mod_event_socket/mod_event_socket.c | 2 ++ src/switch_apr.c | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/include/switch_apr.h b/src/include/switch_apr.h index c723a533e3..50096d5aff 100644 --- a/src/include/switch_apr.h +++ b/src/include/switch_apr.h @@ -985,6 +985,8 @@ SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t ** new_thre #define SWITCH_SO_RCVBUF 128 #define SWITCH_SO_DISCONNECTED 256 #define SWITCH_SO_TCP_NODELAY 512 +#define SWITCH_SO_TCP_KEEPIDLE 520 +#define SWITCH_SO_TCP_KEEPINTVL 530 /** diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index 3ad1b0c966..99a6415469 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -446,6 +446,8 @@ SWITCH_STANDARD_APP(socket_function) switch_socket_opt_set(new_sock, SWITCH_SO_KEEPALIVE, 1); switch_socket_opt_set(new_sock, SWITCH_SO_TCP_NODELAY, 1); + switch_socket_opt_set(new_sock, SWITCH_SO_TCP_KEEPIDLE, 30); + switch_socket_opt_set(new_sock, SWITCH_SO_TCP_KEEPINTVL, 30); if (switch_socket_connect(new_sock, sa) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Socket Error!\n"); diff --git a/src/switch_apr.c b/src/switch_apr.c index a12ae2ddeb..e77be82897 100644 --- a/src/switch_apr.c +++ b/src/switch_apr.c @@ -789,6 +789,34 @@ SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t ** sa SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on) { + if (opt == SWITCH_SO_TCP_KEEPIDLE) { + int r = -10; + +#if defined(TCP_KEEPIDLE) + r = setsockopt(jsock->client_socket, SOL_TCP, TCP_KEEPIDLE, (void *)&on, sizeof(on)); +#endif + if (r == -10) { + return SWITCH_STATUS_NOTIMPL; + } + + + return r ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS; + } + + if (opt == SWITCH_SO_TCP_KEEPINTVL) { + int r = -10; + +#if defined(TCP_KEEPINTVL) + r = setsockopt(jsock->client_socket, SOL_TCP, TCP_KEEPINTVL, (void *)&on, sizeof(on)); +#endif + + if (r == -10) { + return SWITCH_STATUS_NOTIMPL; + } + + return r ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS; + } + return apr_socket_opt_set(sock, opt, on); }