4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.4 2008/02/14 10:34:30 james
14 * *** empty log message ***
16 * Revision 1.3 2008/02/14 02:46:44 james
17 * *** empty log message ***
19 * Revision 1.2 2008/02/14 00:57:58 james
20 * *** empty log message ***
22 * Revision 1.1 2008/02/13 18:05:06 james
23 * *** empty log message ***
31 client_msg (IPC_Msg * m, Context * c)
36 case IPC_MSG_TYPE_NOOP:
38 case IPC_MSG_TYPE_DEBUG:
39 fprintf (stderr, "%p [%d] %s\n", m, m->hdr.size, m->debug.msg);
41 case IPC_MSG_TYPE_KEY:
42 vt102_send (c, m->key.key);
45 fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
50 client_free (Client * c)
56 fprintf (stderr, "Client at %p freed\n", c);
60 clients_new_client (Clients * cs, Socket * s, Context * ctx)
64 c = (Client *) malloc (sizeof (Client));
73 fprintf (stderr, "Client at %p created\n", c);
76 if (ipc_msg_send_debug (s, "new_client"))
83 clients_reap (Clients * cs)
88 for (p = &cs->head; *p;)
108 Clients *ret = (Clients *) malloc (sizeof (Clients));
117 clients_pre_select (Clients * cs, fd_set * rfds, fd_set * wfds)
121 for (c = cs->head; c; c = c->next)
123 socket_pre_select (c->s, rfds, wfds);
128 clients_post_select (Clients * cs, Context * ctx, fd_set * rfds,
134 for (c = cs->head; c; c = c->next)
136 if (socket_post_select (c->s, rfds, wfds))
144 client_msg (c->s->msg, ctx);
145 socket_consume_msg (c->s);
156 clients_shutdown (Clients * cs)
160 for (c = cs->head; c; c = c->next)
175 send_status (Clients * cs, char *msg)
177 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_status)];
178 IPC_Msg_status *m = (IPC_Msg_status *) mbuf;
188 if (len > IPC_MAX_BUF)
191 m->size = len + sizeof (IPC_Msg_status);
192 m->type = IPC_MSG_TYPE_STATUS;
193 strncpy(m->status,msg, IPC_MAX_BUF);
194 m->status[IPC_MAX_BUF-1]=0;
196 for (c = cs->head; c; c = c->next)
199 if (ipc_msg_send (c->s, (IPC_Msg *) m))
208 send_output (Clients * cs, void *buf, int len)
210 char mbuf[IPC_MAX_BUF + sizeof (IPC_Msg_term)];
211 IPC_Msg_term *m = (IPC_Msg_term *) mbuf;
217 if (len > IPC_MAX_BUF)
220 m->size = len + sizeof (IPC_Msg_term);
221 m->type = IPC_MSG_TYPE_TERM;
223 memcpy (m->term, buf, len);
225 for (c = cs->head; c; c = c->next)
228 if (ipc_msg_send (c->s, (IPC_Msg *) m))
237 send_history (History * h, Client * c)
241 HISTORY_INC (h, rptr);
243 HISTORY_INC (h, rptr);
244 while (rptr != h->wptr)
246 History_ent *l = &h->lines[rptr];
250 if (ipc_msg_send_history (c->s, l))
254 HISTORY_INC (h, rptr);
259 send_vt102 (VT102 * v, Client * c)
261 if (ipc_msg_send_vt102 (c->s, v))