Using select() with FASTCGI

Paul Mahoney (
Wed, 22 May 1996 19:57:21 +100 (BST)

Date: Wed, 22 May 1996 19:57:21 +100 (BST)
From: Paul Mahoney <>
To: Fastcgi Developers <>
Subject: Using select() with FASTCGI
Message-Id: <>

I need to wait on a couple of streams and process each has some input
arrives. One stream the FCGI_stdin and the ohter is a pipe from a
child process. So I thought I'd use the select() call.

The extract below almost works... when there is data on the FCGI_stdin
I call FCGI_Accept()... but I then what to loop round for any other
input, including more on FCGI_stdin. Once I get some data from the child
I want to write it back to the client end...the correct client!. 

As I write this I realise the FCGI_ routines can't support what I want to
do :-( I know the FCGI protocol can multiplex sessions down the connection
between the FGCI application and the HTTPD server, but is there a library
that will help use this functionality. 

%<-- Extract of the sort of loop I'm looking for ---------------------------

int CMain::Loop (void)
    fd_set	RdSet;
    int		fdFCGI = fileno(FCGI_stdin);
    int		fdMax  = ((m_iPipe < fdFCGI)? fdFCGI : m_iPipe) + 1;

    for (; ;) {
	FD_SET (m_iPipe, &RdSet);
	FD_SET (fdFCGI, &RdSet);

	switch (select (fdMax,&RdSet,(fd_set*)NULL,(fd_set*)NULL, &Timeout)) {
	    case -1:
		if (errno != EINTR)

		if (FD_ISSET (m_iPipe, &RdSet)) {  // Process incoming GCRS
		    ... write html to client

		if (FD_ISSET (fdFCGI, &RdSet)) { // Process incoming FCGI
		    if (FCGI_Accept() >= 0) {
                         ... get form data an tell child to get working it


Can the team point me in the right direction? I can't be the first to 
want to have an FGCI application manage multiple client sessions.



Paul Mahoney, X-Act Solutions Limited
smail: Owlsmead, Meads Road, Little Common, Bexhill-on-Sea, East Sussex TN39 4SY
email: ...
phone: +44 424 846368