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