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

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Tue May 31 19:05:08 PDT 2005


Author: karl
Date: 2005-05-31 19:05:04 -0700 (Tue, 31 May 2005)
New Revision: 9332

Modified:
   icecast/branches/kh/icecast/src/auth.c
   icecast/branches/kh/icecast/src/connection.c
   icecast/branches/kh/icecast/src/source.c
   icecast/branches/kh/icecast/src/source.h
Log:
drop source_t pending list, a leftover from previous migration, ended up
causing more work than needed


Modified: icecast/branches/kh/icecast/src/auth.c
===================================================================
--- icecast/branches/kh/icecast/src/auth.c	2005-05-31 02:48:40 UTC (rev 9331)
+++ icecast/branches/kh/icecast/src/auth.c	2005-06-01 02:05:04 UTC (rev 9332)
@@ -194,13 +194,6 @@
                 return 0;
             existing = existing->next;
         }
-        existing = source->pending_clients;
-        while (existing)
-        {
-            if (existing->username && strcmp (existing->username, client->username) == 0)
-                return 0;
-            existing = existing->next;
-        }
     }
     return 1;
 }
@@ -215,16 +208,14 @@
     int loop = 10;
     do
     {
-        unsigned int total;
         thread_mutex_lock (&source->lock);
-        total = source->new_listeners + source->listeners;
-        DEBUG2 ("max on %s is %lu", source->mount, source->max_listeners);
-        DEBUG2 ("pending %d, current %lu", source->new_listeners, source->listeners);
+        DEBUG3 ("max on %s is %ld (cur %lu)", source->mount,
+                source->max_listeners, source->listeners);
         if (source->max_listeners == -1)
             break;
         if (client->is_slave)
             break;
-        if (total < (unsigned int)source->max_listeners)
+        if (source->listeners < (unsigned long)source->max_listeners)
             break;
 
         if (loop && source->fallback_when_full && source->fallback_mount)
@@ -241,11 +232,10 @@
         return -1;
 
     } while (1);
-    /* lets add the client to the pending list */
-    source->new_listeners++;
-    client->next = source->pending_clients;
-    source->pending_clients = client;
-    thread_mutex_unlock (&source->lock);
+    /* lets add the client to the active list */
+    client->next = source->active_clients;
+    source->active_clients = client;
+    source->listeners++;
 
     client->write_to_client = format_generic_write_to_client;
     client->check_buffer = format_check_http_buffer;
@@ -253,6 +243,8 @@
 
     sock_set_blocking (client->con->sock, SOCK_NONBLOCK);
     sock_set_nodelay (client->con->sock);
+    thread_mutex_unlock (&source->lock);
+
     if (source->running == 0 && source->on_demand)
     {
         /* enable on-demand relay to start, wake up the slave thread */

Modified: icecast/branches/kh/icecast/src/connection.c
===================================================================
--- icecast/branches/kh/icecast/src/connection.c	2005-05-31 02:48:40 UTC (rev 9331)
+++ icecast/branches/kh/icecast/src/connection.c	2005-06-01 02:05:04 UTC (rev 9332)
@@ -738,7 +738,7 @@
     }
 
     client->respcode = 200;
-    if (sock_write (client->con->sock, "HTTP/1.0 200 OK\r\n\r\n") < 0)
+    if (sock_write (client->con->sock, "HTTP/1.0 200 OK\r\n\r\n") < 19)
     {
         client_destroy (client);
         ERROR0 ("failed to write header");

Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c	2005-05-31 02:48:40 UTC (rev 9331)
+++ icecast/branches/kh/icecast/src/source.c	2005-06-01 02:05:04 UTC (rev 9332)
@@ -97,8 +97,6 @@
         src->mount = strdup (mount);
         src->max_listeners = -1;
 
-        src->pending_clients_tail = &src->pending_clients;
-
         thread_mutex_create (src->mount, &src->lock);
 
         avl_insert (global.source_tree, src);
@@ -211,14 +209,6 @@
         source_free_client (source, client);
     }
     source->fast_clients_p = &source->active_clients;
-    while (source->pending_clients)
-    {
-        client_t *client = source->pending_clients;
-        source->pending_clients = client->next;
-        source_free_client (source, client);
-    }
-    source->pending_clients_tail = &source->pending_clients;
-    source->new_listeners = 0;
 
     format_free_plugin (source->format);
     source->format = NULL;
@@ -241,6 +231,7 @@
     source->queue_size = 0;
     source->queue_size_limit = 0;
     source->listeners = 0;
+    source->prev_listeners = 0;
     source->no_mount = 0;
     source->shoutcast_compat = 0;
     source->max_listeners = -1;
@@ -281,9 +272,6 @@
     if (source->active_clients)
         WARN1("active listeners on mountpoint %s", source->mount);
 
-    if (source->pending_clients)
-        WARN1("pending listeners on mountpoint %s", source->mount);
-
     thread_mutex_destroy (&source->lock);
 
     free (source->mount);
