chiark / gitweb /
movfeat wip
[trains.git] / hostside / client.c
1 /**/
2
3 #include <stdarg.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <errno.h>
7
8 #include "multiplex.h"
9 #include "../layout/dlist.h"
10
11 struct ClientList clients;
12
13 static void new_client(int fd, OutBufferError error,
14                        char *desc, Selector default_selectors) {
15   Client *cl;
16   int r;
17   
18   cl= mmalloc(sizeof(*cl));
19   cl->sel= default_selectors;
20   
21   cl->ci.out.desc= desc;
22   cl->ci.out.fd= fd;
23   cl->ci.out.error= error;
24   cmdin_new(&cl->ci);
25
26   LIST_LINK_TAIL(clients, cl);
27 }
28
29 static void stdin_error(OutBufferChain *ch, const char *e1, const char *e2) {
30   if (!e1)
31     exit(0);
32   fprintf(stderr,"stdin: %s: %s\n", e1, e2);
33   exit(12);  
34 }
35
36 void stdin_client(void) {
37   new_client(0, stdin_error, (char*)"stdin", sel_picio|sel_picioh);
38 }