[FASTCGI] Fwd: Hello and a Threading/External Server/Win32 question
Jay Sprenkle
jsprenkle at gmail.com
Thu Apr 16 17:30:15 EDT 2009
---------- Forwarded message ----------
From: Jay Sprenkle <jsprenkle at gmail.com>
Date: Thu, Apr 16, 2009 at 4:28 PM
Subject: Re: [FASTCGI] Hello and a Threading/External Server/Win32 question
To: Shane Calimlim <shanecalimlim at gmail.com>
I looked at this too and found the answer in cygwin. They duplicate a lot of
the functionality of unix and have already been down this path. Here's the
clue I found:
http://www.mail-archive.com/cygwin@cygwin.com/msg62458.html
I may be wrong but the short answer seems to be you can't pass open file
handles that are tcp connections between processes because windows doesn't
treat everything (tcp connections) as a file. I've not seen any way to get
fastcgi to work on windows as the official specs specify (since you must
pass more than a file handle between processes).
If you get it to work I'd love to see how.
If you use a named pipe on the other hand things get easier, and named pipes
are supposed to be faster than tcp connections too.
On Thu, Apr 16, 2009 at 3:59 PM, Shane Calimlim <shanecalimlim at gmail.com>wrote:
> Hi, first let me say that I'm new to the list, but I've been using (and
> loving) FastCGI for years -- great work everyone involved.
>
> I'm working on a FastCGI external server (using a port) with multiple
> threads. The problem I'm having is that even with multiple threads, only
> one request is being handled at a time. Multiple threads are handling them,
> but FCGX_Accept_r() is locking until the previous request's FCGX_Finish_r()
> is called.
>
> I am also using the Qt framework; in the code snippets below qDebug() is
> just a debugging printf().
>
> Here is the code I'm using:
>
> In main():
>
> if( FCGX_Init() != 0 )
> {
> qDebug( "FCGX_Init() error." );
> ::exit( 1 );
> }
> g_listenSocket = FCGX_OpenSocket( ":9000", 100 );
> if( g_listenSocket < 0 )
> {
> qDebug( "FCGX_OpenSocket() error." );
> ::exit( 1 );
> }
>
> //spawn threads and wait until they all terminate
>
> In each thread:
>
> FCGX_Request request;
> if( FCGX_InitRequest( &request, g_listenSocket, 0 ) != 0 )
> {
> qDebug( "FCGX_InitRequest() error." );
> ::exit( 1 );
> }
>
> int status;
> for(;;)
> {
> status = FCGX_Accept_r( &request );
> if( status != 0 )
> {
> qDebug( "FCGX_Accept_r() error." );
> ::exit( 1 );
> }
>
> FCGX_FPrintF( request.out, "Content-Type: text/plain\r\n\r\n" );
> FCGX_FPrintF( request.out, "Hello World!\n" );
> for( int i = 1; i <= 10; ++i )
> {
> msleep( 1000 ); // this is a Qt function -- a 1 second sleep
> FCGX_FPrintF( request.out, "%d\n", i );
> FCGX_FFlush( request.out );
> }
> FCGX_Finish_r( &request );
> }
>
> I've tried various combinations with Init/OpenSocket being in each thread,
> but have had no luck with those. I've also tried WSADuplicateSocket on
> g_listenSocket, but Windows complains that it is not a socket.
>
> Is this possible at all? Is it possible on Windows? The target platform
> is Linux, but I develop on Windows, so having it work identically on my dev
> machines would be very useful.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.pins.net/mailman/private.cgi/fastcgi-developers/attachments/20090416/3892d6d6/attachment.html>
More information about the FastCGI-developers
mailing list