[Freeswitch-svn] [commit] r11500 - freeswitch/trunk/src/mod/event_handlers/mod_erlang_event

FreeSWITCH SVN andrew at freeswitch.org
Mon Jan 26 17:50:12 PST 2009


Author: andrew
Date: Mon Jan 26 19:50:12 2009
New Revision: 11500

Log:
Ensure events received while a pid session is being created aren't discarded but are queued instead


Modified:
   freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
   freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h

Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c	(original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c	Mon Jan 26 19:50:12 2009
@@ -487,6 +487,10 @@
 	sp = listener->session_list;
 	last = NULL;
 	while(sp) {
+		if (switch_test_flag(sp, LFLAG_WAITING_FOR_PID)) {
+			break;
+		}
+
 		if (!switch_test_flag(sp, LFLAG_OUTBOUND_INIT)) {
 			status = notify_new_session(listener, sp->session, sp->process);
 			if (status != SWITCH_STATUS_SUCCESS)
@@ -494,7 +498,7 @@
 			switch_set_flag(sp, LFLAG_OUTBOUND_INIT);
 		}
 		/* check event queue for this session */
-		if (switch_queue_trypop(sp->event_queue, &pop) == SWITCH_STATUS_SUCCESS) {			   
+		if (switch_queue_trypop(sp->event_queue, &pop) == SWITCH_STATUS_SUCCESS) {
 			switch_event_t *pevent = (switch_event_t *) pop;
 			
 			/* events from attached sessions are wrapped in a {call_event,<EVT>} tuple 
@@ -997,6 +1001,12 @@
 			erlang_pid *pid;
 			erlang_ref ref;
 
+			switch_set_flag(session_element, LFLAG_WAITING_FOR_PID);
+			switch_queue_create(&session_element->event_queue, SWITCH_CORE_QUEUE_LEN, switch_core_session_get_pool(session));
+			switch_mutex_init(&session_element->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+			/* attach the session to the listener */
+			add_session_elem_to_listener(listener,session_element);
+
 			if (!strcmp(function, "!")) {
 				/* send a message to request a pid */
 				ei_x_buff rbuf;
@@ -1022,6 +1032,7 @@
 				if (i > 50) { /* half a second timeout */
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "timed out!\n");
 					switch_core_session_rwunlock(session);
+					remove_session_elem_from_listener(listener,session_element);
 					return NULL;
 				}
 				i++;
@@ -1030,16 +1041,13 @@
 
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got pid!\n");
 
-			ei_link(listener, ei_self(listener->ec), pid);
-
 			session_element->process.type = ERLANG_PID;
 			memcpy(&session_element->process.pid, pid, sizeof(erlang_pid));
 			switch_set_flag(session_element, LFLAG_SESSION_ALIVE);
 			switch_clear_flag(session_element, LFLAG_OUTBOUND_INIT);
-			switch_queue_create(&session_element->event_queue, SWITCH_CORE_QUEUE_LEN, switch_core_session_get_pool(session));
-			switch_mutex_init(&session_element->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
-			/* attach the session to the listener */
-			add_session_elem_to_listener(listener,session_element);
+			switch_clear_flag(session_element, LFLAG_WAITING_FOR_PID);
+
+			ei_link(listener, ei_self(listener->ec), pid);
 		}
 	}
 	return session_element;

Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h	(original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h	Mon Jan 26 19:50:12 2009
@@ -35,8 +35,9 @@
 #define EI_DEBUG
 
 typedef enum {
-	LFLAG_OUTBOUND_INIT = (1 << 0), /* Erlang peer has been notified of this session */
-	LFLAG_SESSION_ALIVE
+	LFLAG_WAITING_FOR_PID = (1 << 0), /* waiting for a node to return a pid */
+	LFLAG_OUTBOUND_INIT = (1 << 1), /* Erlang peer has been notified of this session */
+	LFLAG_SESSION_ALIVE = (1 << 2),
 } session_flag_t;
 
 typedef enum {



More information about the Freeswitch-svn mailing list