From ccc64e79a870d37ddff7afa92a41fd9a8dbecd42 Mon Sep 17 00:00:00 2001 From: james <> Date: Thu, 14 Feb 2008 00:57:58 +0000 Subject: *** empty log message *** --- apps/Makefile.am | 5 ++- apps/client.c | 50 ++++++++++++++++++++++ apps/client.h | 6 +++ apps/clients.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++----- apps/clients.h | 4 +- apps/sympathy.c | 8 +++- apps/sympathyd.c | 42 ++++++++++++++++--- 7 files changed, 221 insertions(+), 19 deletions(-) (limited to 'apps') diff --git a/apps/Makefile.am b/apps/Makefile.am index 6b4d868..f0f5881 100644 --- a/apps/Makefile.am +++ b/apps/Makefile.am @@ -7,6 +7,9 @@ # $Id$ # # $Log$ +# Revision 1.4 2008/02/14 00:57:58 james +# *** empty log message *** +# # Revision 1.3 2008/02/13 18:05:06 james # *** empty log message *** # @@ -26,7 +29,7 @@ noinst_PROGRAMS = sympathyd sympathy noinst_HEADERS=clients.h client.h sympathy_SOURCES = sympathy.c client.c -sympathy_LDADD = ../src/libsympathy.la -lutil +sympathy_LDADD = ../src/libsympathy.a -lutil sympathyd_SOURCES = sympathyd.c clients.c client.c sympathyd_LDADD = ../src/libsympathy.la -lutil diff --git a/apps/client.c b/apps/client.c index e1b650e..54f4c33 100644 --- a/apps/client.c +++ b/apps/client.c @@ -10,8 +10,58 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.2 2008/02/14 00:57:58 james + * *** empty log message *** + * * Revision 1.1 2008/02/13 18:05:06 james * *** empty log message *** * */ +#include +#include "client.h" + +static void client_msg(s) +{ + printf ("%p [%d] %s\n", s->msg, s->msg->hdr.size , s->msg->debug.msg ); + + + +} +void +client (void) +{ + Socket *s; + fd_set rfds, wfds; + + s = socket_connect ("socket"); + + + if (!s) + { + printf ("no socket"); + return; + } + + for (;;) + { + struct timeval tv = { 0, 100000 }; + + + FD_ZERO (&rfds); + FD_ZERO (&wfds); + + socket_pre_select (s, &rfds, &wfds); + + select (FD_SETSIZE, &rfds, &wfds, NULL, &tv); + + socket_post_select (s, &rfds, &wfds); + + while (s->msg) + { + client_msg(s); + socket_consume_msg (s); + } + } + +} diff --git a/apps/client.h b/apps/client.h index 52293d1..1f46781 100644 --- a/apps/client.h +++ b/apps/client.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.2 2008/02/14 00:57:58 james + * *** empty log message *** + * * Revision 1.1 2008/02/13 18:05:06 james * *** empty log message *** * @@ -20,4 +23,7 @@ #ifndef __CLIENT_H__ #define __CLIENT_H__ +void client(void); + + #endif /* __CLIENT_H__ */ diff --git a/apps/clients.c b/apps/clients.c index 234c0ed..6c70e9d 100644 --- a/apps/clients.c +++ b/apps/clients.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.2 2008/02/14 00:57:58 james + * *** empty log message *** + * * Revision 1.1 2008/02/13 18:05:06 james * *** empty log message *** * @@ -19,43 +22,145 @@ static char rcsid[] = "$Id$"; #include "clients.h" -void clients_output (Clients *c, void *_buf, int len) +void +client_free (Client * c) { + if (c->s) + socket_free (c->s); + free (c); + fprintf(stderr,"Client at %p freed\n",c); } -Clients *clients_new(void) +Client * +clients_new_client (Clients * cs, Socket * s, Context * ctx) { + Client *c; + + c = (Client *) malloc (sizeof (Client)); + + c->dead = 0; + c->s = s; + c->next = cs->head; + + cs->head = c; + cs->n++; + fprintf(stderr,"Client at %p created\n",c); -return NULL; + if (ipc_msg_send_debug (s, "new_client")) + c->dead++; + + return c; +} + +void +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); + } + } } -void clients_pre_select (Clients *c, fd_set *rfds, fd_set *wfds) +Clients * +clients_new (void) { + Clients *ret = (Clients *) malloc (sizeof (Clients)); + ret->n = 0; + ret->head = NULL; + return ret; } -void clients_post_select(Clients *c,Context *ctx, fd_set *rfds, fd_set *wfds) +void +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); + } +} +void +clients_post_select (Clients * cs, Context * ctx, fd_set * rfds, + fd_set * wfds) +{ + 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 (deaded) + clients_reap (cs); } -Client * clients_new_client(Clients *c,Socket *s,Context *ctx) +void +clients_output (Clients * cs, void *_buf, int len) { +uint8_t *buf=(uint8_t *) _buf; +Client *c; + +#define DEBUG_MSG_LEN 128 + + char mbuf[sizeof (IPC_Msg_hdr) + DEBUG_MSG_LEN]; + IPC_Msg *m; +int i; + +if (!len) return; + + m = (IPC_Msg *) mbuf; + m->debug.type = IPC_MSG_TYPE_DEBUG; + i=sprintf(m->debug.msg,"buf[0]=%d len=%d",buf[0],len); + m->debug.size = sizeof (IPC_Msg_hdr) + i + 1; + + + + for (c = cs->head; c; c = c->next) + { + if (!c->dead) + if (ipc_msg_send(c->s,m)) + c->dead++; + } -ipc_msg_send_debug(s,"fishsoup"); -socket_free(s); -return NULL; } -void clients_shutdown(Clients *c) +void +clients_shutdown (Clients * cs) { + Client *c; + for (c = cs->head; c; c = c->next) + { + c->dead++; + } + clients_reap (cs); } diff --git a/apps/clients.h b/apps/clients.h index 78ecdc3..da5fd01 100644 --- a/apps/clients.h +++ b/apps/clients.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.2 2008/02/14 00:57:58 james + * *** empty log message *** + * * Revision 1.1 2008/02/13 18:05:06 james * *** empty log message *** * @@ -22,7 +25,6 @@ typedef struct Client_struct { struct Client_struct *next; - Socket *s; int dead; } Client; diff --git a/apps/sympathy.c b/apps/sympathy.c index 8bed929..a9140f8 100644 --- a/apps/sympathy.c +++ b/apps/sympathy.c @@ -10,13 +10,19 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.2 2008/02/14 00:57:58 james + * *** empty log message *** + * * Revision 1.1 2008/02/05 14:25:49 james * *** empty log message *** * */ -#include "sympathy.h" +#include +#include "client.h" int main(int argc,char *argv[]) { + +client(); } diff --git a/apps/sympathyd.c b/apps/sympathyd.c index 2e45ed1..6480713 100644 --- a/apps/sympathyd.c +++ b/apps/sympathyd.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.6 2008/02/14 00:57:58 james + * *** empty log message *** + * * Revision 1.5 2008/02/13 18:05:06 james * *** empty log message *** * @@ -32,6 +35,27 @@ static char rcsid[] = "$Id$"; #include "client.h" #include "clients.h" + +static void send_history(History *h,Client *c) +{ +int rptr=h->wptr; + +HISTORY_INC(h,rptr); + +HISTORY_INC(h,rptr); +while (rptr!=h->wptr) +{ +History_ent *l=&h->lines[rptr]; +if (l->valid) { + +if (ipc_msg_send_history(c->s,l)) + c->dead++; + +} +HISTORY_INC(h,rptr); +} +} + int main (int argc,char *argv[]) { fd_set rfds, wfds; @@ -64,21 +88,25 @@ int main (int argc,char *argv[]) FD_ZERO (&wfds); tty_pre_select (c.t, &rfds,&wfds); - tty_pre_select (a.terminal, &rfds,&wfds); + + FD_SET(s->fd,&rfds); socket_pre_select (s, &rfds, &wfds); clients_pre_select (clients,&rfds,&wfds); - select (FD_SETSIZE, &rfds, NULL, NULL, &tv); - - cs = socket_post_select (s, &rfds, &wfds); + select (FD_SETSIZE, &rfds, &wfds, NULL, &tv); - if (cs) + if (FD_ISSET (s->fd, &rfds) && ((cs=socket_accept (s)))) { { + Client *cl; /*New client connexion */ - clients_new_client (clients, cs, &c); + cl=clients_new_client (clients, cs, &c); + + send_history(c.h,cl); + } + } clients_post_select (clients, &c, &rfds, &wfds); @@ -102,6 +130,8 @@ int main (int argc,char *argv[]) ansi_dispatch (&a, &c); ansi_update (&a, &c); + + } clients_shutdown (clients); -- cgit v1.2.3