X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=sync_filter.c;h=2ca2a657de6a79cb9b9e9ee3be47789e11f48e05;hp=efc10116f788a79bee5e2e75dfdfc0e036d06f1a;hb=HEAD;hpb=764e71ceb1e188086c08e38dfd52d45b67dc15ba diff --git a/sync_filter.c b/sync_filter.c index efc10116..20db1b1d 100644 --- a/sync_filter.c +++ b/sync_filter.c @@ -1,8 +1,4 @@ -/* - * Copyright (C) 2013 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2013 Andre Noll , see file COPYING. */ /** \file sync_filter.c Playback synchronization filter. */ @@ -106,8 +102,8 @@ static void sync_open(struct filter_node *fn) unsigned buddy_given; const struct lls_opt_result *r_b; - ctx = fn->private_data = para_calloc(sizeof(*ctx)); - INIT_LIST_HEAD(&ctx->buddies); + ctx = fn->private_data = zalloc(sizeof(*ctx)); + init_list_head(&ctx->buddies); /* create socket to listen for incoming packets */ ret = makesock( @@ -152,7 +148,7 @@ static void sync_open(struct filter_node *fn) close(fd); goto fail; } - buddy = para_malloc(sizeof(*buddy)); + buddy = alloc(sizeof(*buddy)); buddy->fd = fd; buddy->sbi = sbi + i; buddy->ping_received = false; @@ -180,12 +176,12 @@ static void *sync_setup(const struct lls_parse_result *lpr) r_b = FILTER_CMD_OPT_RESULT(SYNC, BUDDY, lpr); n = lls_opt_given(r_b); - sbi = para_malloc(n * sizeof(*sbi)); + sbi = arr_alloc(n, sizeof(*sbi)); PARA_INFO_LOG("initializing buddy info array of length %u\n", n); for (i = 0; i < n; i++) { const char *url = lls_string_val(i, r_b); size_t len = strlen(url); - char *host = para_malloc(len + 1); + char *host = alloc(len + 1); int port; struct addrinfo *ai; @@ -252,7 +248,7 @@ static void sync_set_timeout(struct sync_filter_context *ctx, tv_add(now, &to, &ctx->timeout); } -static void sync_pre_select(struct sched *s, void *context) +static void sync_pre_monitor(struct sched *s, void *context) { int ret; struct filter_node *fn = context; @@ -265,7 +261,7 @@ static void sync_pre_select(struct sched *s, void *context) ret = btr_node_status(fn->btrn, 0, BTR_NT_INTERNAL); if (ret < 0) return sched_min_delay(s); - para_fd_set(ctx->listen_fd, &s->rfds, &s->max_fileno); + sched_monitor_readfd(ctx->listen_fd, s); if (ret == 0) return; if (ctx->timeout.tv_sec == 0) { /* must ping buddies */ @@ -288,7 +284,7 @@ static struct sync_buddy *sync_find_buddy(struct sockaddr *addr, return NULL; } -static int sync_post_select(__a_unused struct sched *s, void *context) +static int sync_post_monitor(__a_unused struct sched *s, void *context) { int ret; struct filter_node *fn = context; @@ -328,7 +324,7 @@ static int sync_post_select(__a_unused struct sched *s, void *context) } ctx->ping_sent = true; } - if (FD_ISSET(ctx->listen_fd, &s->rfds)) { + if (sched_read_ok(ctx->listen_fd, s)) { char c; for (;;) { struct sockaddr src_addr; @@ -369,7 +365,8 @@ success: ret = -E_SYNC_COMPLETE; /* success */ goto out; fail: - PARA_WARNING_LOG("%s\n", para_strerror(-ret)); + if (ret != -E_EOF) + PARA_WARNING_LOG("%s\n", para_strerror(-ret)); out: sync_close_buddies(ctx); btr_splice_out_node(&fn->btrn); @@ -380,8 +377,8 @@ out: const struct filter lsg_filter_cmd_com_sync_user_data = { .setup = sync_setup, .open = sync_open, - .pre_select = sync_pre_select, - .post_select = sync_post_select, + .pre_monitor = sync_pre_monitor, + .post_monitor = sync_post_monitor, .close = sync_close, .teardown = sync_teardown };