diff options
Diffstat (limited to 'apps/mainloop.c')
-rw-r--r-- | apps/mainloop.c | 75 |
1 files changed, 35 insertions, 40 deletions
diff --git a/apps/mainloop.c b/apps/mainloop.c index dd553e3..5772214 100644 --- a/apps/mainloop.c +++ b/apps/mainloop.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.23 2008/03/06 16:49:05 james + * *** empty log message *** + * * Revision 1.22 2008/03/03 06:04:42 james * *** empty log message *** * @@ -121,7 +124,6 @@ static char rcsid[] = #include "clients.h" -Context *context; typedef struct { @@ -378,6 +380,7 @@ check_status (Context * c, Clients * cs) static int msg_from_server (ANSI * a, IPC_Msg * m, Context * c) { +int err=0; switch (m->hdr.type) { @@ -398,11 +401,11 @@ msg_from_server (ANSI * a, IPC_Msg * m, Context * c) if (a->one_shot) { a->one_shot (a, &c->v->crt); - return 1; + err++;/*Simulate a fatal write error enclosing tty*/ } break; case IPC_MSG_TYPE_TERM: - tty_parse (c, m->term.term, m->term.len); + err+=tty_parse (c, m->term.term, m->term.len); break; case IPC_MSG_TYPE_STATUS: cmd_new_status (c->d, c, m->status.status); @@ -410,54 +413,46 @@ msg_from_server (ANSI * a, IPC_Msg * m, Context * c) default: fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); } - return 0; + return err; } void -mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, - ANSI * ansi, Log * log, int nhistory, CRT_Pos * size) +mainloop ( Context *c, ANSI *ansi,Socket * server_socket, Socket * client_socket) { fd_set rfds, wfds; - Context c = { 0 }; Clients *clients; - context = &c; + c->tp = tty_parser_new (); + c->u = utf8_new (); - c.tp = tty_parser_new (); - c.u = utf8_new (); - - c.v = vt102_new (size); - c.h = history_new (nhistory); - c.l = log; /* are we being fed by a tty or a socket */ if (client_socket) { if (server_socket) abort (); - c.k = keydis_ipc_new (client_socket); + c->k = keydis_ipc_new (client_socket); } else { - if (!tty) + if (!c->t) abort (); - c.t = tty; - c.k = keydis_vt102_new (); + c->k = keydis_vt102_new (); } /* do we have an upstream terminal to talk to */ /* if so start a command parser */ if (ansi) { - c.d = cmd_new (); + c->d = cmd_new (); } else { - c.d = NULL; + c->d = NULL; } - vt102_reset (&c); + vt102_reset (c); if (server_socket) @@ -475,18 +470,18 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, { struct timeval tv = { 0, 250000 }; - if ((c.d) && (c.d->disconnect)) + if ((c->d) && (c->d->disconnect)) break; /*update the status lines, locally or remotely */ - if (c.t) - check_status (&c, clients); + if (c->t) + check_status (c, clients); FD_ZERO (&rfds); FD_ZERO (&wfds); - if (c.t) - tty_pre_select (c.t, &rfds, &wfds); + if (c->t) + tty_pre_select (c->t, &rfds, &wfds); if (server_socket) { @@ -513,24 +508,24 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, Client *new_client; /*New client connexion */ new_client = - clients_new_client (clients, new_client_socket, &c); + clients_new_client (clients, new_client_socket, c); - send_history (c.h, new_client); - send_vt102 (c.v, new_client); + send_history (c->h, new_client); + send_vt102 (c->v, new_client); } } - clients_post_select (clients, &c, &rfds, &wfds); + clients_post_select (clients, c, &rfds, &wfds); } /*any data from the port */ - if (c.t && FD_ISSET (c.t->rfd, &rfds)) + if (c->t && FD_ISSET (c->t->rfd, &rfds)) { char buf[IPC_MAX_BUF]; int red; - red = c.t->recv (c.t, buf, sizeof (buf)); + red = c->t->recv (c->t, buf, sizeof (buf)); if (red < 0) break; @@ -539,7 +534,8 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, { if (clients) send_output (clients, buf, red); - tty_parse (&c, buf, red); + if (tty_parse (c, buf, red)) + break; } } @@ -548,19 +544,16 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, /*any data from the server */ if (client_socket) { - int one_shot; if (socket_post_select (client_socket, &rfds, &wfds)) break; while (client_socket->msg) { - if (msg_from_server (ansi, client_socket->msg, &c)) - one_shot++; + if (msg_from_server (ansi, client_socket->msg, c)) + break; socket_consume_msg (client_socket); } - if (one_shot) - break; } @@ -568,10 +561,12 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, if (ansi) { if (ansi->dispatch) - ansi->dispatch (ansi, &c); + if (ansi->dispatch (ansi, c)) + break; if (ansi->update) - ansi->update (ansi, &c); + if (ansi->update (ansi, c)) + break; } } |