Roxen.git / server / modules / scripting / fastcgi.pike

version» Context lines:

Roxen.git/server/modules/scripting/fastcgi.pike:1:   // This is a roxen module. Copyright © 2000 - 2009, Roxen IS.      inherit "cgi.pike": normalcgi;    - constant cvs_version = "$Id: fastcgi.pike,v 2.22 2011/09/12 10:54:42 grubba Exp $"; + constant cvs_version = "$Id$";      #include <roxen.h>   #include <module.h>   #if !defined(__NT__) && !defined(__AmigaOS__)   # define UNIX 1   #else   # define UNIX 0   #endif      // #define FCGI_ALL_DEBUG
Roxen.git/server/modules/scripting/fastcgi.pike:129:    {    if( request_ids[p->requestid] ) {    request_ids[p->requestid]( p );    } else if( default_cb ) {    default_cb( p );    }    }    }    }    - #if constant( thread_create ) +     void read_thread()    {    DTFUNC("FCGIChannel::read_thread");    string s;       while( (s = fd->read( 1024, 1 ) ) && strlen(s) ) {    got_data( s );    }    catch(fd->close());    end_cb();
Roxen.git/server/modules/scripting/fastcgi.pike:202: Inside #if constant( thread_create )
   }       void write( string what )    {    DTFUNC("FCGIChannel::write");    Thread.MutexKey lock = cond_mutex->lock();    wbuffer += what;    cond->signal();    lock = 0;    } - #else -  void write( string what ) -  { -  wbuffer += what; -  write_cb(); -  } +     -  void write_cb( ) -  { -  if( strlen(wbuffer) ) -  { -  IO_DEBUG(sprintf("nonthreaded write_cb with wbuffer: %s\n",wbuffer)); -  written = fd->write( wbuffer ); -  IO_DEBUG(sprintf("nonthreaded write_cb wrote: %d\n",written)); -  if( written < 0 ) -  end_cb(); -  else -  wbuffer = wbuffer[written..]; -  } -  } -  -  void read_cb( object f, string d ) -  { -  IO_DEBUG(sprintf("Non threaded read_cb, string: %s\n object :%O\n",d,f)); -  got_data( d ); -  } -  -  void do_setup_channels() -  { -  IO_DEBUG(sprintf("Non threaded Setting up read/write/close callbacks for FD: %O\n",fd)); -  fd->set_id( 0 ); -  fd->set_read_callback( read_cb ); -  fd->set_write_callback( write_cb ); -  fd->set_close_callback( end_cb ); -  } - #endif -  +     void end_cb()    {    DTFUNC("FCGIChannel::end_cb");       if( fd )    {    if( close_callback ) {    PROCESS_DEBUG(sprintf("FCGIChannel close callback from end_cb(): %O, calling %O",    this_object(),close_callback));    close_callback( this_object() );
Roxen.git/server/modules/scripting/fastcgi.pike:439:    int writer, closed;       protected    {    int reqid;    FCGIChannel fd;    string buffer = "";    function read_callback, close_callback, close_callback_2;    mixed fid;    - #if constant(thread_create) +     // Note: buffer is accessed both from the read_thread,    // and from other threads due to the implementation    // of set_blocking() and set_nonblocking().    Thread.Mutex read_cb_mutex = Thread.Mutex();   #define LOCK() read_cb_mutex->lock()   #define UNLOCK(KEY) destruct(key) - #else - #define LOCK() 0 - #define UNLOCK(KEY) - #endif +     }       string _sprintf( )    {    return sprintf("FCGI.Stream(%s,%d)", name, reqid);    }       void destroy()    {    DTFUNC("Stream::destroy");
Roxen.git/server/modules/scripting/fastcgi.pike:526:       string read( int nbytes, int noblock )    {    DTFUNC("Stream::read");    IO_DEBUG(sprintf("%O::read(%d,%d)",this_object(),nbytes,noblock));       if(!nbytes)    {    if( noblock )    { - #if constant( thread_create ) +     while( !closed && !strlen( buffer ) ) sleep(0.1); - #endif +     mixed key = LOCK();    string b = buffer;    buffer="";    UNLOCK(key);    return b;    } - #if constant( thread_create ) +     while( !closed ) sleep( 0.1 ); - #endif +     mixed key = LOCK();    string b = buffer;    buffer=0;    UNLOCK(key);    return b;    }    if( !closed && !noblock )    { - #if constant( thread_create ) +     while( !closed && (strlen( buffer ) < nbytes) ) /* assume MT */    sleep( 0.1 ); - #else -  if( !closed && (strlen(buffer) < nbytes) ) -  error("Not enough data available, and waiting would block!\n" ); - #endif +     } - #if constant( thread_create ) +     while( !closed && !strlen( buffer ) ) sleep(0.1); - #endif +     mixed key = LOCK();    string b = buffer[..nbytes-1];    buffer = buffer[nbytes..];    UNLOCK(key);    return b;    }       int write( string data )    {    DTFUNC("Stream::write");
Roxen.git/server/modules/scripting/fastcgi.pike:914:    array all_pids = ({});    mapping options = ([]);    array argv;    array(FCGIChannel) channels = ({});    int current_conns;       void do_connect( object fd, mixed|void q )    {    DTFUNC("FCGI::do_connect");    - #if constant(thread_create) +     THREAD_DEBUG(sprintf("FCGI::do_connect with fd: %O, q: %O\n",fd,q));       IO_DEBUG(" Connecting...\n" );    while( !fd->connect( "localhost",(int)(socket->query_address()/" ")[1]) )    {    IO_DEBUG(" Connection failed...\n" );    sleep( 0.1 );    }    q(); - #else -  IO_DEBUG(sprintf("no thread_create: Connecting to %d...\n",(int)(socket->query_address()/" ")[1])); -  fd->connect( "localhost",(int)(socket->query_address()/" ")[1]); - #endif +     THREAD_DEBUG("FCGI::do_connect done");    }       FCGIChannel new_channel( )    {    DTFUNC("FCGI::new_channel");    PROCESS_DEBUG(sprintf("FCGI::new_channel all_process is :%O\n options: %O\n",all_pids,options));       while( current_conns >= (options->MAX_CONNS*sizeof(all_pids)) )    start_new_script();    current_conns++;    Stdio.File fd = Stdio.File();    fd->open_socket();    FCGIChannel ch = FCGIChannel( fd ); - #if constant(thread_create) +     fd->set_blocking();    mixed th;    th = thread_create( do_connect, fd, ch->setup_channels );    THREAD_DEBUG(sprintf("%O::new_channel created thread id %O for do_connect()",    this,th->id_number())); - #else -  fd->set_nonblocking( 0, -  ch->setup_channels, -  do_connect ); -  fd->set_id( fd ); -  do_connect( fd ); - #endif +     channels += ({ ch });    ch->set_close_callback( lambda(object c)    {    DTFUNC("Channel close callback lambda");    PROCESS_DEBUG(sprintf("Close callback for %O called",c));    channels -= ({ c });    current_conns--;    });    return ch;    }