* WebCit thread pool is no longer tied to the number of server sessions. MIN_WORKER_...
[citadel.git] / webcit / sysdep.c
index 00fafbbed19a4d4510584cff1749ab76df4963b2..432966687a7b646fc3e8f5dbcd64dbfbb91b2c0b 100644 (file)
@@ -143,18 +143,11 @@ void worker_entry(void)
        int ssock;
        int i = 0;
        int fail_this_transaction = 0;
-       int ret;
-       struct timeval tv;
-       fd_set readset, tempset;
        ParsedHttpHdrs Hdr;
 
        memset(&Hdr, 0, sizeof(ParsedHttpHdrs));
        Hdr.HR.eReqType = eGET;
        http_new_modules(&Hdr); 
-       tv.tv_sec = 0;
-       tv.tv_usec = 10000;
-       FD_ZERO(&readset);
-       FD_SET(msock, &readset);
 
        do {
                /* Only one thread can accept at a time */
@@ -162,33 +155,22 @@ void worker_entry(void)
                ssock = -1; 
                errno = EAGAIN;
                do {
-                       ret = -1; /* just one at once should select... */
-                       begin_critical_section(S_SELECT);
-
-                       FD_ZERO(&tempset);
-                       if (msock > 0) FD_SET(msock, &tempset);
-                       tv.tv_sec = 0;
-                       tv.tv_usec = 10000;
-                       if (msock > 0)  ret = select(msock+1, &tempset, NULL, NULL,  &tv);
-                       end_critical_section(S_SELECT);
-                       if ((ret < 0) && (errno != EINTR) && (errno != EAGAIN))
-                       {/* EINTR and EAGAIN are thrown but not of interest. */
-                               lprintf(2, "accept() failed:%d %s\n",
-                                       errno, strerror(errno));
-                       }
-                       else if ((ret > 0) && (msock > 0) && FD_ISSET(msock, &tempset))
-                       {/* Successfully selected, and still not shutting down? Accept! */
-                               ssock = accept(msock, NULL, 0);
-                       }
-                       
+                       --num_threads_executing;
+                       ssock = accept(msock, NULL, 0);
+                       ++num_threads_executing;
+                       lprintf(9, "Thread %u woke up, accept() returned %d %s\n",
+                               pthread_self(),
+                               ssock,
+                               ((ssock >= 0) ? "" : strerror(errno))
+                       );
                } while ((msock > 0) && (ssock < 0)  && (time_to_die == 0));
 
                if ((msock == -1)||(time_to_die))
                {/* ok, we're going down. */
                        int shutdown = 0;
 
-                       /* the first to come here will have to do the cleanup.
-                        * make shure its realy just one.
+                       /* The first thread to get here will have to do the cleanup.
+                        * Make sure it's really just one.
                         */
                        begin_critical_section(S_SHUTDOWN);
                        if (msock == -1)
@@ -217,15 +199,16 @@ void worker_entry(void)
                }
                if (ssock < 0 ) continue;
 
+               /* Now do something. */
                if (msock < 0) {
                        if (ssock > 0) close (ssock);
-                       lprintf(2, "inbetween.");
+                       lprintf(2, "in between.");
                        pthread_exit(NULL);
-               } else { /* Got it? do some real work! */
+               } else {
+                       /* Got it? do some real work! */
                        /* Set the SO_REUSEADDR socket option */
                        i = 1;
-                       setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR,
-                                  &i, sizeof(i));
+                       setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
 
                        /* If we are an HTTPS server, go crypto now. */
 #ifdef HAVE_OPENSSL
@@ -263,8 +246,9 @@ void worker_entry(void)
 #endif
 
                                /* ...and close the socket. */
-                               if (Hdr.http_sock > 0)
+                               if (Hdr.http_sock > 0) {
                                        lingering_close(ssock);
+                               }
                                http_detach_modules(&Hdr);
 
                        }
@@ -441,7 +425,10 @@ void spawn_another_worker_thread()
        pthread_attr_t attr;    /* Thread attributes */
        int ret;
 
-       lprintf(3, "Creating a new thread.  Pool size is now %d\n", ++num_threads);
+       lprintf(3, "Creating a new thread.\n");
+
+       ++num_threads_existing;
+       ++num_threads_executing;
 
        /* set attributes for the new thread */
        pthread_attr_init(&attr);