Skip to content

Commit f968f1a

Browse files
authored
Avoid call disconnection due to request timeout when network change happens. (pjsip#2737)
1 parent b8e5030 commit f968f1a

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

pjsip/include/pjsip/sip_config.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ typedef struct pjsip_cfg_t
181181
*/
182182
pj_bool_t accept_multiple_sdp_answers;
183183

184+
/**
185+
* Don't disconnect the INVITE session after an outgoing request
186+
* gets timed out or responded with 408 (request timeout).
187+
*
188+
* Default is PJ_FALSE.
189+
*/
190+
pj_bool_t keep_inv_after_tsx_timeout;
191+
184192
} endpt;
185193

186194
/** Transaction layer settings. */

pjsip/src/pjsip-ua/sip_inv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,8 +4082,8 @@ static pj_bool_t handle_uac_tsx_response(pjsip_inv_session *inv,
40824082
if (inv->state != PJSIP_INV_STATE_DISCONNECTED &&
40834083
((tsx->status_code == PJSIP_SC_CALL_TSX_DOES_NOT_EXIST &&
40844084
tsx->method.id != PJSIP_CANCEL_METHOD) ||
4085-
tsx->status_code == PJSIP_SC_REQUEST_TIMEOUT ||
4086-
tsx->status_code == PJSIP_SC_TSX_TIMEOUT))
4085+
(tsx->status_code == PJSIP_SC_REQUEST_TIMEOUT &&
4086+
!pjsip_cfg()->endpt.keep_inv_after_tsx_timeout)))
40874087
{
40884088
pjsip_tx_data *bye;
40894089
pj_status_t status;

pjsip/src/pjsip/sip_config.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ pjsip_cfg_t pjsip_sip_cfg_var =
3636
PJSIP_RESOLVE_HOSTNAME_TO_GET_INTERFACE,
3737
0,
3838
PJSIP_ENCODE_SHORT_HNAME,
39-
PJSIP_ACCEPT_MULTIPLE_SDP_ANSWERS
39+
PJSIP_ACCEPT_MULTIPLE_SDP_ANSWERS,
40+
0
4041
},
4142

4243
/* Transaction settings */

pjsip/src/pjsua-lib/pjsua_core.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,6 +3832,15 @@ static void restart_listener_cb(void *user_data)
38323832
}
38333833

38343834

3835+
static void ip_change_put_back_inv_config(void *user_data)
3836+
{
3837+
PJ_UNUSED_ARG(user_data);
3838+
3839+
PJ_LOG(4,(THIS_FILE,"IP change stops ignoring request timeout"));
3840+
pjsip_cfg()->endpt.keep_inv_after_tsx_timeout = PJ_FALSE;
3841+
}
3842+
3843+
38353844
PJ_DEF(pj_status_t) pjsua_handle_ip_change(const pjsua_ip_change_param *param)
38363845
{
38373846
pj_status_t status = PJ_SUCCESS;
@@ -3850,6 +3859,21 @@ PJ_DEF(pj_status_t) pjsua_handle_ip_change(const pjsua_ip_change_param *param)
38503859
}
38513860

38523861
PJ_LOG(3, (THIS_FILE, "Start handling IP address change"));
3862+
3863+
/* Avoid call disconnection due to request timeout. Some requests may
3864+
* be in progress when network is changing, they may eventually get
3865+
* timed out and cause call disconnection.
3866+
*/
3867+
if (!pjsip_cfg()->endpt.keep_inv_after_tsx_timeout) {
3868+
pjsip_cfg()->endpt.keep_inv_after_tsx_timeout = PJ_TRUE;
3869+
3870+
/* Put it back after some time (transaction timeout setting value) */
3871+
pjsua_schedule_timer2(&ip_change_put_back_inv_config, NULL,
3872+
pjsip_cfg()->tsx.td);
3873+
3874+
PJ_LOG(4,(THIS_FILE,"IP change temporarily ignores request timeout"));
3875+
}
3876+
38533877
if (param->restart_listener) {
38543878
PJSUA_LOCK();
38553879
/* Restart listener/transport, handle_ip_change_on_acc() will

0 commit comments

Comments
 (0)