[xiph-commits] r9177 - icecast/branches/kh/icecast/src

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Sun Apr 24 18:22:30 PDT 2005


Author: karl
Date: 2005-04-24 18:22:27 -0700 (Sun, 24 Apr 2005)
New Revision: 9177

Modified:
   icecast/branches/kh/icecast/src/stats.c
Log:
when a stats listener exits, perform an unregister, to avoid bad pointer
references, and handle it as a client so that it is logged in the access log


Modified: icecast/branches/kh/icecast/src/stats.c
===================================================================
--- icecast/branches/kh/icecast/src/stats.c	2005-04-24 04:45:44 UTC (rev 9176)
+++ icecast/branches/kh/icecast/src/stats.c	2005-04-25 01:22:27 UTC (rev 9177)
@@ -599,6 +599,25 @@
 }
 
 /* you must have the _stats_mutex locked here */
+static void _unregister_listener(stats_event_t **queue)
+{
+    event_listener_t **prev = (event_listener_t **)&_event_listeners,
+                     *current = *prev;
+    while (current)
+    {
+        if (current->queue == queue)
+        {
+            *prev = current->next;
+            free (current);
+            break;
+        }
+        prev = &current->next;
+        current = *prev;
+    }
+}
+
+
+/* you must have the _stats_mutex locked here */
 static void _register_listener(stats_event_t **queue, mutex_t *mutex)
 {
     event_listener_t *node;
@@ -660,15 +679,18 @@
     return event;
 }
 
-static int _send_event_to_client(stats_event_t *event, connection_t *con)
+static int _send_event_to_client(stats_event_t *event, client_t *client)
 {
-    int ret;
+    int ret = -1, len;
+    char buf [200];
 
     /* send data to the client!!!! */
-    ret = sock_write(con->sock, "EVENT %s %s %s\n",
+    len = snprintf (buf, sizeof (buf), "EVENT %s %s %s\n",
             (event->source != NULL) ? event->source : "global",
             event->name ? event->name : "null",
             event->value ? event->value : "null");
+    if (len > 0 && len < sizeof (buf))
+        ret = client_send_bytes (client, buf, len);
 
     return (ret == -1) ? 0 : 1;
 }
@@ -761,6 +783,7 @@
     mutex_t local_event_mutex;
     stats_event_t *event;
 
+    INFO0 ("stats client starting");
     /* increment the thread count */
     thread_mutex_lock(&_stats_mutex);
     _stats_threads++;
@@ -774,7 +797,7 @@
         thread_mutex_lock(&local_event_mutex);
         event = _get_event_from_queue(&local_event_queue);
         if (event != NULL) {
-            if (!_send_event_to_client(event, client->con)) {
+            if (!_send_event_to_client(event, client)) {
                 _free_event(event);
                 thread_mutex_unlock(&local_event_mutex);
                 break;
@@ -789,12 +812,15 @@
         thread_mutex_unlock(&local_event_mutex);
     }
 
-    thread_mutex_destroy(&local_event_mutex);
-
     thread_mutex_lock(&_stats_mutex);
+    _unregister_listener (&local_event_queue);
     _stats_threads--;
     thread_mutex_unlock(&_stats_mutex);
 
+    thread_mutex_destroy(&local_event_mutex);
+    client_destroy (client);
+    INFO0 ("stats client finished");
+
     return NULL;
 }
 



More information about the commits mailing list