* context_loop.c, webserver.c, webserver.h: SO_LINGER and locking fix
authorNathan Bryant <loanshark@uncensored.citadel.org>
Wed, 9 Dec 1998 19:35:28 +0000 (19:35 +0000)
committerNathan Bryant <loanshark@uncensored.citadel.org>
Wed, 9 Dec 1998 19:35:28 +0000 (19:35 +0000)
webcit/ChangeLog
webcit/context_loop.c
webcit/webserver.c
webcit/webserver.h

index 1778f3529acde48750ba15ff4f08b8083e4d319a..2e8e7c7c149bf91bc4d3f5567c63bf9a05069c88 100644 (file)
@@ -1,3 +1,6 @@
+1998-12-09 Nathan Bryant <bryant@cs.usm.maine.edu>
+       * context_loop.c, webserver.c, webserver.h: SO_LINGER and locking fix
+
 Wed Dec  9 11:13:48 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Smoothed out some of the login/logout code.  Failed authentication
          now works the way it should.  New user login not yet supported.
index 48b288f376f8040c05eb47ad9cbdce3f416e145f..357bd6b0250b9b76be8cf50b68c0d3c32abab3a0 100644 (file)
@@ -220,10 +220,19 @@ void *context_loop(int sock) {
                write(TheSession->inpipe[1], "\n", 1);
                }
        printf("   Writing %d bytes of content\n", ContentLength);
-       while (ContentLength--) {
-               read(sock, buf, 1);
-               write(TheSession->inpipe[1], buf, 1);
-               }
+       if (ContentLength > 0) {
+               while (ContentLength > 0) {
+                       a = ContentLength;
+                       if (a > sizeof buf) a = sizeof buf;
+                       if (!client_read(sock, buf, a)) goto end;
+                       if (write(TheSession->inpipe[1], buf, a) != a) goto end;
+                       ContentLength -= a;
+                       }
+
+               /* Discard the CRLF following the POST data. Yes, this is
+                * necessary. No, you don't want to know why. */
+               if (!client_read(sock, buf, 2)) goto end;
+               }       
 
        /*
         * ...and get the response.
@@ -247,24 +256,6 @@ void *context_loop(int sock) {
                write(sock, buf, 1);
                }
 
-       /*
-        * Now our HTTP connection is done.  It would be relatively easy
-        * to support HTTP/1.1 "persistent" connections by looping back to
-        * the top of this function.  For now, we'll just close.
-        */
-
-       /* FIX ... This is a weird problem, exhibited on Linux 2.1.130...
-        * the socket doesn't linger properly before closing, so we implement
-        * a ten-second delay before closing the socket.
-       printf("   Lingering...\n");
-       sleep(10);
-        */
-
-       printf("   Closing socket\n");
-       close(sock);
-
-       unlock_session(TheSession);
-
        /*
         * If the last response included a "close session" directive,
         * remove the context now.
@@ -273,8 +264,6 @@ void *context_loop(int sock) {
                printf("Removing session.\n");
                pthread_mutex_lock(&MasterCritter);
 
-               lock_session(TheSession);
-
                if (SessionList==TheSession) {
                        SessionList = SessionList->next;
                        }
@@ -293,8 +282,20 @@ void *context_loop(int sock) {
        
                pthread_mutex_unlock(&MasterCritter);
                }
+       else {
+       end:
+               unlock_session(TheSession);
+               }
+
+        /*
+         * Now our HTTP connection is done.  It would be relatively easy
+         * to support HTTP/1.1 "persistent" connections by looping back to
+         * the top of this function.  For now, we'll just close.
+         */
 
        free(req);
+        printf("   Closing socket\n");
+       close(sock);
 
        /*
         * The thread handling this HTTP connection is now finished.
index 0a65572ef0f6b0a4e5683ebd4493fa0e84ef76f2..aea5eff0a5807683b8e83a270bba88b0582c2e8b 100644 (file)
@@ -247,7 +247,7 @@ int main(int argc, char **argv)
         pthread_attr_t attr;           /* Thread attributes */
        int a, i;                       /* General-purpose variables */
        int port = PORT_NUM;            /* Port to listen on */
-       struct linger WebLinger = { 1, 9000 };
+       /*struct linger WebLinger = { 1, 9000 };*/
 
        /* Parse command line */
        while ((a = getopt(argc, argv, "hp:")) != EOF)
@@ -299,8 +299,8 @@ int main(int argc, char **argv)
                        i = 1;
                        setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR,
                                &i, sizeof(i));
-                       setsockopt(ssock, SOL_SOCKET, SO_LINGER,
-                               &WebLinger, sizeof(struct linger));
+/*                     setsockopt(ssock, SOL_SOCKET, SO_LINGER,
+                               &WebLinger, sizeof(struct linger));*/
 
                        /* set attributes for the new thread */
                        pthread_attr_init(&attr);
index 611ac085028f0de84156982610d9e849498c43a3..9add4b88800e63b6f3932d178a59946299e694db 100644 (file)
@@ -1,2 +1,3 @@
 /* $Id$ */
 int client_gets(int sock, char *buf);
+int client_read(int sock, char *buf, int bytes);