[xiph-cvs] cvs commit: icecast/src source.c source.h

Karl Heyes karl at xiph.org
Thu Feb 26 08:51:45 PST 2004



karl        04/02/26 11:51:44

  Modified:    src      source.c source.h
  Log:
  separate source initialisation, and collect the YP setup code into one area

Revision  Changes    Path
1.78      +62 -61    icecast/src/source.c

Index: source.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -r1.77 -r1.78
--- source.c	26 Feb 2004 11:56:48 -0000	1.77
+++ source.c	26 Feb 2004 16:51:43 -0000	1.78
@@ -345,38 +345,17 @@
 }
 
 
-void *source_main(void *arg)
+static void source_init (source_t *source)
 {
-    source_t *source = (source_t *)arg;
-    source_t *fallback_source;
-    char buffer[4096];
-    long bytes, sbytes;
-    int ret;
-    client_t *client;
-    avl_node *client_node;
-
-    refbuf_t *refbuf, *abuf;
-    int data_done;
-
+    ice_config_t *config = config_get_config();
+    char *listenurl;
+    int listen_url_size;
 #ifdef USE_YP
     char *s;
     long current_time;
     int    i;
     char *ai;
-#endif
-
-    ice_config_t *config;
-    char *hostname;
-    char *listenurl;
-    int listen_url_size;
-    int port;
 
-    config = config_get_config();
-    
-    hostname = strdup(config->hostname);
-    port = config->port;
-
-#ifdef USE_YP
     for (i=0;i<config->num_yp_directories;i++) {
         if (config->yp_url[i]) {
             source->ypdata[source->num_yp_directories] = yp_create_ypdata();
@@ -388,20 +367,7 @@
             source->num_yp_directories++;
         }
     }
-#endif
     
-    config_release_config();
-
-    /* grab a read lock, to make sure we get a chance to cleanup */
-    thread_rwlock_rlock(source->shutdown_rwlock);
-
-    /* start off the statistics */
-    source->listeners = 0;
-    stats_event_inc(NULL, "sources");
-    stats_event_inc(NULL, "source_total_connections");
-    stats_event(source->mount, "listeners", "0");
-    stats_event(source->mount, "type", source->format->format_description);
-#ifdef USE_YP
     source->audio_info = util_dict_new();
     /* ice-* is icecast, icy-* is shoutcast */
     if ((s = httpp_getvar(source->parser, "ice-url"))) {
@@ -462,12 +428,11 @@
             free(source->ypdata[i]->listen_url);
         }
         /* 6 for max size of port */
-        listen_url_size = strlen("http://") + 
-            strlen(hostname) + 
-            strlen(":") + 6 + strlen(source->mount) + 1;
-        source->ypdata[i]->listen_url = malloc(listen_url_size);
-        sprintf(source->ypdata[i]->listen_url, "http://%s:%d%s", 
-                hostname, port, source->mount);
+        listen_url_size = strlen("http://") + strlen(config->hostname) +
+            strlen(":") + 6 + strlen (source->mount) + 1;
+        source->ypdata[i]->listen_url = malloc (listen_url_size);
+        sprintf (source->ypdata[i]->listen_url, "http://%s:%d%s",
+                config->hostname, config->port, source->mount);
     }
 
     if(source->yp_public) {
@@ -485,20 +450,23 @@
         }
     }
 #endif
+
     /* 6 for max size of port */
-    listen_url_size = strlen("http://") + 
-    strlen(hostname) + strlen(":") + 6 + strlen(source->mount) + 1;
-    
-    listenurl = malloc(listen_url_size);
-    memset(listenurl, '\000', listen_url_size);
-    sprintf(listenurl, "http://%s:%d%s", hostname, port, source->mount);
-    stats_event(source->mount, "listenurl", listenurl);
-    if (hostname) {
-        free(hostname);
-    }
+    listen_url_size = strlen("http://") + strlen(config->hostname) +
+        strlen(":") + 6 + strlen(source->mount) + 1;
+
+    listenurl = malloc (listen_url_size);
+    memset (listenurl, '\000', listen_url_size);
+    snprintf (listenurl, listen_url_size, "http://%s:%d%s",
+            config->hostname, config->port, source->mount);
+    config_release_config();
+
+    stats_event (source->mount, "listenurl", listenurl);
+
     if (listenurl) {
         free(listenurl);
     }
+
     if (source->dumpfilename != NULL)
     {
         source->dumpfile = fopen (source->dumpfilename, "ab");
@@ -509,6 +477,16 @@
         }
     }
 
+    /* grab a read lock, to make sure we get a chance to cleanup */
+    thread_rwlock_rlock (source->shutdown_rwlock);
+
+    /* start off the statistics */
+    source->listeners = 0;
+    stats_event_inc (NULL, "sources");
+    stats_event_inc (NULL, "source_total_connections");
+    stats_event (source->mount, "listeners", "0");
+    stats_event (source->mount, "type", source->format->format_description);
+    
     sock_set_blocking (source->con->sock, SOCK_NONBLOCK);
 
     DEBUG0("Source creation complete");
@@ -521,7 +499,10 @@
     ** loop or jingle track or whatever the fallback is used for
     */
 
-    if(source->fallback_override && source->fallback_mount) {
+    if (source->fallback_override && source->fallback_mount)
+    {
+        source_t *fallback_source;
+
         avl_tree_rlock(global.source_tree);
         fallback_source = source_find_mount(source->fallback_mount);
 
@@ -530,6 +511,21 @@
 
         avl_tree_unlock(global.source_tree);
     }
+}
+
+
+void source_main (source_t *source)
+{
+    char buffer[4096];
+    long bytes, sbytes;
+    int ret;
+    client_t *client;
+    avl_node *client_node;
+
+    refbuf_t *refbuf, *abuf;
+    int data_done;
+
+    source_init (source);
 
     while (global.running == ICE_RUNNING && source->running) {
         ret = source->format->get_buffer(source->format, NULL, 0, &refbuf);
@@ -782,13 +778,18 @@
     /* we have de-activated the source now, so no more clients will be
      * added, now move the listeners we have to the fallback (if any)
      */
-    avl_tree_rlock(global.source_tree);
-    fallback_source = source_find_mount (source->fallback_mount);
+    if (source->fallback_mount)
+    {
+        source_t *fallback_source;
 
-    if (fallback_source != NULL)
-        source_move_clients (source, fallback_source);
+        avl_tree_rlock(global.source_tree);
+        fallback_source = source_find_mount (source->fallback_mount);
 
-    avl_tree_unlock (global.source_tree);
+        if (fallback_source != NULL)
+            source_move_clients (source, fallback_source);
+
+        avl_tree_unlock (global.source_tree);
+    }
 
     /* delete this sources stats */
     stats_event_dec(NULL, "sources");
@@ -808,7 +809,7 @@
        therefore reserved */
     source_clear_source (source);
 
-    return NULL;
+    return;
 }
 
 static int _compare_clients(void *compare_arg, void *a, void *b)

<p><p>1.23      +1 -1      icecast/src/source.h

Index: source.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- source.h	26 Feb 2004 11:56:48 -0000	1.22
+++ source.h	26 Feb 2004 16:51:43 -0000	1.23
@@ -71,7 +71,7 @@
 int source_free_source(void *key);
 void source_move_clients (source_t *source, source_t *dest);
 int source_remove_client(void *key);
-void *source_main(void *arg);
+void source_main(source_t *source);
 
 extern mutex_t move_clients_mutex;
 

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list