4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.3 2008/02/14 02:46:44 james
14 * *** empty log message ***
16 * Revision 1.2 2008/02/14 00:57:58 james
17 * *** empty log message ***
19 * Revision 1.1 2008/02/13 18:05:06 james
20 * *** empty log message ***
28 client_msg (IPC_Msg * m, Context * c)
33 case IPC_MSG_TYPE_NOOP:
35 case IPC_MSG_TYPE_DEBUG:
36 fprintf (stderr, "%p [%d] %s\n", m, m->hdr.size, m->debug.msg);
38 case IPC_MSG_TYPE_KEY:
39 vt102_send (c, m->key.key);
42 fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
47 client_free (Client * c)
53 fprintf (stderr, "Client at %p freed\n", c);
57 clients_new_client (Clients * cs, Socket * s, Context * ctx)
61 c = (Client *) malloc (sizeof (Client));
70 fprintf (stderr, "Client at %p created\n", c);
73 if (ipc_msg_send_debug (s, "new_client"))
80 clients_reap (Clients * cs)
85 for (p = &cs->head; *p;)
105 Clients *ret = (Clients *) malloc (sizeof (Clients));
114 clients_pre_select (Clients * cs, fd_set * rfds, fd_set * wfds)
118 for (c = cs->head; c; c = c->next)
120 socket_pre_select (c->s, rfds, wfds);
125 clients_post_select (Clients * cs, Context * ctx, fd_set * rfds,
131 for (c = cs->head; c; c = c->next)
133 if (socket_post_select (c->s, rfds, wfds))
141 client_msg (c->s->msg, ctx);
142 socket_consume_msg (c->s);
152 clients_output (Clients * cs, void *buf, int len)
154 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_term)];
155 IPC_Msg_term *m = (IPC_Msg_term *) mbuf;
161 if (len > IPC_MAX_BUF)
164 m->size = len + sizeof (IPC_Msg_term);
165 m->type = IPC_MSG_TYPE_TERM;
167 memcpy (m->term, buf, len);
169 for (c = cs->head; c; c = c->next)
172 if (ipc_msg_send (c->s, (IPC_Msg *) m))
181 clients_shutdown (Clients * cs)
185 for (c = cs->head; c; c = c->next)