* Fixed the problem of worker threads waking up prematurely.
authorArt Cancro <ajc@citadel.org>
Thu, 28 Oct 1999 03:20:18 +0000 (03:20 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 28 Oct 1999 03:20:18 +0000 (03:20 +0000)
* 'QUIT'-terminated sessions now exit properly.  Still need to fix code for
  sessions which are terminated from another session or by the server.

citadel/ChangeLog
citadel/citserver.c
citadel/sysdep.c

index 0040631e77e6b7dc4247d567be9818ec269e1a9a..03fd32230ad4041241498b8044addae71a8939d4 100644 (file)
@@ -1,10 +1,13 @@
 $Log$
+Revision 1.399  1999/10/28 03:20:17  ajc
+* Fixed the problem of worker threads waking up prematurely.
+* 'QUIT'-terminated sessions now exit properly.  Still need to fix code for
+  sessions which are terminated from another session or by the server.
+
 Revision 1.398  1999/10/27 04:26:58  ajc
 * Initial hack of worker-thread rearchitecture.  Right now it is successfully
   dispatching worker threads to active client sockets (and to the master
-  socket too, of course).  Removing sessions is currently broken.  There is
-  also a problem with worker threads waking up too quickly when a client
-  command is entered (race condition?).   More cleanup to follow.
+  socket too, of course).  Removing sessions is currently broken.
 
 Revision 1.397  1999/10/26 20:20:29  ajc
 * Removed the auto-reconnect stuff... it was locking the client in an active
@@ -1371,4 +1374,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
-
index cd791e3583587ba67191f4aca0f9e7ca6cad04c3..0e5c9e90856aebed5bd2d4ddf7861e8d55cc9a59 100644 (file)
@@ -862,13 +862,10 @@ void begin_session(struct CitContext *con)
 void do_command_loop(void) {
        char cmdbuf[256];
 
-       lprintf(9, "Hi, I'm do_command_loop() and I have client socket %d\n",
-               CC->client_socket);
-
        time(&CC->lastcmd);
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        if (client_gets(cmdbuf) < 1) {
-               lprintf(3, "Socket is broken, I think.\n");
+               lprintf(3, "Client socket is broken.  Ending session.\n");
                cleanup(EXIT_NULL);
        }
        lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, cmdbuf);
@@ -899,6 +896,7 @@ void do_command_loop(void) {
 
        else if (!strncasecmp(cmdbuf,"QUIT",4)) {
                cprintf("%d Goodbye.\n",OK);
+               cleanup(0);
                }
 
        else if (!strncasecmp(cmdbuf,"LOUT",4)) {
index 0f004f172645af4817b4d81d3ea38313f56a6b81..367cc792247466a3f3fc8f61feb0bc8fb94f8dc2 100644 (file)
@@ -868,10 +868,7 @@ void worker_thread(void) {
                 */
 
                begin_critical_section(S_I_WANNA_SELECT);
-               lprintf(9, "Worker thread %2d woke up\n", getpid());
-
-SETUP_FD:
-               FD_ZERO(&readfds);
+SETUP_FD:      FD_ZERO(&readfds);
                FD_SET(msock, &readfds);
                highest = msock;
                FD_SET(rescan[0], &readfds);
@@ -889,10 +886,7 @@ SETUP_FD:
                }
                end_critical_section(S_SESSION_TABLE);
 
-               lprintf(9, "Thread %2d can wake up on %d different fd's\n",
-                       getpid(), numselect);
                retval = select(highest + 1, &readfds, NULL, NULL, NULL);
-               lprintf(9, "select() returned %d\n", retval);
 
                /* Now figure out who made this select() unblock.
                 * First, check for an error or exit condition.
@@ -907,7 +901,6 @@ SETUP_FD:
                 * on the master socket.
                 */
                else if (FD_ISSET(msock, &readfds)) {
-                       lprintf(9, "It's the master socket!\n");
                        alen = sizeof fsin;
                        ssock = accept(msock, (struct sockaddr *)&fsin, &alen);
                        if (ssock < 0) {
@@ -945,7 +938,6 @@ SETUP_FD:
                 * current data.
                 */
                else if (FD_ISSET(rescan[0], &readfds)) {
-                       lprintf(9, "rescanning\n");
                        read(rescan[0], &junk, 1);
                        goto SETUP_FD;
                }
@@ -961,7 +953,7 @@ SETUP_FD:
                            ptr = ptr->next) {
                                if ( (FD_ISSET(ptr->client_socket, &readfds))
                                   && (ptr->state == CON_IDLE) ) {
-                                       bind_me = con;
+                                       bind_me = ptr;
                                }
                        }
                        if (bind_me != NULL) {
@@ -976,8 +968,6 @@ SETUP_FD:
 
                        /* We're bound to a session, now do *one* command */
                        if (bind_me != NULL) {
-                               lprintf(9, "Binding thread to session %d\n",
-                                       bind_me->client_socket);
                                pthread_setspecific(MyConKey, (void *)bind_me);
                                do_command_loop();
                                pthread_setspecific(MyConKey, (void *)NULL);