aboutsummaryrefslogtreecommitdiffstats
path: root/apps/clients.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/clients.c')
-rw-r--r--apps/clients.c125
1 files changed, 115 insertions, 10 deletions
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);
}