move accept to socket_accept itself
authorChristian Thaeter <ct@pipapo.org>
Sun, 21 Oct 2007 23:59:15 +0000 (01:59 +0200)
committerChristian Thaeter <ct@pipapo.org>
Sun, 21 Oct 2007 23:59:15 +0000 (01:59 +0200)
src/rxpd.h
src/rxpd_connection.c
src/rxpd_socket.c

index 1ce0366..ade5d6a 100644 (file)
@@ -251,7 +251,7 @@ struct rxpd_connection
 
 
 struct rxpd_connection*
-rxpd_connection_new (struct rxpd_socket* socket);
+rxpd_connection_new (struct rxpd_socket* socket, int fd);
 
 void
 rxpd_connection_delete (struct rxpd_connection* self);
index 770ef8b..a6c8355 100644 (file)
 #include "rxpd.h"
 
 struct rxpd_connection*
-rxpd_connection_new (struct rxpd_socket* socket)
+rxpd_connection_new (struct rxpd_socket* socket, int fd)
 {
   struct rxpd_connection* self;
   self = rxpd_malloc (sizeof (struct rxpd_connection));
 
-  self->fd = pth_accept (socket->fd, NULL, 0);
-  if (self->fd == -1)
-    abort ();
-
+  self->fd = fd;
   self->socket = socket;
   self->file = NULL;
   self->tmp_str = NULL;
index 507c561..9c7dd0d 100644 (file)
@@ -129,15 +129,14 @@ rxpd_socket_accept (void* ptr)
 
   pth_event_t ev = pth_event (PTH_EVENT_FD|PTH_UNTIL_FD_READABLE, self->fd);
 
-  rxpd_log (NULL, LOG_NOTICE, "pre ACCEPT\n");
-
   // TODO cancel thread to leave the loop?
   while (pth_wait (ev))
     {
-      rxpd_log (NULL, LOG_NOTICE, "ACCEPT\n");
+      int fd = pth_accept (self->fd, NULL, 0);
+      if (fd == -1)
+        rxpd_die ("error accepting connection\n");
 
-      struct rxpd_connection* conn =
-        rxpd_connection_new (self);
+      struct rxpd_connection* conn = rxpd_connection_new (self, fd);
       rxpd_connection_spawn (conn);
     }