4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.5 2008/02/14 10:34:47 james
14 * *** empty log message ***
16 * Revision 1.4 2008/02/14 10:34:30 james
17 * *** empty log message ***
19 * Revision 1.3 2008/02/14 02:46:44 james
20 * *** empty log message ***
22 * Revision 1.2 2008/02/14 00:57:58 james
23 * *** empty log message ***
25 * Revision 1.1 2008/02/13 18:05:06 james
26 * *** empty log message ***
34 client_msg (IPC_Msg * m, Context * c)
39 case IPC_MSG_TYPE_NOOP:
41 case IPC_MSG_TYPE_DEBUG:
42 fprintf (stderr, "%p [%d] %s\n", m, m->hdr.size, m->debug.msg);
44 case IPC_MSG_TYPE_KEY:
45 vt102_send (c, m->key.key);
48 fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
53 client_free (Client * c)
59 fprintf (stderr, "Client at %p freed\n", c);
63 clients_new_client (Clients * cs, Socket * s, Context * ctx)
67 c = (Client *) malloc (sizeof (Client));
76 fprintf (stderr, "Client at %p created\n", c);
79 if (ipc_msg_send_debug (s, "new_client"))
86 clients_reap (Clients * cs)
91 for (p = &cs->head; *p;)
111 Clients *ret = (Clients *) malloc (sizeof (Clients));
120 clients_pre_select (Clients * cs, fd_set * rfds, fd_set * wfds)
124 for (c = cs->head; c; c = c->next)
126 socket_pre_select (c->s, rfds, wfds);
131 clients_post_select (Clients * cs, Context * ctx, fd_set * rfds,
137 for (c = cs->head; c; c = c->next)
139 if (socket_post_select (c->s, rfds, wfds))
147 client_msg (c->s->msg, ctx);
148 socket_consume_msg (c->s);
159 clients_shutdown (Clients * cs)
163 for (c = cs->head; c; c = c->next)
178 send_status (Clients * cs, char *msg)
180 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_status)];
181 IPC_Msg_status *m = (IPC_Msg_status *) mbuf;
188 len = strlen (msg) + 1;
192 if (len > IPC_MAX_BUF)
195 m->size = len + sizeof (IPC_Msg_status);
196 m->type = IPC_MSG_TYPE_STATUS;
197 strncpy (m->status, msg, IPC_MAX_BUF);
198 m->status[IPC_MAX_BUF - 1] = 0;
200 for (c = cs->head; c; c = c->next)
203 if (ipc_msg_send (c->s, (IPC_Msg *) m))
212 send_output (Clients * cs, void *buf, int len)
214 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_term)];
215 IPC_Msg_term *m = (IPC_Msg_term *) mbuf;
221 if (len > IPC_MAX_BUF)
224 m->size = len + sizeof (IPC_Msg_term);
225 m->type = IPC_MSG_TYPE_TERM;
227 memcpy (m->term, buf, len);
229 for (c = cs->head; c; c = c->next)
232 if (ipc_msg_send (c->s, (IPC_Msg *) m))
241 send_history (History * h, Client * c)
245 HISTORY_INC (h, rptr);
247 HISTORY_INC (h, rptr);
248 while (rptr != h->wptr)
250 History_ent *l = &h->lines[rptr];
254 if (ipc_msg_send_history (c->s, l))
258 HISTORY_INC (h, rptr);
263 send_vt102 (VT102 * v, Client * c)
265 if (ipc_msg_send_vt102 (c->s, v))