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

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Wed Sep 15 07:21:04 PDT 2004


Author: karl
Date: 2004-09-15 07:21:04 -0700 (Wed, 15 Sep 2004)
New Revision: 7761

Modified:
   icecast/trunk/icecast/src/yp.c
Log:
the YP code could end up maintaining duplicate entries if the source
reconnect delay is very short.


Modified: icecast/trunk/icecast/src/yp.c
===================================================================
--- icecast/trunk/icecast/src/yp.c	2004-09-13 16:28:46 UTC (rev 7760)
+++ icecast/trunk/icecast/src/yp.c	2004-09-15 14:21:04 UTC (rev 7761)
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <curl/curl.h>
 
 #include <thread/thread.h>
 
@@ -29,7 +30,6 @@
 #include "source.h"
 #include "cfgfile.h"
 #include "stats.h"
-#include <curl/curl.h>
 
 #ifdef WIN32
 #define snprintf _snprintf
@@ -55,6 +55,7 @@
 typedef struct ypdata_tag
 {
     int remove;
+    int release;
     int cmd_ok;
 
     char *sid;
@@ -186,9 +187,9 @@
 
 
 /* search for a ypdata entry corresponding to a specific mountpoint */
-static ypdata_t *find_yp_mount (struct yp_server *server, const char *mount)
+static ypdata_t *find_yp_mount (ypdata_t *mounts, const char *mount)
 {
-    ypdata_t *yp = server->mounts;
+    ypdata_t *yp = mounts;
     while (yp)
     {
         if (strcmp (yp->mount, mount) == 0)
@@ -322,6 +323,7 @@
     yp_update = 1;
     yp->remove = 1;
     yp->process = do_yp_add;
+
     return 0;
 }
 
@@ -410,6 +412,12 @@
             return;
         s = tmp;
 
+        if (yp->release)
+        {
+            yp->process = do_yp_remove;
+            yp->next_update = 0;
+        }
+
         ret = yp->process (yp, s, len);
         if (ret == 0)
         {
@@ -849,11 +857,11 @@
     thread_rwlock_rlock (&yp_lock);
     while (server)
     {
-        ypdata_t *yp = find_yp_mount (server, mount);
+        ypdata_t *yp = find_yp_mount (server->mounts, mount);
         if (yp)
         {
-            DEBUG2 ("mark %s on YP %s", mount, server->url);
-            yp->process = do_yp_remove;
+            DEBUG2 ("release %s on YP %s", mount, server->url);
+            yp->release = 1;
             yp->next_update = 0;
         }
         server = server->next;
@@ -868,20 +876,32 @@
 {
     struct yp_server *server = active_yps;
     time_t trigger;
+    ypdata_t *search_list = NULL;
 
     thread_rwlock_rlock (&yp_lock);
     /* do update in 3 secs, give stats chance to update */
     trigger = time(NULL) + 3;
+    if (server)
+        search_list = server->mounts;
+
     while (server)
     {
-        ypdata_t *yp = find_yp_mount (server, mount);
+        ypdata_t *yp = find_yp_mount (search_list, mount);
         if (yp)
         {
+            /* we may of found old entries not purged yet, so skip them */
+            if (yp->release == 0 || yp->remove == 0)
+            {
+                search_list = yp->next;
+                continue;
+            }
             /* only force if touch */
             if (yp->process == do_yp_touch)
                 yp->next_update = trigger;
         }
         server = server->next;
+        if (server)
+            search_list = server->mounts;
     }
     thread_rwlock_unlock (&yp_lock);
 }



More information about the commits mailing list