Instead of using compile-time constants PJSIP_TCP_KEEP_ALIVE_INTERVAL and PJSIP_TLS_KEEP_ALIVE_INTERVAL, use writable variables (sub-fields of pjsip_cfg_t) initialized with the compile-time values -------------- next part -------------- Index: pjsip/include/pjsip/sip_config.h =================================================================== --- pjsip/include/pjsip/sip_config.h (revision 3689) +++ pjsip/include/pjsip/sip_config.h (revision 3691) @@ -217,6 +217,30 @@ } 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; Index: pjsip/src/pjsip/sip_transport_tcp.c =================================================================== --- pjsip/src/pjsip/sip_transport_tcp.c (revision 3689) +++ pjsip/src/pjsip/sip_transport_tcp.c (revision 3691) @@ -1134,8 +1134,8 @@ tcp_destroy(&tcp->base, status); } else { /* 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); @@ -1491,8 +1491,8 @@ 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; @@ -1518,9 +1518,9 @@ 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, @@ -1547,7 +1547,7 @@ } /* 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, Index: pjsip/src/pjsip/sip_config.c =================================================================== --- pjsip/src/pjsip/sip_config.c (revision 3689) +++ pjsip/src/pjsip/sip_config.c (revision 3691) @@ -49,6 +49,16 @@ /* Client registration client */ { PJSIP_REGISTER_CLIENT_CHECK_CONTACT + }, + + /* TCP transport settings */ + { + PJSIP_TCP_KEEP_ALIVE_INTERVAL + }, + + /* TLS transport settings */ + { + PJSIP_TLS_KEEP_ALIVE_INTERVAL } }; Index: pjsip/src/pjsip/sip_transport_tls.c =================================================================== --- pjsip/src/pjsip/sip_transport_tls.c (revision 3689) +++ pjsip/src/pjsip/sip_transport_tls.c (revision 3691) @@ -1288,8 +1288,8 @@ 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); @@ -1704,8 +1704,8 @@ 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; @@ -1737,9 +1737,9 @@ 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, @@ -1767,7 +1767,7 @@ } /* 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,