1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-09-29 15:25:24 +00:00

sip: origin: Handle nua_shutdown() timeout gracefully

If we don't handle the timeout explicitly we would never leave the
`while (!self->is_nua_shutdown)` loop.
This commit is contained in:
Evangelos Ribeiro Tzaras 2021-09-02 18:00:13 +02:00
parent bede9f42e8
commit a3d91d92b5

View file

@ -95,6 +95,7 @@ struct _CallsSipOrigin
/* Needed to handle shutdown correctly. See sip_callback and dispose method */
gboolean is_nua_shutdown;
gboolean is_shutdown_success;
CallsAccountState state;
@ -737,8 +738,14 @@ sip_callback (nua_event_t event,
case nua_r_shutdown:
/* see also deinit_sip () */
g_debug ("response to nua_shutdown: %03d %s", status, phrase);
if (status == 200)
if (status == 200) {
origin->is_nua_shutdown = TRUE;
origin->is_shutdown_success = TRUE;
}
else if (status == 500) {
origin->is_nua_shutdown = TRUE;
origin->is_shutdown_success = FALSE;
}
break;
/* Deprecated events */
@ -1019,38 +1026,44 @@ init_sip_account (CallsSipOrigin *self,
}
static void
static gboolean
deinit_sip_account (CallsSipOrigin *self)
{
g_assert (CALLS_IS_SIP_ORIGIN (self));
if (self->state == CALLS_ACCOUNT_NULL)
return;
return TRUE;
remove_calls (self, NULL);
if (self->nua) {
g_debug ("Requesting nua_shutdown ()");
self->is_nua_shutdown = FALSE;
self->is_shutdown_success = FALSE;
nua_shutdown (self->nua);
// need to wait for nua_r_shutdown event before calling nua_destroy ()
while (!self->is_nua_shutdown)
su_root_step (self->ctx->root, 100);
g_debug ("nua_shutdown () complete. Destroying nua handle");
if (!self->is_shutdown_success) {
g_warning ("nua_shutdown() timed out. Cannot proceed");
return FALSE;
}
g_debug ("nua_shutdown() complete. Destroying nua handle");
nua_destroy (self->nua);
self->nua = NULL;
}
self->state = CALLS_ACCOUNT_NULL;
return TRUE;
}
static void
on_network_changed (CallsSipOrigin *self)
{
deinit_sip_account (self);
init_sip_account (self, NULL);
if (deinit_sip_account (self))
init_sip_account (self, NULL);
}