httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@en.muc.de (Ralf S. Engelschall)
Subject FastCGI (mod_fastcgi.c) ported to Apache 1.1b2
Date Mon, 06 May 1996 21:35:53 GMT

After fighting three hours unter Apache 1.1b2 with the FastCGI module from
OpenMarket, which was written for Apache 1.0.x, I was finally successful!

Now it runs fine on one of my FreeBSD 2.1.0 boxes. I still don't gave it a
try under the Solaris box, where my major Apache-servers run, but it should
work there, too.

The problem was the introduction of the buffer code in 1.1, as you still
mentioned. I've rewritten the mod_fastcgi.c to use the bxxxx() functions.   A
context diff is attached at the end of this message. Apply it to the
mod_fastcgi.c from OpenMarket.

I'm not 100% sure if I use the buffer code correctly, but I hope. As
D.E.Knuth said: "Beware of bugs in the above code; I have only proved it
correct, not tried it." ;-)

And, yes, my version of tiny-fcgi increases the counter!!

Here are the relevant part of my Apache configuration:

===============
  :
Alias         /internal/fcgi/ =[PATH_DIR_INTERNAL]=/fcgi/
  :
</Directory>
<Directory =[PATH_DIR_INTERNAL]=/fcgi>
Options FollowSymLinks MultiViews
AllowOverride None
allow from all
</Directory>
  :
#   let files with extension .fcgi threated as FastCGI scripts
AddType  application/x-httpd-fcgi   fcg fcgi
AppClass =[PATH_DIR_INTERNAL]=/fcgi/tiny-fcgi.fcgi     -listen-queue-depth 10 -processes 1
AppClass =[PATH_DIR_INTERNAL]=/fcgi/fastcgi-echo.fcgi  -listen-queue-depth 10 -processes 1
  :
===============
(the =[..]= statements get expanded by a preprocessor. just substitute them
 with direct paths)

Now, when I reference the URL
http://en2.en.sdm.de/internal/fcgi/tiny-fcgi.fcgi then the FastCGI demo page
(holding the counter, mentioned above) is displayed!

Please have a look at my diffs. I will send it to the OpenMarket people to
prevent us from doing it again and again for their next releases.

PS: For those of you who still don't know anything about FastCGI: 
    Have a look at http://www.fastcgi.com/

Greetings,
                                        Ralf S. Engelschall    
                                        rse@en.muc.de
                                        http://www.muc.de/~rse

-------------------------------------------------------
*** mod_fastcgi.c.orig	Mon May  6 22:31:26 1996
--- mod_fastcgi.c	Mon May  6 23:11:15 1996
***************
*** 16,23 ****
--- 16,29 ----
   *
   *  Trung Dung
   *  tdung@openmarket.com
+  *
+  *  Ported from Apache-1.0-based code to Apache-1.1b2 internals by
+  *  Ralf S. Engelschall
+  *  <rse@en.muc.de>
   */
  
+ /* #define APACHEVERSION 10 */
+ #define APACHEVERSION 11
  
  #include <stdio.h>
  #include <unistd.h>
***************
*** 53,64 ****
--- 59,78 ----
  char * translateName(WS_Request *r, char *uri, char *fullpath);
  void add_cgi_vars(WS_Request *r);
  void timeout(int);
+ #if (APACHEVERSION < 11)
  int GetFromStream(FILE *fp, char *buf, int len);
+ #else
+ int GetFromStream(BUFF *bp, char *buf, int len);
+ #endif
  #define WS_TimeOut(x)  timeout(x)
  #define HostInfo(x) x->server
  #define HostName(x) x->server->server_hostname
  #define HostPort(x) x->server->port
+ #ifdef __FreeBSD__
+ jmp_buf jmp_env;
+ #else
  sigjmp_buf jmp_env;
+ #endif
  int initOnce = 1;
  /*------------------------------------------------------------*/
  #define FCGI_MAGIC_TYPE "application/x-httpd-fcgi"
***************
*** 2278,2284 ****
  
      if (nFirst) {
        char szBuf[SERVER_BUFSIZE];
!       nBytes=GetFromStream(reqPtr->connection->request_in, szBuf,SERVER_BUFSIZE);
        if (nBytes > 0) {
  	BufferAddData(infoPtr->reqInbufPtr, szBuf, nBytes);
  	ClientToCgiBuffer(infoPtr);
--- 2292,2302 ----
  
      if (nFirst) {
        char szBuf[SERVER_BUFSIZE];
! #if (APACHEVERSION < 11)
! 	  nBytes=GetFromStream(reqPtr->connection->request_in, szBuf,SERVER_BUFSIZE);
! #else
!       nBytes=GetFromStream(reqPtr->connection->client, szBuf,SERVER_BUFSIZE);
! #endif
        if (nBytes > 0) {
  	BufferAddData(infoPtr->reqInbufPtr, szBuf, nBytes);
  	ClientToCgiBuffer(infoPtr);
***************
*** 3000,3006 ****
--- 3018,3026 ----
  
  static void FastCGIRestart()
  {
+ #if 0
      fprintf(stderr, "Caught sig huh\n");
+ #endif
      while (fastCgiServers) {
          FreeFcgiServerInfo(fastCgiServers);
      }
***************
*** 3318,3328 ****
--- 3338,3358 ----
  
  void PrepareClientSocket(WS_Request *reqPtr, int *csdIn, int *csdOut)
  {
+ #if (APACHEVERSION <11)
    fflush(reqPtr->connection->client);
    *csdIn = fileno (reqPtr->connection->request_in);
    *csdOut = fileno (reqPtr->connection->client);
+ #else
+   bflush(reqPtr->connection->client);
+   *csdOut = reqPtr->connection->client->fd;
+   if (reqPtr->connection->client->fd_in != reqPtr->connection->client->fd)
+       *csdIn = reqPtr->connection->client->fd_in;
+   else
+       *csdIn = reqPtr->connection->client->fd;
+ #endif
  }
  
+ #if (APACHEVERSION < 11)
  int GetFromStream(FILE *fp, char *buf, int len)
  {
    int fp_size;
***************
*** 3335,3340 ****
--- 3365,3384 ----
    }
    return fp_size;
  }
+ #else
+ int GetFromStream(BUFF *bp, char *buf, int len)
+ {
+   int bp_size;
+   bp_size = bp->incnt;
+   if (bp_size > len)
+     bp_size = len;
+   if (bp_size > 0) {
+     bread(bp, buf, bp_size);
+   }
+   return bp_size;
+ }
+ #endif
+ 
  void MakeExtraEnvStr(WS_Request *reqPtr)
  {
    table_set(reqPtr->subprocess_env,"SERVER_HOSTNAME",reqPtr->server->server_hostname);
-------------------------------------------------------

Mime
View raw message