From be42afab1c325fae5c3c270876a3447220adcca5 Mon Sep 17 00:00:00 2001 From: james <> Date: Fri, 7 Mar 2008 13:16:02 +0000 Subject: *** empty log message *** --- apps/clients.c | 165 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 106 insertions(+), 59 deletions(-) (limited to 'apps/clients.c') diff --git a/apps/clients.c b/apps/clients.c index 621c21c..0dcd863 100644 --- a/apps/clients.c +++ b/apps/clients.c @@ -1,4 +1,4 @@ -/* +/* * clients.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.19 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.18 2008/03/03 18:16:16 james * *** empty log message *** * @@ -74,6 +77,61 @@ static char rcsid[] = "$Id$"; #include #include "clients.h" + +void client_initialize(Client *c,Context *ctx) +{ + send_history (ctx->h, c); + send_vt102 (ctx->v, c); + c->initialized=1; +} + +void +client_execute_message (Client *client,IPC_Msg * m, Context * c) +{ + switch (m->hdr.type) { + case IPC_MSG_TYPE_NOOP: + break; + case IPC_MSG_TYPE_DEBUG: + log_f (c->l, "", m->debug.msg); + break; + case IPC_MSG_TYPE_KEY: + vt102_send (c, m->key.key); + break; + case IPC_MSG_TYPE_SETBAUD: + tty_set_baud (c->t, m->setbaud.baud); + tty_parse_reset (c); + log_f (c->l, "", m->setbaud.baud); + break; + case IPC_MSG_TYPE_SENDBREAK: + log_f (c->l, ""); + tty_send_break (c->t); + break; + case IPC_MSG_TYPE_SETFLOW: + log_f (c->l, "", m->setflow.flow ? "on" : "off"); + tty_set_flow (c->t, m->setflow.flow); + break; + case IPC_MSG_TYPE_SETANSI: + vt102_set_ansi (c->v, m->setansi.ansi); + break; + case IPC_MSG_TYPE_HANGUP: + log_f (c->l, ""); + tty_hangup (c->t); + break; + case IPC_MSG_TYPE_SETSIZE: + vt102_resize (c, m->setsize.winsize); + break; + case IPC_MSG_TYPE_RESET: + vt102_reset (c); + break; + case IPC_MSG_TYPE_INITIALIZE: + client_initialize(client,c); + break; + default: + log_f (c->l, "", m->hdr.type); + } +} + + void client_free (Client * c) { @@ -91,8 +149,9 @@ clients_new_client (Clients * cs, Socket * s, Context * ctx) { Client *c; - c = (Client *) malloc (sizeof (Client)); + c = (Client *) xmalloc (sizeof (Client)); + c->initialized=0; c->dead = 0; c->s = s; c->next = cs->head; @@ -117,27 +176,23 @@ clients_reap (Clients * cs) Client **p, *c; - for (p = &cs->head; *p;) - { - Client *c = *p; - - if (c->dead) - { - *p = c->next; - client_free (c); - cs->n--; - } - else - { - p = &(c->next); - } + for (p = &cs->head; *p;) { + Client *c = *p; + + if (c->dead) { + *p = c->next; + client_free (c); + cs->n--; + } else { + p = &(c->next); } + } } Clients * clients_new (void) { - Clients *ret = (Clients *) malloc (sizeof (Clients)); + Clients *ret = (Clients *) xmalloc (sizeof (Clients)); ret->n = 0; ret->head = NULL; @@ -150,10 +205,9 @@ clients_pre_select (Clients * cs, fd_set * rfds, fd_set * wfds) { Client *c; - for (c = cs->head; c; c = c->next) - { - socket_pre_select (c->s, rfds, wfds); - } + for (c = cs->head; c; c = c->next) { + socket_pre_select (c->s, rfds, wfds); + } } void @@ -163,21 +217,19 @@ clients_post_select (Clients * cs, Context * ctx, fd_set * rfds, Client *c; int deaded = 0; - for (c = cs->head; c; c = c->next) - { - if (socket_post_select (c->s, rfds, wfds)) - { - c->dead++; - deaded++; - } - - if (c->s->msg) - { - socket_execute_msg (c->s, ctx); - } + for (c = cs->head; c; c = c->next) { + if (socket_post_select (c->s, rfds, wfds)) { + c->dead++; + deaded++; + } + if (c->s->msg) { + client_execute_message (c,c->s->msg,ctx); + socket_consume_msg (c->s); } + } + if (deaded) clients_reap (cs); } @@ -188,10 +240,9 @@ clients_shutdown (Clients * cs) { Client *c; - for (c = cs->head; c; c = c->next) - { - c->dead++; - } + for (c = cs->head; c; c = c->next) { + c->dead++; + } clients_reap (cs); @@ -225,12 +276,11 @@ send_status (Clients * cs, char *msg) strncpy (m->status, msg, IPC_MAX_BUF); m->status[IPC_MAX_BUF - 1] = 0; - for (c = cs->head; c; c = c->next) - { - if (!c->dead) - if (ipc_msg_send (c->s, (IPC_Msg *) m)) - c->dead++; - } + for (c = cs->head; c; c = c->next) { + if (!c->dead && c->initialized) + if (ipc_msg_send (c->s, (IPC_Msg *) m)) + c->dead++; + } return len; } @@ -254,12 +304,11 @@ send_output (Clients * cs, void *buf, int len) m->len = len; memcpy (m->term, buf, len); - for (c = cs->head; c; c = c->next) - { - if (!c->dead) - if (ipc_msg_send (c->s, (IPC_Msg *) m)) - c->dead++; - } + for (c = cs->head; c; c = c->next) { + if (!c->dead && c->initialized) + if (ipc_msg_send (c->s, (IPC_Msg *) m)) + c->dead++; + } return len; @@ -273,18 +322,16 @@ send_history (History * h, Client * c) HISTORY_INC (h, rptr); HISTORY_INC (h, rptr); - while (rptr != h->wptr) - { - History_ent *l = &h->lines[rptr]; - if (l->valid) - { + while (rptr != h->wptr) { + History_ent *l = &h->lines[rptr]; + if (l->valid) { - if (ipc_msg_send_history (c->s, l)) - c->dead++; + if (ipc_msg_send_history (c->s, l)) + c->dead++; - } - HISTORY_INC (h, rptr); } + HISTORY_INC (h, rptr); + } } void -- cgit v1.2.3