[FASTCGI] Hello and a Threading/External Server/Win32 question

Shane Calimlim shanecalimlim at gmail.com
Thu Apr 16 17:00:32 EDT 2009


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/a847263f/attachment.html>


More information about the FastCGI-developers mailing list