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

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Tue Oct 26 09:31:16 PDT 2004


Author: karl
Date: 2004-10-26 09:31:16 -0700 (Tue, 26 Oct 2004)
New Revision: 8107

Modified:
   icecast/trunk/icecast/src/connection.c
Log:
small updates. reject source client with invalid mountpoint, avoid aliasing
issues with queue and id, and change handler to avoid leaving clients on the
connection queue (rare)


Modified: icecast/trunk/icecast/src/connection.c
===================================================================
--- icecast/trunk/icecast/src/connection.c	2004-10-26 15:37:34 UTC (rev 8106)
+++ icecast/trunk/icecast/src/connection.c	2004-10-26 16:31:16 UTC (rev 8107)
@@ -76,11 +76,10 @@
 } thread_queue_t;
 
 static mutex_t _connection_mutex;
-static unsigned long _current_id = 0;
+static volatile unsigned long _current_id = 0;
 static int _initialized = 0;
-static cond_t _pool_cond;
 
-static con_queue_t *_queue = NULL;
+static volatile con_queue_t *_queue = NULL;
 static mutex_t _queue_mutex;
 
 static thread_queue_t *_conhands = NULL;
@@ -97,7 +96,6 @@
     thread_mutex_create(&_queue_mutex);
     thread_mutex_create(&move_clients_mutex);
     thread_rwlock_create(&_source_shutdown_rwlock);
-    thread_cond_create(&_pool_cond);
     thread_cond_create(&global.shutdown_cond);
 
     _initialized = 1;
@@ -108,7 +106,6 @@
     if (!_initialized) return;
     
     thread_cond_destroy(&global.shutdown_cond);
-    thread_cond_destroy(&_pool_cond);
     thread_rwlock_destroy(&_source_shutdown_rwlock);
     thread_mutex_destroy(&_queue_mutex);
     thread_mutex_destroy(&_connection_mutex);
@@ -264,17 +261,11 @@
     
     thread_mutex_lock(&_queue_mutex);
     node->con = con;
-    node->next = _queue;
+    node->next = (con_queue_t *)_queue;
     _queue = node;
     thread_mutex_unlock(&_queue_mutex);
-
 }
 
-static void _signal_pool(void)
-{
-    thread_cond_signal(&_pool_cond);
-}
-
 static void _push_thread(thread_queue_t **queue, thread_type *thread_id)
 {
     /* create item */
@@ -342,13 +333,12 @@
 
     i = 0;
 
-    thread_cond_broadcast(&_pool_cond);
     id = _pop_thread(&_conhands);
     while (id != NULL) {
         thread_join(id);
-        _signal_pool();
         id = _pop_thread(&_conhands);
     }
+    INFO0("All connection threads down");
 }
 
 void connection_accept_loop(void)
@@ -372,7 +362,6 @@
 
         if (con) {
             _add_connection(con);
-            _signal_pool();
         }
     }
 
@@ -392,9 +381,13 @@
     con_queue_t *oldnode = NULL;
     connection_t *con = NULL;
 
+    /* common case, no new connections so don't bother taking locks */
+    if (_queue == NULL)
+        return NULL;
+
     thread_mutex_lock(&_queue_mutex);
     if (_queue) {
-        node = _queue;
+        node = (con_queue_t *)_queue;
         while (node->next) {
             oldnode = node;
             node = node->next;
@@ -423,7 +416,6 @@
     con->event = event_data;
 
     _add_connection(con);
-    _signal_pool();
 }
 
 
@@ -508,7 +500,7 @@
 
         return 0;
     }
-    WARN1("Request to add source when maximum source limit"
+    WARN1("Request to add source when maximum source limit "
             "reached %d", global.sources);
 
     global_unlock();
@@ -681,6 +673,13 @@
 
     INFO1("Source logging in at mountpoint \"%s\"", uri);
                 
+    if (uri[0] != '/')
+    {
+        WARN0 ("source mountpoint not starting with /");
+        client_send_401 (client);
+        return;
+    }
+
     if (!connection_check_source_pass(parser, uri)) {
         /* We commonly get this if the source client is using the wrong
          * protocol: attempt to diagnose this and return an error
@@ -708,6 +707,7 @@
     else
     {
         client_send_404 (client, "Mountpoint in use");
+        WARN1 ("Mountpoint %s in use", uri);
     }
 }
 
@@ -964,11 +964,7 @@
     client_t *client;
 
     while (global.running == ICE_RUNNING) {
-        memset(header, 0, 4096);
 
-        thread_cond_wait(&_pool_cond);
-        if (global.running != ICE_RUNNING) break;
-
         /* grab a connection and set the socket to blocking */
         while ((con = _get_connection())) {
 
@@ -991,7 +987,8 @@
             sock_set_blocking(con->sock, SOCK_BLOCK);
 
             /* fill header with the http header */
-            if (util_read_header(con->sock, header, 4096) == 0) {
+            memset(header, 0, sizeof (header));
+            if (util_read_header(con->sock, header, sizeof (header)) == 0) {
                 /* either we didn't get a complete header, or we timed out */
                 connection_close(con);
                 continue;
@@ -1035,6 +1032,7 @@
                 }
 
                 free(uri);
+                continue;
             } 
             else if(httpp_parse_icy(parser, header, strlen(header))) {
                 /* TODO: Map incoming icy connections to /icy_0, etc. */
@@ -1050,6 +1048,7 @@
                 avl_tree_unlock(global.source_tree);
 
                 _handle_source_request(con, parser, mount);
+                continue;
             }
             else {
                 ERROR0("HTTP request parsing failed");
@@ -1058,7 +1057,9 @@
                 continue;
             }
         }
+        thread_sleep (100000);
     }
+    DEBUG0 ("Connection thread done");
 
     return NULL;
 }



More information about the commits mailing list