for (ptr = bindings.head; ptr; lst = ptr, ptr = ptr->next) {
if ((listener && ptr->listener == listener) ||
- (pid && (&ptr->process.type == ERLANG_PID) && (!strcmp(pid->node, ptr->process.pid.node)) && pid->creation == ptr->process.pid.creation && pid->num == ptr->process.pid.num && pid->serial == ptr->process.pid.serial)) {
+ (pid && (ptr->process.type == ERLANG_PID) && !ei_compare_pids(&ptr->process.pid, pid))) {
if (bindings.head == ptr) {
if (ptr->next) {
bindings.head = ptr->next;
switch_mutex_unlock(listener->session_mutex);
}
+static void remove_session_elem_from_listener(listener_t *listener, session_elem_t *session)
+{
+ session_elem_t *s, *last = NULL;
+
+ if(!session)
+ return;
+
+ switch_mutex_lock(listener->session_mutex);
+ for(s = listener->session_list; s; s = s->next) {
+ if (s == session) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removing session\n");
+ if (last) {
+ last->next = s->next;
+ } else {
+ listener->session_list = s->next;
+ }
+ switch_channel_clear_flag(switch_core_session_get_channel(s->session), CF_CONTROLLED);
+ /* this allows the application threads to exit */
+ switch_clear_flag_locked(s, LFLAG_SESSION_ALIVE);
+ switch_core_session_rwunlock(s->session);
+ }
+ last = s;
+ }
+ switch_mutex_unlock(listener->session_mutex);
+}
+
+
+session_elem_t * find_session_elem_by_pid(listener_t *listener, erlang_pid *pid)
+{
+ session_elem_t *s = NULL;
+
+ switch_mutex_lock(listener->session_mutex);
+ for (s = listener->session_list; s; s = s->next) {
+ if (s->process.type == ERLANG_PID && ei_compare_pids(pid, &s->process.pid)) {
+ break;
+ }
+ }
+ switch_mutex_unlock(listener->session_mutex);
+
+ return s;
+}
+
+
static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, const char *key_name, const char *key_value,
switch_event_t *params, void *user_data)
{
case ERL_EXIT :
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_exit from %s <%d.%d.%d>\n", msg.from.node, msg.from.creation, msg.from.num, msg.from.serial);
remove_binding(NULL, &msg.from);
+ /* 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, find_session_elem_by_pid(listener, &msg.from));
/* TODO - check if this linked pid is any of the log/event handler processes and cleanup if it is. */
break;
default :
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got pid!\n");
+ ei_link(listener, pid, ei_self(listener->ec));
+
session_element->process.type = ERLANG_PID;
memcpy(&session_element->process.pid, pid, sizeof(erlang_pid));
switch_set_flag(session_element, LFLAG_SESSION_ALIVE);
switch_core_session_t *session;
switch_mutex_t *flag_mutex;
uint32_t flags;
- /* registered process name that will receive call notifications from this session */
struct erlang_process process;
switch_queue_t *event_queue;
struct session_elem *next;
void ei_x_print_msg(ei_x_buff *buf, erlang_pid *pid, int send);
int ei_sendto(ei_cnode *ec, int fd, struct erlang_process *process, ei_x_buff *buf);
void ei_hash_ref(erlang_ref *ref, char *output);
+int ei_compare_pids(erlang_pid *pid1, erlang_pid *pid2);
switch_status_t initialise_ei(struct ei_cnode_s *ec);
#define ei_encode_switch_event(_b, _e) ei_encode_switch_event_tag(_b, _e, "event")