]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - sync_filter.c
net.c: Remove unused local_name().
[paraslash.git] / sync_filter.c
index 8c3570fda92d23ef25214cbcd1344e1831296a41..de30b168bf62e66172e9ac332532fbdebc153f29 100644 (file)
@@ -61,18 +61,17 @@ struct sync_filter_config {
 
 static void sync_close_buddy(struct sync_buddy *buddy)
 {
-       if (buddy->fd < 0)
-               return;
-       PARA_DEBUG_LOG("closing %s\n", buddy->sbi->url);
+       PARA_DEBUG_LOG("closing %s, fd %d\n", buddy->sbi->url, buddy->fd);
        close(buddy->fd);
-       buddy->fd = -1;
+       list_del(&buddy->node);
+       free(buddy);
 }
 
 static void sync_close_buddies(struct sync_filter_context *ctx)
 {
-       struct sync_buddy *buddy;
+       struct sync_buddy *buddy, *tmp;
 
-       FOR_EACH_BUDDY(buddy, &ctx->buddies)
+       FOR_EACH_BUDDY_SAFE(buddy, tmp, &ctx->buddies)
                sync_close_buddy(buddy);
 }
 
@@ -222,7 +221,7 @@ fail:
 }
 
 /*
- * True if we sent a packet to all budies and received a packet from each
+ * True if we sent a packet to all buddies and received a packet from each
  * enabled buddy.
  */
 static bool sync_complete(struct sync_filter_context *ctx)
@@ -244,6 +243,8 @@ static void sync_disable_active_buddies(struct sync_filter_context *ctx)
        FOR_EACH_BUDDY(buddy, &ctx->buddies) {
                if (buddy->sbi->disabled)
                        continue;
+               if (buddy->ping_received == true)
+                       continue;
                PARA_NOTICE_LOG("disabling %s\n", buddy->sbi->url);
                buddy->sbi->disabled = true;
        }
@@ -328,11 +329,10 @@ static int sync_post_select(__a_unused struct sched *s, void *context)
                                buddy->sbi->url, buddy->sbi->disabled?
                                "disabled" : "enabled");
                        ret = xwrite(buddy->fd, &c, 1);
-                       sync_close_buddy(buddy);
                        if (ret < 0) {
                                PARA_WARNING_LOG("failed to write to %s: %s\n",
                                        buddy->sbi->url, para_strerror(-ret));
-                               list_del(&buddy->node);
+                               sync_close_buddy(buddy);
                        }
                }
                ctx->ping_sent = true;
@@ -361,14 +361,14 @@ static int sync_post_select(__a_unused struct sched *s, void *context)
                                        buddy->sbi->url);
                                buddy->sbi->disabled = false;
                        }
-                       list_del(&buddy->node);
+                       buddy->ping_received = true;
                }
        }
        if (!sync_complete(ctx))
                return 1;
        /*
         * Although all enabled buddies are in sync we do not splice out
-        * ourselves immediately. We rather wait until the timout expires,
+        * ourselves immediately. We rather wait until the timeout expires,
         * or the buddy list has become empty. This opens a time window
         * for disabled buddies to become enabled by sending us a packet.
         */