]> code.citadel.org Git - citadel.git/blobdiff - citadel/sysdep.c
* Changed 'number of worker threads' from a sysconfig.h #define to an actual
[citadel.git] / citadel / sysdep.c
index 0a83ced547fceb623360dd899596298e4fc8de3a..333319b9cfcec0c262cee6bd957ccd1027276761 100644 (file)
@@ -69,6 +69,7 @@ int verbosity = DEFAULT_VERBOSITY;            /* Logging level */
 
 struct CitContext masterCC;
 int rescan[2];                                 /* The Rescan Pipe */
+time_t last_purge = 0;                         /* Last dead session purge */
 
 /*
  * lprintf()  ...   Write logging information
@@ -424,7 +425,7 @@ int client_read_to(char *buf, int bytes, int timeout)
        while(len<bytes) {
                FD_ZERO(&rfds);
                FD_SET(CC->client_socket, &rfds);
-               tv.tv_sec = 1;
+               tv.tv_sec = timeout;
                tv.tv_usec = 0;
 
                retval = select( (CC->client_socket)+1, 
@@ -633,10 +634,10 @@ int convert_login(char NameToConvert[]) {
  * of CPU time and keep the context list locked too much.
  */
 void dead_session_purge(void) {
-       static time_t last_purge = 0;
        struct CitContext *ptr, *rem;
-       
+
        if ( (time(NULL) - last_purge) < 5 ) return;    /* Too soon, go away */
+       time(&last_purge);
 
        do {
                rem = NULL;
@@ -651,7 +652,10 @@ void dead_session_purge(void) {
                /* RemoveContext() enters its own S_SESSION_TABLE critical
                 * section, so we have to do it like this.
                 */     
-               if (rem != NULL) RemoveContext(rem);
+               if (rem != NULL) {
+                       lprintf(9, "Purging session %d\n", rem->cs_pid);
+                       RemoveContext(rem);
+               }
 
        } while (rem != NULL);
 }
@@ -809,7 +813,7 @@ int main(int argc, char **argv)
        /*
         * Now create a bunch of worker threads.
         */
-       for (i=0; i<(NUM_WORKER_THREADS-1); ++i) {
+       for (i=0; i<(config.c_worker_threads-1); ++i) {
                pthread_attr_init(&attr);
                        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
                if (pthread_create(&HousekeepingThread, &attr,
@@ -978,6 +982,8 @@ SETUP_FD:   FD_ZERO(&readfds);
                dead_session_purge();
        }
 
+       /* If control reaches this point, the server is shutting down */        
+       master_cleanup();
        pthread_exit(NULL);
 }