00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <streambuf>
00023 #include <ostream>
00024 #include <cstring>
00025 #include <algorithm>
00026 #include <ios>
00027 #include <istream>
00028
00029 #include <fastcgi++/protocol.hpp>
00030
00032 namespace Fastcgipp
00033 {
00035
00042 template <class charT, class traits>
00043 class Fcgistream: public std::basic_ostream<charT, traits>
00044 {
00045 public:
00046 Fcgistream(): std::basic_ostream<charT, traits>(&buffer) { }
00048 void set(Protocol::FullId id_, Transceiver& transceiver_, Protocol::RecordType type_) { buffer.set(id_, transceiver_, type_); }
00049
00051
00059 void dump(char* data, size_t size) { buffer.dump(data, size); }
00061
00068 void dump(std::basic_istream<char>& stream);
00069 private:
00071
00078 class Fcgibuf: public std::basic_streambuf<charT, traits>
00079 {
00080 public:
00081 Fcgibuf(): dumpSize(0), dumpPtr(0) { setp(buffer, buffer+buffSize); }
00083
00091 void set(Protocol::FullId id_, Transceiver& transceiver_, Protocol::RecordType type_)
00092 {
00093 id=id_;
00094 transceiver=&transceiver_;
00095 type=type_;
00096 }
00097
00098 virtual ~Fcgibuf() { try{ sync(); } catch(...){ } }
00100
00108 void dump(char* data, size_t size) { dumpPtr=data; dumpSize=size; sync(); }
00109
00110 private:
00111 typedef typename std::basic_streambuf<charT, traits>::int_type int_type;
00112 typedef typename std::basic_streambuf<charT, traits>::traits_type traits_type;
00113 typedef typename std::basic_streambuf<charT, traits>::char_type char_type;
00114
00115 int_type overflow(int_type c = traits_type::eof());
00116
00117 int sync() { return emptyBuffer(); }
00118
00119 std::streamsize xsputn(const char_type *s, std::streamsize n);
00120
00122 char* dumpPtr;
00124 size_t dumpSize;
00125
00127 int emptyBuffer();
00129 Transceiver* transceiver;
00131 static const int buffSize = 8192;
00133 char_type buffer[buffSize];
00135 Protocol::FullId id;
00136
00138 Protocol::RecordType type;
00139 };
00141 Fcgibuf buffer;
00142 };
00143 }