gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r8338 - libmicrohttpd/src/daemon


From: gnunet
Subject: [GNUnet-SVN] r8338 - libmicrohttpd/src/daemon
Date: Tue, 17 Mar 2009 15:04:24 -0600

Author: grothoff
Date: 2009-03-17 15:04:24 -0600 (Tue, 17 Mar 2009)
New Revision: 8338

Modified:
   libmicrohttpd/src/daemon/daemon.c
Log:
thread pool bugfix from Richard Alimi

Modified: libmicrohttpd/src/daemon/daemon.c
===================================================================
--- libmicrohttpd/src/daemon/daemon.c   2009-03-17 07:34:32 UTC (rev 8337)
+++ libmicrohttpd/src/daemon/daemon.c   2009-03-17 21:04:24 UTC (rev 8338)
@@ -575,7 +575,9 @@
   if ((s < 0) || (addrlen <= 0))
     {
 #if HAVE_MESSAGES
-      MHD_DLOG (daemon, "Error accepting connection: %s\n", STRERROR (errno));
+      /* This could be a common occurance with multiple worker threads */
+      if ((EAGAIN != errno) && (EWOULDBLOCK != errno))
+        MHD_DLOG (daemon, "Error accepting connection: %s\n", STRERROR 
(errno));
 #endif
       if (s != -1)
         {
@@ -1267,6 +1269,8 @@
     }
   else if (retVal->worker_pool_size > 0)
     {
+      int sk_flags;
+
       /* Coarse-grained count of connections per thread (note error
        * due to integer division). Also keep track of how many
        * connections are leftover after an equal split. */
@@ -1275,7 +1279,17 @@
       unsigned int leftover_conns = retVal->max_connections
                                     % retVal->worker_pool_size;
 
-      i = 0; /* we need this in case malloc fails */
+      i = 0; /* we need this in case fcntl or malloc fails */
+
+      /* Accept must be non-blocking. Multiple children may wake up
+       * to handle a new connection, but only one will win the race.
+       * The others must immediately return. */
+      sk_flags = fcntl (socket_fd, F_GETFL);
+      if (sk_flags < 0)
+        goto thread_failed;
+      if (fcntl (socket_fd, F_SETFL, sk_flags | O_NONBLOCK) < 0)
+        goto thread_failed;
+
       /* Allocate memory for pooled objects */
       retVal->worker_pool = malloc (sizeof (struct MHD_Daemon)
                                     * retVal->worker_pool_size);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]