httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Randy Terbush" <ra...@covalent.net>
Subject RE: [PATCH] Allow non-buffered cgi's on NT.
Date Thu, 22 Jul 1999 02:13:56 GMT
+1

> -----Original Message-----
> From: new-httpd-owner@apache.org
> [mailto:new-httpd-owner@apache.org]On
> Behalf Of Ryan Bloom
> Sent: Sunday, July 11, 1999 8:49 PM
> To: new-httpd@apache.org
> Subject: [PATCH] Allow non-buffered cgi's on NT.
>
>
>
> I am including a patch to allow non-buffered cgi's on NT.
> This does not
> work on 95/98, and never will.  In order to do this, we
> have to use named
> Pipes, and 9X doesn't support this featuer.  I would like
> to see this in
> 1.3.7.
>
> Ryan
>
> ? src/support/Debug
> ? src/support/htdigest.pch
> ? src/support/htdigest.pdb
> ? src/support/vc50.idb
> ? src/support/vc50.pdb
> Index: src/main/alloc.c
> ===================================================================
> RCS file: /home/cvs/apache-1.3/src/main/alloc.c,v
> retrieving revision 1.113
> diff -u -r1.113 alloc.c
> --- alloc.c	1999/05/25 15:32:54	1.113
> +++ alloc.c	1999/07/12 01:55:46
> @@ -68,6 +68,10 @@
>
>  #include <stdarg.h>
>
> +#ifdef WIN32
> +#include <winbase.h>
> +#endif
> +
>  #ifdef OS2
>  #define INCL_DOS
>  #include <os2.h>
> @@ -2380,6 +2384,7 @@
>  				BUFF **pipe_in, BUFF
> **pipe_out, BUFF **pipe_err)
>  {
>  #ifdef WIN32
> +	OSVERSIONINFO oslev;
>      SECURITY_ATTRIBUTES sa = {0};
>      HANDLE hPipeOutputRead  = NULL;
>      HANDLE hPipeOutputWrite = NULL;
> @@ -2393,7 +2398,11 @@
>      HANDLE hCurrentProcess;
>      pid_t pid = 0;
>      child_info info;
> +    char *pipename;
> +    char mytid[6];
>
> +    oslev.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
> +	GetVersionEx(&oslev);
>
>      ap_block_alarms();
>
> @@ -2407,28 +2416,29 @@
>
>
>      /* Create pipes for standard input/output/error redirection. */
> -    if (pipe_in && !CreatePipe(&hPipeInputRead,
> &hPipeInputWrite, &sa, 0))
> -	return 0;
> -
> -    if (pipe_out && !CreatePipe(&hPipeOutputRead,
> &hPipeOutputWrite, &sa, 0)) {
> -	if(pipe_in) {
> -	    CloseHandle(hPipeInputRead);
> -	    CloseHandle(hPipeInputWrite);
> -	}
> -	return 0;
> -    }
> -
> -    if (pipe_err && !CreatePipe(&hPipeErrorRead,
> &hPipeErrorWrite, &sa, 0)) {
> -	if(pipe_in) {
> -	    CloseHandle(hPipeInputRead);
> -	    CloseHandle(hPipeInputWrite);
> -	}
> -	if(pipe_out) {
> -	    CloseHandle(hPipeOutputRead);
> -	    CloseHandle(hPipeOutputWrite);
> -	}
> -	return 0;
> -    }
> +	if (oslev.dwPlatformId != VER_PLATFORM_WIN32_NT) {
> +        /* We are on 95 or 98, must use anonymous pipes */
> +        if (pipe_in && !CreatePipe(&hPipeInputRead,
> &hPipeInputWrite, &sa, 0))
> +	    return 0;
> +
> +        if (pipe_out && !CreatePipe(&hPipeOutputRead,
> &hPipeOutputWrite, &sa, 0)) {
> +	        if(pipe_in) {
> +	            CloseHandle(hPipeInputRead);
> +    	        CloseHandle(hPipeInputWrite);
> +	        }
> +    	    return 0;
> +        }
> +        if (pipe_err && !CreatePipe(&hPipeErrorRead,
> &hPipeErrorWrite, &sa, 0)) {
> +    	    if(pipe_in) {
> +	            CloseHandle(hPipeInputRead);
> +    	        CloseHandle(hPipeInputWrite);
> +	        }
> +	        if(pipe_out) {
> +	            CloseHandle(hPipeOutputRead);
> +	            CloseHandle(hPipeOutputWrite);
> +	        }
> +	        return 0;
> +        }
>      /*
>       * When the pipe handles are created, the security descriptor
>       * indicates that the handle can be inherited.
> However, we do not
> @@ -2440,6 +2450,9 @@
>       * sides of the pipes, and no I/O error will occur.  Microsoft
>       * recommends using DuplicateHandle to turn off the inherit bit
>       * under NT and Win95.
> +     * No need to do this on NT anymore, because we are
> using Named pipes, so we can
> +     * Just define the server side to be non-inheritable,
> and the client side inheritable
> +     * So, we put this section in the 95/98 statements.
>       */
>      hCurrentProcess = GetCurrentProcess();
>      if ((pipe_in && !DuplicateHandle(hCurrentProcess,
> hPipeInputWrite,
> @@ -2480,6 +2493,79 @@
>  	    hPipeErrorRead = hPipeErrorReadDup;
>  	}
>      }
> +
> +    }
> +    else {
> +        /* We are on NT, we can use Named pipes for
> non-blocking I/O. */
> +        pipename = ap_palloc(p, 20);
> +
> +        itoa(GetCurrentThreadId(), mytid, 10);
> +        if (pipe_in) {
> +            pipename = ap_pstrcat(p,
> "\\\\.\\pipe\\INCGIPIPE", mytid, NULL);
> +            hPipeInputWrite = CreateNamedPipe(pipename,
> PIPE_ACCESS_OUTBOUND,
> +
> PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT, 1,
> 8024, 8024, 0, NULL);
> +            if (hPipeInputWrite == INVALID_HANDLE_VALUE) {
> +                return 0;
> +            }
> +            hPipeInputRead = CreateFile(pipename,
> GENERIC_READ, 0, &sa, OPEN_EXISTING,
> +                                        0, NULL);
> +            if (hPipeInputRead == INVALID_HANDLE_VALUE) {
> +                return 0;
> +            }
> +        }
> +
> +        if (pipe_out) {
> +            pipename = ap_pstrcat(p,
> "\\\\.\\pipe\\OUTCGIPIPE", mytid, NULL);
> +            hPipeOutputRead = CreateNamedPipe(pipename,
> PIPE_ACCESS_INBOUND,
> +
> PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT, 1,
> 8024, 8024, 0, NULL);
> +            if (hPipeOutputRead == INVALID_HANDLE_VALUE) {
> +    	        if(pipe_in) {
> +	                CloseHandle(hPipeInputRead);
> +    	            CloseHandle(hPipeInputWrite);
> +	            }
> +    	        return 0;
> +            }
> +            hPipeOutputWrite = CreateFile(pipename,
> GENERIC_WRITE, 0, &sa, OPEN_EXISTING,
> +                                        0, NULL);
> +            if (hPipeInputRead == INVALID_HANDLE_VALUE) {
> +    	        if(pipe_in) {
> +	                CloseHandle(hPipeInputRead);
> +    	                CloseHandle(hPipeInputWrite);
> +	            }
> +    	        return 0;
> +            }
> +        }
> +
> +        if (pipe_err) {
> +            pipename = ap_pstrcat(p,
> "\\\\.\\pipe\\ERRCGIPIPE", mytid, NULL);
> +            hPipeErrorRead = CreateNamedPipe(pipename,
> PIPE_ACCESS_INBOUND,
> +
> PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT, 1,
> 8024, 8024, 0, NULL);
> +            if (hPipeErrorRead == INVALID_HANDLE_VALUE) {
> +                if(pipe_in) {
> +	                CloseHandle(hPipeInputRead);
> +    	            CloseHandle(hPipeInputWrite);
> +	            }
> +	            if(pipe_out) {
> +	                CloseHandle(hPipeOutputRead);
> +    	            CloseHandle(hPipeOutputWrite);
> +	            }
> +                return 0;
> +            }
> +            hPipeErrorWrite = CreateFile(pipename,
> GENERIC_WRITE, 0, &sa, OPEN_EXISTING,
> +                                         0, NULL);
> +            if (hPipeErrorWrite == INVALID_HANDLE_VALUE) {
> +                if(pipe_in) {
> +	                CloseHandle(hPipeInputRead);
> +    	            CloseHandle(hPipeInputWrite);
> +	            }
> +	            if(pipe_out) {
> +	                CloseHandle(hPipeOutputRead);
> +    	            CloseHandle(hPipeOutputWrite);
> +	            }
> +                return 0;
> +            }
> +        }
> +    } /* done creating pipes on NT :) */
>
>      /* The script writes stdout to this pipe handle */
>      info.hPipeOutputWrite = hPipeOutputWrite;
> Index: src/main/buff.c
> ===================================================================
> RCS file: /home/cvs/apache-1.3/src/main/buff.c,v
> retrieving revision 1.87
> diff -u -r1.87 buff.c
> --- buff.c	1999/04/27 20:36:30	1.87
> +++ buff.c	1999/07/12 01:55:50
> @@ -237,8 +237,14 @@
>
>  #ifdef WIN32
>      if (fb->hFH != INVALID_HANDLE_VALUE) {
> -        if (!ReadFile(fb->hFH,buf,nbyte,&rv,NULL))
> +        if (!ReadFile(fb->hFH,buf,nbyte,&rv,NULL)) {
>              rv = -1;
> +            while (rv == -1 && GetLastError() == ERROR_NO_DATA) {
> +                if (!ReadFile(fb->hFH,buf,nbyte,&rv,NULL)) {
> +                    rv = -1;
> +                }
> +            }
> +        }
>      }
>      else
>  #endif
>
> ____________________________________________________________
> ___________
> Ryan Bloom		rbb@raleigh.ibm.com
> 4205 S Miami Blvd
> RTP, NC 27709		It's a beautiful sight to see good dancers
> 			doing simple steps.  It's a painful sight to
> 			see beginners doing complicated patterns.
>


Mime
View raw message