@@ -320,7 +308,7 @@
  */
 void source_move_clients (source_t *source, source_t *dest)
 {
-    unsigned int count = 0;
+    unsigned long count = 0;
     if (strcmp (source->mount, dest->mount) == 0)
     {
         WARN1 ("src and dst are the same \"%s\", skipping", source->mount);
@@ -370,36 +358,20 @@
             if (client->check_buffer != format_check_http_buffer)
             {
                 client_set_queue (client, NULL);
-                client->write_to_client = NULL;
             }
 
-            *dest->pending_clients_tail = client;
-            dest->pending_clients_tail = &client->next;
+            client->next = dest->active_clients;
+            dest->active_clients = client;
             count++;
         }
         if (count != source->listeners)
-            WARN2 ("count %u, listeners %lu", count, source->listeners);
-        count = 0;
-        while (source->pending_clients)
-        {
-            client_t *client = source->pending_clients;
-            source->pending_clients = client->next;
-            /* clients on pending have a unique refbuf containing headers
-             * so no need to change them here */
-            *dest->pending_clients_tail = client;
-            dest->pending_clients_tail = &client->next;
-            count++;
-        }
-        source->pending_clients_tail = &source->pending_clients;
-        if (count != source->new_listeners)
-            WARN2 ("count %u, new listeners %u", count, source->new_listeners);
-        
-        count = source->listeners + source->new_listeners;
-        INFO2 ("passing %d listeners to \"%s\"", count, dest->mount);
+            WARN2 ("count %lu, listeners %lu", count, source->listeners);
 
-        dest->new_listeners += count;
+        INFO2 ("passing %lu listeners to \"%s\"", count, dest->mount);
+
+        dest->listeners += count;
         source->listeners = 0;
-        source->new_listeners = 0;
+        source->listeners = 0;
         stats_event (source->mount, "listeners", "0");
 
     } while (0);
@@ -500,7 +472,8 @@
         {
             if (source->last_read + (time_t)source->timeout < current)
             {
-                DEBUG2 ("last read is %ld, current is %ld", source->last_read, current);
+                DEBUG3 ("last %ld, timeout %d, now %ld", (long)source->last_read, 
+                        source->timeout, (long)current);
                 WARN0 ("Disconnecting source due to socket timeout");
                 source->running = 0;
                 break;
@@ -629,7 +602,6 @@
 {
     client_t *client, **client_p;
     client_t *fast_clients = NULL, **fast_client_tail = &fast_clients;
-    unsigned int listeners = source->listeners;
 
     /* where do we start from */
     if (fast_clients_only)
@@ -675,8 +647,9 @@
         *client_p = fast_clients;
 
     /* has the listener count changed */
-    if (source->listeners != listeners)
+    if (source->listeners != source->prev_listeners)
     {
+        source->prev_listeners = source->listeners;
         INFO2("listener count on %s now %lu", source->mount, source->listeners);
         stats_event_args (source->mount, "listeners", "%lu", source->listeners);
         if (source->listeners == 0)
@@ -687,41 +660,6 @@
 }
 
 
-static void process_pending_clients (source_t *source)
-{
-    unsigned count = 0;
-    client_t *client = source->pending_clients;
-
-    while (client)
-    {
-        client_t *to_go = client;
-
-        client = client->next;
-        /*  trap from when clients have been moved */
-        if (to_go->write_to_client == NULL)
-        {
-            to_go->write_to_client = source->format->write_buf_to_client;
-            to_go->check_buffer = format_advance_queue;
-        }
-
-        to_go->next = source->active_clients;
-        source->active_clients = to_go;
-
-        count++;
-        source->new_listeners--;
-    }
-    source->pending_clients = NULL;
-    source->pending_clients_tail = &source->pending_clients;
-
-    if (count)
-    {
-        DEBUG1("Adding %d client(s)", count);
-        source->listeners += count;
-        stats_event_args (source->mount, "listeners", "%d", source->listeners);
-    }
-}
-
-
 static void source_init (source_t *source)
 {
     char *str = "0";
@@ -821,10 +759,6 @@
         if (source->queue_size > source->queue_size_limit)
             remove_from_q = 1;
 
-        /* add pending clients */
-        if (source->pending_clients)
-            process_pending_clients (source);
-
         process_listeners (source, 0, remove_from_q);
 
         /* lets reduce the queue, any lagging clients should of been
@@ -1230,7 +1164,7 @@
     else
     {
         char buf [10];
-        snprintf (buf, sizeof (buf), "%lu", source->max_listeners);
+        snprintf (buf, sizeof (buf), "%ld", source->max_listeners);
         stats_event (source->mount, "max_listeners", buf);
     }
     if (source->on_demand)

Modified: icecast/branches/kh/icecast/src/source.h
===================================================================
--- icecast/branches/kh/icecast/src/source.h	2005-05-31 02:48:40 UTC (rev 9331)
+++ icecast/branches/kh/icecast/src/source.h	2005-06-01 02:05:04 UTC (rev 9332)
@@ -39,10 +39,6 @@
     client_t *active_clients;
     client_t **fast_clients_p;
 
-    client_t *pending_clients;
-    client_t **pending_clients_tail;
-    unsigned int new_listeners;
-
     rwlock_t *shutdown_rwlock;
     util_dict *audio_info;
 
@@ -54,6 +50,7 @@
     FILE *dumpfile;
 
     unsigned long listeners;
+    unsigned long prev_listeners;
     long max_listeners;
     int yp_public;
     int fallback_override;



More information about the commits mailing list