1 // fcgio.h - defines classes fcgio_buf, fcgio_ostream, fcgio_istream
2 // and replaces cin, cout and cerr with FastCGI versions
3 // you must include this file in any source file which
4 // uses cin, cout or cerr. It must also appear at the end
7 // $Id: fcgio.h,v 1.1 1999/08/15 03:37:59 roberts Exp $
9 // This work is based on routines written by George Feinberg. They
10 // have been mostly re-written and extensively changed by
13 // Copyright (c) 1999 by Apollo Software. All rights reserved.
15 // You are free to use this software without charge or royalty
16 // as long as this notice is not removed or altered, and recognition
17 // is given to the author(s)
27 // FastCGI streambuf replacement. Implements low level io to the
28 // FastCGI c functions so our higher level iostreams will talk
29 // in the fcgi protocol
30 class fcgio_buf : public streambuf {
33 fcgio_buf( FCGX_Stream *str) { fcgi_str = str; }
37 // tells the stream to go flush itself
39 // handles allocation of buffers by failing since buffer support isn't used
40 virtual int doallocate() { return 0; }
42 virtual int xsgetn(char *s, int n);
43 virtual int xsputn(const char* s, int n);
44 virtual int overflow(int);
45 virtual int underflow();
46 virtual streambuf* setbuf(char* s, int n);
49 FCGX_Stream * fcgi_str;
53 // Here's the ostream class definition. All it has to do is
54 // call ios::init() passing an instance of fcgio_buf
55 class fcgio_ostream : public ostream {
57 fcgio_ostream(FCGX_Stream *str);
58 ~fcgio_ostream() { buf.sync(); }
65 // Here's the istream class definition. All it has to do is
66 // call ios::init() passing an instance of fcgio_buf
67 class fcgio_istream : public istream {
69 fcgio_istream(FCGX_Stream *str);
73 // FastCGI stuff used for the FCGX_ functions
75 // buffer for getting data
76 const int buffersize=100;
77 char buffer[buffersize];
81 // replace cin and cout with our own versions
82 #ifndef USE_CIN_COUT_CERR
84 #define cout (*FCGIX_cout)
85 extern fcgio_ostream *FCGIX_cout;
88 #define cerr (*FCGIX_cerr)
89 extern fcgio_ostream *FCGIX_cerr;
92 #define cin (*FCGIX_cin)
93 extern fcgio_istream *FCGIX_cin;