www-apache-bugdb mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "William A. Rowe, Jr." <wr...@lnd.com>
Subject RE: os-windows/5671: CGI print to stdout while reading POST from stdin deadlocks Win32 Pipes
Date Mon, 31 Jan 2000 15:30:01 GMT
The following reply was made to PR os-windows/5671; it has been noted by GNATS.

From: "William A. Rowe, Jr." <wrowe@lnd.com>
To: <submit@bugz.apache.org>, <apache-bugdb@apache.org>
Cc:  
Subject: RE: os-windows/5671: CGI print to stdout while reading POST from stdin deadlocks
Win32 Pipes
Date: Mon, 31 Jan 2000 09:19:35 -0600

 My humble appologies, here is the corrected example write-while-reading
 script:
 
 #include <memory.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 
 /* For _setmode binary MS-DOS semantics: */
 #include <fcntl.h>
 #include <io.h>
 
 const char hex[16] = "0123456789abcdef";
 
 
 int main(int argc, char **argv, char **argenv)
 {
     char *content_type = NULL;
     unsigned long content_length = 0;
 
     unsigned char strbuf[16], outbuf[80];
     unsigned long off, offset = 0;
     int i, len, acnt;
     char **aptr, *ignptr;
 
     /* For _setmode binary MS-DOS semantics: */
     _setmode(_fileno(stdin), _O_BINARY);
 
     aptr = argenv;
     while (*aptr)
     {
         if (strncmp("CONTENT_TYPE=", *aptr, 13) == 0)
             content_type = *aptr + 13;
         else if (strncmp("CONTENT_LENGTH=", *aptr, 15) == 0)
             content_length = strtoul(*aptr + 15, &ignptr, 10);
         ++aptr;
     }
 
     puts("Content-type: text/plain\n");
 
     fflush(stdout);
 
     puts("Command Line Arguments:\n");
     acnt = argc; aptr = argv;
 	while (acnt-- && *aptr)
         puts(*(aptr++));
 
     fflush(stdout);
 
     puts("\nEnvironmental Values:\n");
     aptr = argenv;
 	while (*aptr)
         puts(*(aptr++));
 
     fflush(stdout);
 
     puts("\nInput Stream (POST):\n");
     while (len = fread(strbuf, 1, (offset + sizeof(strbuf) < content_length)
                                 ? sizeof(strbuf) : (content_length -
 offset), stdin))
     {
         memset(outbuf, ' ', sizeof(outbuf));
         outbuf[76] = '\0';
         for (i = 8, off = offset; i--; off >>= 4)
             outbuf[i] = hex[off & 0x0f];
         for (i = 0; i < len; ++i)
             outbuf[i * 3 + 10] = hex[strbuf[i] >> 4],
             outbuf[i * 3 + 11] = hex[strbuf[i] & 0x0f],
             outbuf[i + 59] = (strbuf[i] < 32 || strbuf[i] > 126) ? '.' :
 strbuf[i];
         puts(outbuf);
         offset += len;
         if (!(offset | 0x3f))
             fflush(stdout);
         if (ferror(stdin) || feof(stdin))
             break;
     }
 
     printf("\nTotal Stream Length: %ld\n", offset);
     fflush(stdout);
 
     return 0;
 }
 

Mime
View raw message