X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=client.c;h=038fc0134e52adcc041fa52c152a321b9818b58e;hb=408458ad84180244b6a2ac327d13685bfb2b0867;hp=6ea5e7e1b1d2601cb84c3c532fab85cd6f32481b;hpb=7e57898039560a94313e04ca61716ae00719b150;p=paraslash.git diff --git a/client.c b/client.c index 6ea5e7e1..038fc013 100644 --- a/client.c +++ b/client.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2009 Andre Noll + * Copyright (C) 1997-2011 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -7,7 +7,6 @@ /** \file client.c the client program used to connect to para_server */ #include -#include #include #include "para.h" @@ -19,15 +18,17 @@ #include "stdin.h" #include "stdout.h" #include "client.h" +#include "buffer_tree.h" #include "error.h" INIT_CLIENT_ERRLISTS; +static struct sched sched; static struct client_task *ct; static struct stdin_task sit; static struct stdout_task sot; -static void supervisor_post_select(__a_unused struct sched *s, struct task *t) +static void supervisor_post_select(struct sched *s, struct task *t) { if (ct->task.error < 0) { t->error = ct->task.error; @@ -35,20 +36,13 @@ static void supervisor_post_select(__a_unused struct sched *s, struct task *t) } if (ct->status == CL_SENDING) { stdin_set_defaults(&sit); - sit.buf = para_malloc(sit.bufsize), - register_task(&sit.task); - ct->inbuf = sit.buf; - ct->in_loaded = &sit.loaded; - ct->in_error = &sit.task.error; + register_task(s, &sit.task); t->error = -E_TASK_STARTED; return; } if (ct->status == CL_RECEIVING) { stdout_set_defaults(&sot); - sot.bufp = &ct->buf; - sot.loaded = &ct->loaded; - sot.input_error = &ct->task.error; - register_task(&sot.task); + register_task(s, &sot.task); t->error = -E_TASK_STARTED; return; } @@ -59,10 +53,9 @@ static struct task svt = { .status = "supervisor task" }; -static int client_loglevel; /* loglevel */ +static int client_loglevel = LL_ERROR; /* loglevel */ INIT_STDERR_LOGGING(client_loglevel); - /** * The client program to connect to para_server. * @@ -90,13 +83,29 @@ int main(int argc, char *argv[]) init_random_seed_or_die(); s.default_timeout.tv_sec = 1; s.default_timeout.tv_usec = 0; - ret = client_open(argc, argv, &ct, &client_loglevel); - if (ret < 0) /* can not use PARA_LOG here because ct is NULL */ - exit(EXIT_FAILURE); - register_task(&svt); - ret = schedule(&s); + + /* + * We add buffer tree nodes for stdin and stdout even though + * only one of them will be needed. This simplifies the code + * a bit wrt. to the buffer tree setup. + */ + sit.btrn = btr_new_node(&(struct btr_node_description) + EMBRACE(.name = "stdin")); + ret = client_open(argc, argv, &ct, &client_loglevel, sit.btrn, NULL, &sched); if (ret < 0) - PARA_ERROR_LOG("%s\n", para_strerror(-ret)); + goto out; + sot.btrn = btr_new_node(&(struct btr_node_description) + EMBRACE(.name = "stdout", .parent = ct->btrn)); + register_task(&sched, &svt); + ret = schedule(&sched); +out: client_close(ct); - return ret >= 0? EXIT_SUCCESS: EXIT_FAILURE; + btr_free_node(sit.btrn); + btr_free_node(sot.btrn); + if (ret < 0) { + /* can not use PARA_LOG here because ct is NULL */ + fprintf(stderr, "%s\n", para_strerror(-ret)); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; }