simplified socket/connection management, only one sockets list
authorChristian Thaeter <ct@pipapo.org>
Mon, 8 Oct 2007 14:24:41 +0000 (16:24 +0200)
committerChristian Thaeter <ct@pipapo.org>
Mon, 8 Oct 2007 14:24:41 +0000 (16:24 +0200)
rxpd.c
rxpd.h

diff --git a/rxpd.c b/rxpd.c
index 260d681..27cf0fb 100644 (file)
--- a/rxpd.c
+++ b/rxpd.c
@@ -34,10 +34,7 @@ rxpd_init (char* rulesdir)
 
   psplay_init_root (&global_base.files, rxpd_file_cmp, rxpd_file_delete);
 
-  llist_init (&global_base.sockets_pending);
-  llist_init (&global_base.sockets_active);
-  llist_init (&global_base.connections_pending);
-  llist_init (&global_base.connections_active);
+  llist_init (&global_base.sockets);
 
   return &global_base;
 }
@@ -49,26 +46,11 @@ rxpd_destroy (void)
     {
       free (global_base.rulesdir);
       psplay_destroy_root (&global_base.files);
-      LLIST_WHILE_HEAD (&global_base.sockets_pending, n)
+      LLIST_WHILE_HEAD (&global_base.sockets, n)
         {
           struct rxpd_socket* socket = (struct rxpd_socket*)n;
           rxpd_socket_delete (socket);
         }
-      LLIST_WHILE_HEAD (&global_base.sockets_active, n)
-        {
-          struct rxpd_socket* socket = (struct rxpd_socket*)n;
-          rxpd_socket_delete (socket);
-        }
-      LLIST_WHILE_HEAD (&global_base.connections_pending, n)
-        {
-          struct rxpd_connection* connection = (struct rxpd_connection*)n;
-          rxpd_connection_delete (connection);
-        }
-      LLIST_WHILE_HEAD (&global_base.connections_active, n)
-        {
-          struct rxpd_connection* connection = (struct rxpd_connection*)n;
-          rxpd_connection_delete (connection);
-        }
     }
 }
 
@@ -270,7 +252,7 @@ rxpd_socket_new_tcp4 (struct rxpd_base* base, const char* addr, unsigned short p
     abort ();
 
   event_set (&self->ev, self->fd, EV_READ, rxpd_socket_accept, self);
-  llist_insert_tail (&base->sockets_pending, &self->node);
+  llist_insert_tail (&base->sockets, &self->node);
   return self;
 }
 
@@ -292,7 +274,6 @@ rxpd_socket_schedule (struct rxpd_socket* self)
 {
   if (self)
     {
-      llist_insert_head (&self->base->sockets_active, &self->node);
       event_add (&self->ev, NULL);
     }
   return self;
@@ -304,7 +285,6 @@ rxpd_socket_suspend (struct rxpd_socket* self)
   if (self)
     {
       event_del (&self->ev);
-      llist_insert_tail (&self->base->sockets_pending, &self->node);
     }
   return self;
 }
@@ -451,9 +431,6 @@ rxpd_connection_new (struct rxpd_base* base, int fd)
   rxpd_buffer_init (&self->out, self);
   
   event_set (&self->ev, self->fd, EV_READ, rxpd_connection_parse_cmd, self);
-
-  llist_insert_tail (&base->connections_pending, &self->node);
-
   return self;
 }
 
@@ -474,23 +451,11 @@ rxpd_connection_schedule (struct rxpd_connection* self)
 {
   if (self)
     {
-      llist_insert_tail (&self->base->connections_active, &self->node);
       event_add (&self->ev, NULL);
     }
   return self;
 }
 
-struct rxpd_connection*
-rxpd_connection_suspend (struct rxpd_connection* self)
-{
-  if (self)
-    {
-      event_del (&self->ev);
-      llist_insert_tail (&self->base->connections_pending, &self->node);
-    }
-  return self;
-}
-
 void
 rxpd_connection_parse_cmd (int fd, short event, void* ptr)
 {
@@ -771,17 +736,11 @@ rxpd_connection_cmd_SHUTDOWN (int fd, short event, void* ptr)
 {
   struct rxpd_connection* self = (struct rxpd_connection*) ptr;
   // destroy all sockets
-  LLIST_WHILE_HEAD (&self->base->sockets_pending, n)
-    {
-      struct rxpd_socket* socket = (struct rxpd_socket*)n;
-      rxpd_socket_delete (socket);
-    }
-  LLIST_WHILE_HEAD (&self->base->sockets_active, n)
+  LLIST_WHILE_HEAD (&self->base->sockets, n)
     {
       struct rxpd_socket* socket = (struct rxpd_socket*)n;
       rxpd_socket_delete (socket);
     }
-
   rxpd_buffer_printf (&self->out, "#OK:\n");
   close (fd);
 }
diff --git a/rxpd.h b/rxpd.h
index 5fe0a1a..07beb28 100644 (file)
--- a/rxpd.h
+++ b/rxpd.h
@@ -72,13 +72,9 @@ struct rxpd_base
   char* rulesdir;
   psplayroot files;
 
-  llist sockets_pending;
-  llist sockets_active;
-  llist connections_pending;
-  llist connections_active;
+  llist sockets;
 };
 
-
 struct rxpd_base*
 rxpd_init (char* rulesdir);
 
@@ -86,7 +82,6 @@ void
 rxpd_destroy (void);
 
 
-
 //
 struct rxpd_rule
 {
@@ -214,10 +209,6 @@ struct rxpd_connection*
 rxpd_connection_schedule (struct rxpd_connection* self);
 
 
-struct rxpd_connection*
-rxpd_connection_suspend (struct rxpd_connection* self);
-
-
 int
 rxpd_connection_readline (struct rxpd_connection* self);