[xiph-commits] r16254 - icecast/trunk/icecast/src

karl at svn.xiph.org karl at svn.xiph.org
Fri Jul 10 08:08:31 PDT 2009


Author: karl
Date: 2009-07-10 08:08:30 -0700 (Fri, 10 Jul 2009)
New Revision: 16254

Modified:
   icecast/trunk/icecast/src/source.c
   icecast/trunk/icecast/src/stats.c
Log:
fix case of global listeners count becoming out of sync. It is possible that
connecting listeners will disconnect before any processing is done on them.


Modified: icecast/trunk/icecast/src/source.c
===================================================================
--- icecast/trunk/icecast/src/source.c	2009-07-10 11:29:02 UTC (rev 16253)
+++ icecast/trunk/icecast/src/source.c	2009-07-10 15:08:30 UTC (rev 16254)
@@ -193,6 +193,8 @@
 
 void source_clear_source (source_t *source)
 {
+    int c;
+
     DEBUG1 ("clearing source \"%s\"", source->mount);
 
     avl_tree_wlock (source->pending_tree);
@@ -212,16 +214,27 @@
         source->dumpfile = NULL;
     }
 
-    if (source->listeners)
-        stats_event_sub (NULL, "listeners", source->listeners);
-
     /* lets kick off any clients that are left on here */
     avl_tree_wlock (source->client_tree);
-    while (avl_get_first (source->client_tree))
+    c=0;
+    while (1)
     {
-        avl_delete (source->client_tree,
-                avl_get_first (source->client_tree)->key, _free_client);
+        avl_node *node = avl_get_first (source->client_tree);
+        if (node)
+        {
+            client_t *client = node->key;
+            if (client->respcode == 200)
+                c++; /* only count clients that have had some processing */
+            avl_delete (source->client_tree, client, _free_client);
+            continue;
+        }
+        break;
     }
+    if (c)
+    {
+        stats_event_sub (NULL, "listeners", source->listeners);
+        INFO2 ("%d active listeners on %s released", c, source->mount);
+    }
     avl_tree_unlock (source->client_tree);
 
     while (avl_get_first (source->pending_tree))
@@ -722,9 +735,10 @@
 
             if (client->con->error) {
                 client_node = avl_get_next(client_node);
+                if (client->respcode == 200)
+                    stats_event_dec (NULL, "listeners");
                 avl_delete(source->client_tree, (void *)client, _free_client);
                 source->listeners--;
-                stats_event_dec (NULL, "listeners");
                 DEBUG0("Client removed");
                 continue;
             }

Modified: icecast/trunk/icecast/src/stats.c
===================================================================
--- icecast/trunk/icecast/src/stats.c	2009-07-10 11:29:02 UTC (rev 16253)
+++ icecast/trunk/icecast/src/stats.c	2009-07-10 15:08:30 UTC (rev 16254)
@@ -458,7 +458,11 @@
             case STATS_EVENT_ADD:
                 value = atoi (node->value)+atoi (event->value);
                 break;
+            case STATS_EVENT_SUB:
+                value = atoll (node->value) - atoll (event->value);
+                break;
             default:
+                WARN2 ("unhandled event (%d) for %s", event->action, event->source);
                 break;
         }
         str = malloc (16);



More information about the commits mailing list