X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=sync_filter.c;h=6a2a09462f9b1d452c8c997ac04dbfaba1f30521;hp=379b54b13395b20190e69543b57ed49ed3e569fe;hb=d385c301094dfca932c5be9c1429047794fb3706;hpb=d1e6b28f66e243516d01916f9125baee75dd98d6 diff --git a/sync_filter.c b/sync_filter.c index 379b54b1..6a2a0946 100644 --- a/sync_filter.c +++ b/sync_filter.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Andre Noll + * Copyright (C) 2013 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -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); } @@ -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; } @@ -258,10 +259,10 @@ static void sync_set_timeout(struct sync_filter_context *ctx, tv_add(now, &to, &ctx->timeout); } -static void sync_pre_select(struct sched *s, struct task *t) +static void sync_pre_select(struct sched *s, void *context) { int ret; - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = context; struct sync_filter_context *ctx = fn->private_data; struct sync_filter_config *sfc = fn->conf; @@ -295,10 +296,10 @@ static struct sync_buddy *sync_find_buddy(struct sockaddr *addr, return NULL; } -static int sync_post_select(__a_unused struct sched *s, struct task *t) +static int sync_post_select(__a_unused struct sched *s, void *context) { int ret; - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = context; struct sync_filter_context *ctx = fn->private_data; struct sync_filter_config *sfc = fn->conf; struct sync_buddy *buddy, *tmp; @@ -328,11 +329,10 @@ static int sync_post_select(__a_unused struct sched *s, struct task *t) 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,7 +361,7 @@ static int sync_post_select(__a_unused struct sched *s, struct task *t) buddy->sbi->url); buddy->sbi->disabled = false; } - list_del(&buddy->node); + buddy->ping_received = true; } } if (!sync_complete(ctx))