2 * Copyright (C) 1997-2010 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file client.c the client program used to connect to para_server */
10 #include <openssl/rc4.h>
17 #include "client.cmdline.h"
22 #include "buffer_tree.h"
27 static struct client_task *ct;
28 static struct stdin_task sit;
29 static struct stdout_task sot;
31 static void supervisor_post_select(__a_unused struct sched *s, struct task *t)
33 if (ct->task.error < 0) {
34 t->error = ct->task.error;
37 if (ct->status == CL_SENDING) {
38 stdin_set_defaults(&sit);
39 register_task(&sit.task);
40 t->error = -E_TASK_STARTED;
43 if (ct->status == CL_RECEIVING) {
44 stdout_set_defaults(&sot);
45 register_task(&sot.task);
46 t->error = -E_TASK_STARTED;
51 static struct task svt = {
52 .post_select = supervisor_post_select,
53 .status = "supervisor task"
56 static int client_loglevel = LL_ERROR; /* loglevel */
57 INIT_STDERR_LOGGING(client_loglevel);
60 * The client program to connect to para_server.
62 * \param argc Usual argument count.
63 * \param argv Usual argument vector.
65 * It registers two tasks: The client task that communicates with para_server
66 * and the supervisor task that minitors whether the client task intends to
67 * read from stdin or write to stdout.
69 * Once it has been determined whether the client command corresponds to a
70 * stdin command (addmood, addimg, ..), either the stdin task or the stdout
71 * task is set up to replace the supervisor task.
73 * \return EXIT_SUCCESS or EXIT_FAILURE
75 * \sa client_open(), stdin.c, stdout.c, para_client(1), para_server(1)
77 int main(int argc, char *argv[])
81 static struct sched s;
83 init_random_seed_or_die();
84 s.default_timeout.tv_sec = 1;
85 s.default_timeout.tv_usec = 0;
87 * We add buffer tree nodes for stdin and stdout even though
88 * only one of them will be needed. This simplifies the code
89 * a bit wrt. to the buffer tree setup.
91 sit.btrn = btr_new_node(&(struct btr_node_description)
92 EMBRACE(.name = "stdin"));
93 ret = client_open(argc, argv, &ct, &client_loglevel, sit.btrn, NULL);
96 sot.btrn = btr_new_node(&(struct btr_node_description)
97 EMBRACE(.name = "stdout", .parent = ct->btrn));
102 btr_free_node(sit.btrn);
103 btr_free_node(sot.btrn);
105 /* can not use PARA_LOG here because ct is NULL */
106 fprintf(stderr, "%s\n", para_strerror(-ret));