diff options
-rw-r--r-- | pjsip/include/pjsip-ua/sip_regc.h | 13 | ||||
-rw-r--r-- | pjsip/include/pjsip/sip_config.h | 18 | ||||
-rw-r--r-- | pjsip/src/pjsip-ua/sip_reg.c | 15 | ||||
-rw-r--r-- | pjsip/src/pjsip/sip_transport.c | 4 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_acc.c | 7 |
5 files changed, 53 insertions, 4 deletions
diff --git a/pjsip/include/pjsip-ua/sip_regc.h b/pjsip/include/pjsip-ua/sip_regc.h index 4ef4bbaa..c2aec0c8 100644 --- a/pjsip/include/pjsip-ua/sip_regc.h +++ b/pjsip/include/pjsip-ua/sip_regc.h @@ -265,6 +265,19 @@ PJ_DECL(pj_status_t) pjsip_regc_set_route_set(pjsip_regc *regc, PJ_DECL(pj_status_t) pjsip_regc_set_transport(pjsip_regc *regc, const pjsip_tpselector *sel); +/** + * Release the reference to current transport being used by the regc, if any. + * The regc keeps the reference to the last transport being used in order + * to prevent it from being destroyed. In some situation however, such as + * when the transport is disconnected, it is necessary to instruct the + * regc to release this reference so that the transport can be destroyed. + * See https://trac.pjsip.org/repos/ticket/1481 for background info. + * + * @param regc The client registration instance. + * + * @return PJ_SUCCESS on success, or the appropriate error code. + */ +PJ_DECL(pj_status_t) pjsip_regc_release_transport(pjsip_regc *regc); /** * Add headers to be added to outgoing REGISTER requests. diff --git a/pjsip/include/pjsip/sip_config.h b/pjsip/include/pjsip/sip_config.h index 3d0c0946..8efc8814 100644 --- a/pjsip/include/pjsip/sip_config.h +++ b/pjsip/include/pjsip/sip_config.h @@ -427,8 +427,9 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void) /** - * Idle timeout interval to be applied to transports with no usage - * before the transport is destroyed. Value is in seconds. + * Idle timeout interval to be applied to outgoing transports (i.e. client + * side) with no usage before the transport is destroyed. Value is in + * seconds. * * Default: 30 */ @@ -438,6 +439,19 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void) /** + * Idle timeout interval to be applied to incoming transports (i.e. server + * side) with no usage before the transport is destroyed. Server typically + * should let client close the connection, hence set this interval to a large + * value. Value is in seconds. + * + * Default: 600 + */ +#ifndef PJSIP_TRANSPORT_SERVER_IDLE_TIME +# define PJSIP_TRANSPORT_SERVER_IDLE_TIME 600 +#endif + + +/** * Maximum number of usages for a transport before a new transport is * created. This only applies for ephemeral transports such as TCP. * diff --git a/pjsip/src/pjsip-ua/sip_reg.c b/pjsip/src/pjsip-ua/sip_reg.c index 750e22f7..c02c17bb 100644 --- a/pjsip/src/pjsip-ua/sip_reg.c +++ b/pjsip/src/pjsip-ua/sip_reg.c @@ -440,6 +440,17 @@ PJ_DEF(pj_status_t) pjsip_regc_set_transport( pjsip_regc *regc, return PJ_SUCCESS; } +/* Release transport */ +PJ_DEF(pj_status_t) pjsip_regc_release_transport(pjsip_regc *regc) +{ + PJ_ASSERT_RETURN(regc, PJ_EINVAL); + if (regc->last_transport) { + pjsip_transport_dec_ref(regc->last_transport); + regc->last_transport = NULL; + } + return PJ_SUCCESS; +} + PJ_DEF(pj_status_t) pjsip_regc_add_headers( pjsip_regc *regc, const pjsip_hdr *hdr_list) @@ -1269,7 +1280,9 @@ PJ_DEF(pj_status_t) pjsip_regc_send(pjsip_regc *regc, pjsip_tx_data *tdata) pj_lock_acquire(regc->lock); /* Get last transport used and add reference to it */ - if (tdata->tp_info.transport != regc->last_transport) { + if (tdata->tp_info.transport != regc->last_transport && + status==PJ_SUCCESS) + { if (regc->last_transport) { pjsip_transport_dec_ref(regc->last_transport); regc->last_transport = NULL; diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c index 13b33e09..556868cf 100644 --- a/pjsip/src/pjsip/sip_transport.c +++ b/pjsip/src/pjsip/sip_transport.c @@ -857,7 +857,9 @@ PJ_DEF(pj_status_t) pjsip_transport_dec_ref( pjsip_transport *tp ) if (tp->is_shutdown) { delay.sec = delay.msec = 0; } else { - delay.sec = PJSIP_TRANSPORT_IDLE_TIME; + delay.sec = (tp->dir==PJSIP_TP_DIR_OUTGOING) ? + PJSIP_TRANSPORT_IDLE_TIME : + PJSIP_TRANSPORT_SERVER_IDLE_TIME; delay.msec = 0; } diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c index b8f0dd8e..5182ef56 100644 --- a/pjsip/src/pjsua-lib/pjsua_acc.c +++ b/pjsip/src/pjsua-lib/pjsua_acc.c @@ -2882,6 +2882,13 @@ void pjsua_acc_on_tp_state_changed(pjsip_transport *tp, continue; } + /* Release regc transport immediately + * See https://trac.pjsip.org/repos/ticket/1481 + */ + if (pjsua_var.acc[i].regc) { + pjsip_regc_release_transport(pjsua_var.acc[i].regc); + } + /* Schedule reregistration for this account */ schedule_reregistration(acc); } |