diff options
author | Liong Sauw Ming <ming@teluu.com> | 2015-05-11 05:57:50 +0000 |
---|---|---|
committer | Liong Sauw Ming <ming@teluu.com> | 2015-05-11 05:57:50 +0000 |
commit | ccf97961a75679ae321352735896f9db46032ab7 (patch) | |
tree | 6702ba80e32acf48a7f9cd79571b7115c8ac289f /pjsip | |
parent | babf151e91586b89c9f1be56dd5fe0505796e6dc (diff) |
Fixed #1851: Runtime configuration of TCP and TLS keep alive intervals
Thanks to Michele Cicciotti for the patch.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5090 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r-- | pjsip/include/pjsip/sip_config.h | 30 | ||||
-rw-r--r-- | pjsip/src/pjsip/sip_config.c | 10 | ||||
-rw-r--r-- | pjsip/src/pjsip/sip_transport_tcp.c | 14 | ||||
-rw-r--r-- | pjsip/src/pjsip/sip_transport_tls.c | 14 |
4 files changed, 54 insertions, 14 deletions
diff --git a/pjsip/include/pjsip/sip_config.h b/pjsip/include/pjsip/sip_config.h index 3fd0e41d..6036ba46 100644 --- a/pjsip/include/pjsip/sip_config.h +++ b/pjsip/include/pjsip/sip_config.h @@ -217,6 +217,30 @@ typedef struct pjsip_cfg_t } regc; + /** TCP transport settings */ + struct { + /** + * Set the interval to send keep-alive packet for TCP transports. + * If the value is zero, keep-alive will be disabled for TCP. + * + * Default is PJSIP_TCP_KEEP_ALIVE_INTERVAL. + */ + long keep_alive_interval; + + } tcp; + + /** TLS transport settings */ + struct { + /** + * Set the interval to send keep-alive packet for TLS transports. + * If the value is zero, keep-alive will be disabled for TLS. + * + * Default is PJSIP_TLS_KEEP_ALIVE_INTERVAL. + */ + long keep_alive_interval; + + } tls; + } pjsip_cfg_t; @@ -649,6 +673,9 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void) * Set the interval to send keep-alive packet for TCP transports. * If the value is zero, keep-alive will be disabled for TCP. * + * This option can be changed in run-time by settting + * \a tcp.keep_alive_interval field of pjsip_cfg(). + * * Default: 90 (seconds) * * @see PJSIP_TCP_KEEP_ALIVE_DATA @@ -672,6 +699,9 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void) * Set the interval to send keep-alive packet for TLS transports. * If the value is zero, keep-alive will be disabled for TLS. * + * This option can be changed in run-time by settting + * \a tls.keep_alive_interval field of pjsip_cfg(). + * * Default: 90 (seconds) * * @see PJSIP_TLS_KEEP_ALIVE_DATA diff --git a/pjsip/src/pjsip/sip_config.c b/pjsip/src/pjsip/sip_config.c index 59748760..3576f351 100644 --- a/pjsip/src/pjsip/sip_config.c +++ b/pjsip/src/pjsip/sip_config.c @@ -49,6 +49,16 @@ pjsip_cfg_t pjsip_sip_cfg_var = /* Client registration client */ { PJSIP_REGISTER_CLIENT_CHECK_CONTACT + }, + + /* TCP transport settings */ + { + PJSIP_TCP_KEEP_ALIVE_INTERVAL + }, + + /* TLS transport settings */ + { + PJSIP_TLS_KEEP_ALIVE_INTERVAL } }; diff --git a/pjsip/src/pjsip/sip_transport_tcp.c b/pjsip/src/pjsip/sip_transport_tcp.c index 3402eb01..0dc0bacb 100644 --- a/pjsip/src/pjsip/sip_transport_tcp.c +++ b/pjsip/src/pjsip/sip_transport_tcp.c @@ -1140,8 +1140,8 @@ static pj_bool_t on_accept_complete(pj_activesock_t *asock, return PJ_TRUE; } /* Start keep-alive timer */ - if (PJSIP_TCP_KEEP_ALIVE_INTERVAL) { - pj_time_val delay = {PJSIP_TCP_KEEP_ALIVE_INTERVAL, 0}; + if (pjsip_cfg()->tcp.keep_alive_interval) { + pj_time_val delay = {pjsip_cfg()->tcp.keep_alive_interval, 0}; pjsip_endpt_schedule_timer(listener->endpt, &tcp->ka_timer, &delay); @@ -1499,8 +1499,8 @@ static pj_bool_t on_connect_complete(pj_activesock_t *asock, tcp_flush_pending_tx(tcp); /* Start keep-alive timer */ - if (PJSIP_TCP_KEEP_ALIVE_INTERVAL) { - pj_time_val delay = { PJSIP_TCP_KEEP_ALIVE_INTERVAL, 0 }; + if (pjsip_cfg()->tcp.keep_alive_interval) { + pj_time_val delay = { pjsip_cfg()->tcp.keep_alive_interval, 0 }; pjsip_endpt_schedule_timer(tcp->base.endpt, &tcp->ka_timer, &delay); tcp->ka_timer.id = PJ_TRUE; @@ -1526,9 +1526,9 @@ static void tcp_keep_alive_timer(pj_timer_heap_t *th, pj_timer_entry *e) pj_gettimeofday(&now); PJ_TIME_VAL_SUB(now, tcp->last_activity); - if (now.sec > 0 && now.sec < PJSIP_TCP_KEEP_ALIVE_INTERVAL) { + if (now.sec > 0 && now.sec < pjsip_cfg()->tcp.keep_alive_interval) { /* There has been activity, so don't send keep-alive */ - delay.sec = PJSIP_TCP_KEEP_ALIVE_INTERVAL - now.sec; + delay.sec = pjsip_cfg()->tcp.keep_alive_interval - now.sec; delay.msec = 0; pjsip_endpt_schedule_timer(tcp->base.endpt, &tcp->ka_timer, @@ -1555,7 +1555,7 @@ static void tcp_keep_alive_timer(pj_timer_heap_t *th, pj_timer_entry *e) } /* Register next keep-alive */ - delay.sec = PJSIP_TCP_KEEP_ALIVE_INTERVAL; + delay.sec = pjsip_cfg()->tcp.keep_alive_interval; delay.msec = 0; pjsip_endpt_schedule_timer(tcp->base.endpt, &tcp->ka_timer, diff --git a/pjsip/src/pjsip/sip_transport_tls.c b/pjsip/src/pjsip/sip_transport_tls.c index 7c3c7e5f..7fec591e 100644 --- a/pjsip/src/pjsip/sip_transport_tls.c +++ b/pjsip/src/pjsip/sip_transport_tls.c @@ -1281,8 +1281,8 @@ static pj_bool_t on_accept_complete(pj_ssl_sock_t *ssock, tls_destroy(&tls->base, status); } else { /* Start keep-alive timer */ - if (PJSIP_TLS_KEEP_ALIVE_INTERVAL) { - pj_time_val delay = {PJSIP_TLS_KEEP_ALIVE_INTERVAL, 0}; + if (pjsip_cfg()->tls.keep_alive_interval) { + pj_time_val delay = {pjsip_cfg()->tls.keep_alive_interval, 0}; pjsip_endpt_schedule_timer(listener->endpt, &tls->ka_timer, &delay); @@ -1747,8 +1747,8 @@ static pj_bool_t on_connect_complete(pj_ssl_sock_t *ssock, tls_flush_pending_tx(tls); /* Start keep-alive timer */ - if (PJSIP_TLS_KEEP_ALIVE_INTERVAL) { - pj_time_val delay = { PJSIP_TLS_KEEP_ALIVE_INTERVAL, 0 }; + if (pjsip_cfg()->tls.keep_alive_interval) { + pj_time_val delay = { pjsip_cfg()->tls.keep_alive_interval, 0 }; pjsip_endpt_schedule_timer(tls->base.endpt, &tls->ka_timer, &delay); tls->ka_timer.id = PJ_TRUE; @@ -1780,9 +1780,9 @@ static void tls_keep_alive_timer(pj_timer_heap_t *th, pj_timer_entry *e) pj_gettimeofday(&now); PJ_TIME_VAL_SUB(now, tls->last_activity); - if (now.sec > 0 && now.sec < PJSIP_TLS_KEEP_ALIVE_INTERVAL) { + if (now.sec > 0 && now.sec < pjsip_cfg()->tls.keep_alive_interval) { /* There has been activity, so don't send keep-alive */ - delay.sec = PJSIP_TLS_KEEP_ALIVE_INTERVAL - now.sec; + delay.sec = pjsip_cfg()->tls.keep_alive_interval - now.sec; delay.msec = 0; pjsip_endpt_schedule_timer(tls->base.endpt, &tls->ka_timer, @@ -1810,7 +1810,7 @@ static void tls_keep_alive_timer(pj_timer_heap_t *th, pj_timer_entry *e) } /* Register next keep-alive */ - delay.sec = PJSIP_TLS_KEEP_ALIVE_INTERVAL; + delay.sec = pjsip_cfg()->tls.keep_alive_interval; delay.msec = 0; pjsip_endpt_schedule_timer(tls->base.endpt, &tls->ka_timer, |