Change year in Copyright comment from 2007 to 2008.
[paraslash.git] / client.c
1 /*
2 * Copyright (C) 1997-2008 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file client.c the client program used to connect to para_server */
8
9 #include "para.h"
10 #include "list.h"
11 #include "sched.h"
12 #include "client.cmdline.h"
13 #include "string.h"
14 #include "stdin.h"
15 #include "stdout.h"
16 #include "client.h"
17 #include "error.h"
18
19 INIT_CLIENT_ERRLISTS;
20
21 static struct private_client_data *pcd;
22 static struct stdin_task sit;
23 static struct stdout_task sot;
24
25
26 INIT_STDERR_LOGGING(pcd->conf.loglevel_arg);
27
28 static void client_event_handler(struct task *t)
29 {
30 struct private_client_data *p = t->private_data;
31
32 PARA_NOTICE_LOG("%s\n", para_strerror(-t->ret));
33 if (t->ret != -E_HANDSHAKE_COMPLETE) {
34 unregister_task(t);
35 p->error = t->ret;
36 return;
37 }
38 if (p->status == CL_SENDING) {
39 stdin_set_defaults(&sit);
40 sit.buf = para_malloc(sit.bufsize),
41 register_task(&sit.task);
42 p->inbuf = sit.buf;
43 p->in_loaded = &sit.loaded;
44 p->in_error = &sit.error;
45 return;
46 }
47 stdout_set_defaults(&sot);
48 sot.buf = p->buf;
49 sot.loaded = &p->loaded;
50 sot.input_error = &p->error;
51 register_task(&sot.task);
52 }
53
54 /**
55 * the client program to connect to para_server
56 *
57 * \param argc usual argument count
58 * \param argv usual argument vector
59 *
60 * It registers two tasks: The client task that communicates with para_server
61 * and the standard out task that writes any output produced by the client task
62 * to standard out.
63 *
64 * \return EXIT_SUCCESS or EXIT_FAILURE
65 *
66 * \sa client_open(), stdout.c, stdout.h, para_client(1), para_server(1)
67 */
68 int main(int argc, char *argv[])
69 {
70
71 int ret;
72 struct sched s;
73
74 s.default_timeout.tv_sec = 1;
75 s.default_timeout.tv_usec = 0;
76 ret = client_open(argc, argv, &pcd);
77 if (ret < 0) /* can not use PARA_LOG here */
78 exit(EXIT_FAILURE);
79 pcd->task.event_handler = client_event_handler;
80 ret = schedule(&s);
81 if (ret < 0)
82 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
83 client_close(pcd);
84 return ret >= 0? EXIT_SUCCESS: EXIT_FAILURE;
85 }