Re: cout instead of FCGX_FPrintF (c++)

Michael Hartley <michael.hartley-jEoFCcbHCOQze0waTqBjZBy+ShKaMYb+@public.gmane.org>
Newsgroups gmane.comp.web.fastcgi.devel
Message-ID <[email protected]>
Waldemar Biernacki <wb@...> writes:

> 
> Tim Wood encourage me (thank you Tim!) to present my solution of the task.
> Here it is. 
> I please (all of you) to comment it as I realize the solution has many holes:
> 
> Waldemar Biernacki
> 
> =================================================
> #include <stdlib.h>
> #include <iostream>
> #include <string>
> 
> #include "fcgi_config.h"
> #include "fcgiapp.h"
> 
> using namespace std;
> 
> extern char **environ;
> 
> FCGX_Stream *in, *out, *err;
> 
> FCGX_Stream & operator<<( FCGX_Stream &o, const char * s ) {
> 	FCGX_FPrintF ( out, s );
> 	return o;
> }
> FCGX_Stream & operator<<( FCGX_Stream &o, string s ) {
> 	FCGX_FPrintF ( out, s.c_str() );
> 	return o;
> }
> FCGX_Stream & operator<<( FCGX_Stream &o, int s ) {
> 	FCGX_FPrintF ( out, "%d", s );
> 	return o;
> }
> 
> int main () {
> 	FCGX_ParamArray envp;
> 
> 	int count = 0;
> 	while ( FCGX_Accept ( &in, &out, &err, &envp ) >= 0 ) {
> 		*out << "Content-type: text/html\r\n\r\n"
> 			<< "<br> Request: "<< ++count <<" <br>";
> 		string some_string = "Now we are testing strings... \n";
> 		*out << "<br> " << some_string << "\n"
> 			<< "<br>... Finish!";
> 	}
> 	return 0;
> }
> 
> 
> 
> ___________________________________
> fastcgi-developers mailing list
> http://fastcgi.com/fastcgi-developers/
> 

Hi,

I was quite interested in your implementation at first, then I noticed a number 
of opportunities for improvement which I've detailed below.

The function call to FCGX_FPrintF is very expensive and would be better replaced 
by a call to FCGX_PutS.  If you work through fcgiapp.c you'll discover the 
FCGX_FPrintF function is a clever piece of code that performs a lot of work, on 
the other hand FCGX_PutS is very simple and virtually routes your string 
directly to the output network stream.

My second observation was that operators only work because they write to a 
globally defined FCGX_steam which is of course no use whatsoever if any FCGI 
application wants to maintain more than a single connection at any one time.

I would be interested to see you fixing these issues.


Kind regards,
Michael Hartley, http://www.openfieldsolutions.co.uk

___________________________________
fastcgi-developers mailing list
http://fastcgi.com/fastcgi-developers/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.