add more missing documentation
[paraslash.git] / client.c
1 /*
2 * Copyright (C) 1997-2007 Andre Noll <maan@systemlinux.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
17 */
18
19 /** \file client.c the client program used to connect to para_server */
20
21 #include "para.h"
22 #include "list.h"
23 #include "sched.h"
24 #include "client.cmdline.h"
25 #include "string.h"
26 #include "stdin.h"
27 #include "stdout.h"
28 #include "client.h"
29 #include "error.h"
30
31 INIT_CLIENT_ERRLISTS;
32
33 static struct private_client_data *pcd;
34 static struct stdin_task sit;
35 static struct stdout_task sot;
36
37
38 INIT_STDERR_LOGGING(pcd->conf.loglevel_arg);
39
40 static void client_event_handler(struct task *t)
41 {
42 struct private_client_data *p = t->private_data;
43
44 PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t->ret));
45 if (t->ret != -E_HANDSHAKE_COMPLETE) {
46 unregister_task(t);
47 p->eof = 1;
48 return;
49 }
50 if (p->status == CL_SENDING) {
51 stdin_set_defaults(&sit);
52 sit.buf = para_malloc(sit.bufsize),
53 register_task(&sit.task);
54 p->inbuf = sit.buf;
55 p->in_loaded = &sit.loaded;
56 p->in_eof = &sit.eof;
57 return;
58 }
59 stdout_set_defaults(&sot);
60 sot.buf = p->buf;
61 sot.loaded = &p->loaded;
62 sot.input_eof = &p->eof;
63 register_task(&sot.task);
64 }
65
66 /**
67 * the client program to connect to para_server
68 *
69 * \param argc usual argument count
70 * \param argv usual argument vector
71 *
72 * It registers two tasks: The client task that communicates with para_server
73 * and the standard out task that writes any output produced by the client task
74 * to standard out.
75 *
76 * \return EXIT_SUCCESS or EXIT_FAILURE
77 *
78 * \sa client_open(), stdout.c, stdout.h, para_client(1), para_server(1)
79 */
80 int main(int argc, char *argv[])
81 {
82
83 int ret;
84 struct sched s;
85
86 s.default_timeout.tv_sec = 1;
87 s.default_timeout.tv_usec = 0;
88 ret = client_open(argc, argv, &pcd);
89 if (ret < 0) /* can not use PARA_LOG here */
90 exit(EXIT_FAILURE);
91 pcd->task.event_handler = client_event_handler;
92 ret = sched(&s);
93 if (ret < 0)
94 PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
95 client_close(pcd);
96 return ret >= 0? EXIT_SUCCESS: EXIT_FAILURE;
97 }