Skip to content

Commit

Permalink
Update listener restart in IP change: don't create/restart listener i…
Browse files Browse the repository at this point in the history
…f currently no listener, also update docs that bound address setting will be reset. (#3873)
  • Loading branch information
nanangizz authored Mar 15, 2024
1 parent ed40439 commit a974061
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pjsip/include/pjsua-lib/pjsua.h
Original file line number Diff line number Diff line change
Expand Up @@ -2787,6 +2787,9 @@ typedef struct pjsua_ip_change_param
{
/**
* If set to PJ_TRUE, this will restart the transport listener.
* Note that if restarting listener is enabled and the listener is
* configured with a bound address, the address will be reset
* so it will bind to any address (e.g: IPv4 "0.0.0.0" or IPv6 "::").
*
* Default : PJ_TRUE
*/
Expand Down
22 changes: 19 additions & 3 deletions pjsip/src/pjsip/sip_transport_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,22 @@ PJ_DEF(pj_status_t) pjsip_tcp_transport_restart(pjsip_tpfactory *factory,
pj_status_t status = PJ_SUCCESS;
struct tcp_listener *listener = (struct tcp_listener *)factory;

/* Just update the published address if currently no listener */
if (!listener->asock) {
PJ_LOG(3,(factory->obj_name,
"TCP restart requested while no listener created, "
"update the published address only"));

status = update_factory_addr(listener, a_name);
if (status != PJ_SUCCESS)
return status;

/* Set transport info. */
update_transport_info(listener);

return PJ_SUCCESS;
}

lis_close(listener);

status = pjsip_tcp_transport_lis_start(factory, local, a_name);
Expand All @@ -1753,15 +1769,15 @@ PJ_DEF(pj_status_t) pjsip_tcp_transport_restart(pjsip_tpfactory *factory,

return status;
}

status = pjsip_tpmgr_register_tpfactory(listener->tpmgr,
&listener->factory);
if (status != PJ_SUCCESS) {
tcp_perror(listener->factory.obj_name,
"Unable to register the transport listener", status);
} else {
listener->is_registered = PJ_TRUE;
}
listener->is_registered = PJ_TRUE;
}

return status;
}
Expand Down
16 changes: 16 additions & 0 deletions pjsip/src/pjsip/sip_transport_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,22 @@ PJ_DEF(pj_status_t) pjsip_tls_transport_restart(pjsip_tpfactory *factory,
pj_status_t status = PJ_SUCCESS;
struct tls_listener *listener = (struct tls_listener *)factory;

/* Just update the published address if currently no listener */
if (!listener->ssock) {
PJ_LOG(3,(factory->obj_name,
"TLS restart requested while no listener created, "
"update the published address only"));

status = update_factory_addr(listener, a_name);
if (status != PJ_SUCCESS)
return status;

/* Set transport info. */
update_transport_info(listener);

return PJ_SUCCESS;
}

lis_close(listener);

status = pjsip_tls_transport_lis_start(factory, local, a_name);
Expand Down

0 comments on commit a974061

Please sign in to comment.