Unify outbound session cleanup code, possibly fixes MODEVENT-47
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13900 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
216c5374b5
commit
c872e09265
|
@ -304,6 +304,7 @@ static listener_t * find_listener(char* nodename)
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void add_session_elem_to_listener(listener_t *listener, session_elem_t *session_element)
|
static void add_session_elem_to_listener(listener_t *listener, session_elem_t *session_element)
|
||||||
{
|
{
|
||||||
switch_mutex_lock(listener->session_mutex);
|
switch_mutex_lock(listener->session_mutex);
|
||||||
|
@ -312,6 +313,7 @@ static void add_session_elem_to_listener(listener_t *listener, session_elem_t *s
|
||||||
switch_mutex_unlock(listener->session_mutex);
|
switch_mutex_unlock(listener->session_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void remove_session_elem_from_listener(listener_t *listener, session_elem_t *session_element)
|
static void remove_session_elem_from_listener(listener_t *listener, session_elem_t *session_element)
|
||||||
{
|
{
|
||||||
session_elem_t *s, *last = NULL;
|
session_elem_t *s, *last = NULL;
|
||||||
|
@ -320,10 +322,9 @@ static void remove_session_elem_from_listener(listener_t *listener, session_elem
|
||||||
if (!session_element)
|
if (!session_element)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch_mutex_lock(listener->session_mutex);
|
|
||||||
for(s = listener->session_list; s; s = s->next) {
|
for(s = listener->session_list; s; s = s->next) {
|
||||||
if (s == session_element) {
|
if (s == session_element) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removing session element\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removing session element for %s\n", session_element->uuid_str);
|
||||||
if (last) {
|
if (last) {
|
||||||
last->next = s->next;
|
last->next = s->next;
|
||||||
} else {
|
} else {
|
||||||
|
@ -335,10 +336,17 @@ static void remove_session_elem_from_listener(listener_t *listener, session_elem
|
||||||
}
|
}
|
||||||
/* this allows the application threads to exit */
|
/* this allows the application threads to exit */
|
||||||
switch_clear_flag_locked(s, LFLAG_SESSION_ALIVE);
|
switch_clear_flag_locked(s, LFLAG_SESSION_ALIVE);
|
||||||
|
switch_safe_free(s);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
last = s;
|
last = s;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void remove_session_elem_from_listener_locked(listener_t *listener, session_elem_t *session_element) {
|
||||||
|
switch_mutex_lock(listener->session_mutex);
|
||||||
|
remove_session_elem_from_listener(listener, session_element);
|
||||||
switch_mutex_unlock(listener->session_mutex);
|
switch_mutex_unlock(listener->session_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -557,14 +565,7 @@ static switch_status_t check_attached_sessions(listener_t *listener)
|
||||||
if (pevent->event_id == SWITCH_EVENT_CHANNEL_DESTROY) {
|
if (pevent->event_id == SWITCH_EVENT_CHANNEL_DESTROY) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy event for attached session for %s\n", sp->uuid_str);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy event for attached session for %s\n", sp->uuid_str);
|
||||||
|
|
||||||
/* remove session from list */
|
|
||||||
if (last)
|
|
||||||
last->next = sp->next;
|
|
||||||
else
|
|
||||||
listener->session_list = sp->next;
|
|
||||||
|
|
||||||
/* this allows the application threads to exit */
|
/* this allows the application threads to exit */
|
||||||
switch_clear_flag_locked(sp, LFLAG_SESSION_ALIVE);
|
|
||||||
removed = sp;
|
removed = sp;
|
||||||
|
|
||||||
ei_x_new_with_version(&ebuf);
|
ei_x_new_with_version(&ebuf);
|
||||||
|
@ -583,7 +584,7 @@ static switch_status_t check_attached_sessions(listener_t *listener)
|
||||||
}
|
}
|
||||||
sp = sp->next;
|
sp = sp->next;
|
||||||
if (removed) {
|
if (removed) {
|
||||||
switch_safe_free(removed)
|
remove_session_elem_from_listener(listener, removed);
|
||||||
} else {
|
} else {
|
||||||
last = sp;
|
last = sp;
|
||||||
}
|
}
|
||||||
|
@ -682,7 +683,7 @@ static void handle_exit(listener_t *listener, erlang_pid *pid)
|
||||||
s->uuid_str);
|
s->uuid_str);
|
||||||
/* TODO - if a spawned process that was handling an outbound call fails.. what do we do with the call? */
|
/* TODO - if a spawned process that was handling an outbound call fails.. what do we do with the call? */
|
||||||
}
|
}
|
||||||
remove_session_elem_from_listener(listener, s);
|
remove_session_elem_from_listener_locked(listener, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listener->log_process.type == ERLANG_PID && !ei_compare_pids(&listener->log_process.pid, pid)) {
|
if (listener->log_process.type == ERLANG_PID && !ei_compare_pids(&listener->log_process.pid, pid)) {
|
||||||
|
@ -1167,7 +1168,7 @@ session_elem_t* attach_call_to_spawned_process(listener_t* listener, char *modul
|
||||||
while (!(p = switch_core_hash_find(listener->spawn_pid_hash, hash)) || p == &globals.WAITING) {
|
while (!(p = switch_core_hash_find(listener->spawn_pid_hash, hash)) || p == &globals.WAITING) {
|
||||||
if (i > 50) { /* half a second timeout */
|
if (i > 50) { /* half a second timeout */
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Timed out when waiting for outbound pid\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Timed out when waiting for outbound pid\n");
|
||||||
remove_session_elem_from_listener(listener,session_element);
|
remove_session_elem_from_listener_locked(listener,session_element);
|
||||||
switch_core_hash_insert(listener->spawn_pid_hash, hash, &globals.TIMEOUT); /* TODO lock this? */
|
switch_core_hash_insert(listener->spawn_pid_hash, hash, &globals.TIMEOUT); /* TODO lock this? */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue