[Freeswitch-svn] [commit] r10134 - freeswitch/trunk/src/mod/event_handlers/mod_event_socket

Freeswitch SVN anthm at freeswitch.org
Thu Oct 23 17:58:09 EDT 2008


Author: anthm
Date: Thu Oct 23 17:58:09 2008
New Revision: 10134

Modified:
   freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c

Log:
cleanup

Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	(original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	Thu Oct 23 17:58:09 2008
@@ -163,10 +163,27 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+
+static void expire_listener(listener_t **listener)
+{
+	void *pop;
+	
+	switch_thread_rwlock_unlock((*listener)->rwlock);
+	switch_core_hash_destroy(&(*listener)->event_hash);
+	switch_core_destroy_memory_pool(&(*listener)->pool);
+	
+	while (switch_queue_trypop((*listener)->event_queue, &pop) == SWITCH_STATUS_SUCCESS) {
+		switch_event_t *pevent = (switch_event_t *) pop;
+		switch_event_destroy(&pevent);
+	}
+
+	*listener = NULL;
+}
+
 static void event_handler(switch_event_t *event)
 {
 	switch_event_t *clone = NULL;
-	listener_t *l;
+	listener_t *l, *lp;
 
 	switch_assert(event != NULL);
 
@@ -174,20 +191,24 @@
 		return;
 	}
 
+	lp = listen_list.listeners;
+
 	switch_mutex_lock(listen_list.mutex);
-	for (l = listen_list.listeners; l; l = l->next) {
+	while(lp) {
 		uint8_t send = 0;
-
+		
+		l = lp;
+		lp = lp->next;
+		
 		if (!switch_test_flag(l, LFLAG_EVENTS)) {
 			continue;
 		}
-
+		
 		if (switch_test_flag(l, LFLAG_STATEFUL) && l->timeout && switch_timestamp(NULL) - l->last_flush > l->timeout) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Stateful Listener %u has expired\n", l->id);
 			remove_listener(l);
-			switch_thread_rwlock_unlock(l->rwlock);
-			switch_core_hash_destroy(&l->event_hash);
-			switch_core_destroy_memory_pool(&l->pool);
+			expire_listener(&l);
+			continue;
 		}
 
 		if (l->event_list[SWITCH_EVENT_ALL]) {
@@ -559,9 +580,7 @@
 			stream->write_function(stream, "<data>\n <reply type=\"success\">listener %u destroyed</reply>\n", listener->id);
 			xmlize_listener(listener, stream);
 			stream->write_function(stream, "</data>\n");
-			switch_thread_rwlock_unlock(listener->rwlock);
-			switch_core_hash_destroy(&listener->event_hash);
-			switch_core_destroy_memory_pool(&listener->pool);
+			expire_listener(&listener);
 			goto end;
 		} else {
 			stream->write_function(stream, "<data><reply type=\"error\">Can't find listener</reply></data>\n");
@@ -600,7 +619,7 @@
 					listener->ebuf = switch_xml_toxml(xml, SWITCH_FALSE);
 					switch_xml_free(xml);
 				} else {
-					stream->write_function(stream, "-ERR XML Error\n");
+					stream->write_function(stream, "<data><reply type=\"error\">XML Render Error</reply></data>\n");
 					break;
 				}
 



More information about the Freeswitch-svn mailing list