]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
cleanup
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 23 Oct 2008 21:58:09 +0000 (21:58 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 23 Oct 2008 21:58:09 +0000 (21:58 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10134 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/event_handlers/mod_event_socket/mod_event_socket.c

index 1cdb5e90bc15d42832bff4e55e139a1a6e169091..c36aeb73bfa94eb3ce8c19a0a5a06ad5d1cb0706 100644 (file)
@@ -163,10 +163,27 @@ static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_l
        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 @@ static void event_handler(switch_event_t *event)
                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 @@ SWITCH_STANDARD_API(event_manager_function)
                        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 @@ SWITCH_STANDARD_API(event_manager_function)
                                        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;
                                }