• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

fcgistream.hpp

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003 * Copyright (C) 2007 Eddie Carle [eddie@erctech.org]                       *
00004 *                                                                          *
00005 * This file is part of fastcgi++.                                          *
00006 *                                                                          *
00007 * fastcgi++ is free software: you can redistribute it and/or modify it     *
00008 * under the terms of the GNU Lesser General Public License as  published   *
00009 * by the Free Software Foundation, either version 3 of the License, or (at *
00010 * your option) any later version.                                          *
00011 *                                                                          *
00012 * fastcgi++ is distributed in the hope that it will be useful, but WITHOUT *
00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    *
00014 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public     *
00015 * License for more details.                                                *
00016 *                                                                          *
00017 * You should have received a copy of the GNU Lesser General Public License *
00018 * along with fastcgi++.  If not, see <http://www.gnu.org/licenses/>.       *
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(): dumpPtr(0), dumpSize(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 }

Generated on Fri Jan 21 2011 12:29:32 for fastcgi++ by  doxygen 1.7.2