fastcgi++
fcgistream.hpp
Go to the documentation of this file.
1 
2 /***************************************************************************
3 * Copyright (C) 2007 Eddie Carle [eddie@erctech.org] *
4 * *
5 * This file is part of fastcgi++. *
6 * *
7 * fastcgi++ is free software: you can redistribute it and/or modify it *
8 * under the terms of the GNU Lesser General Public License as published *
9 * by the Free Software Foundation, either version 3 of the License, or (at *
10 * your option) any later version. *
11 * *
12 * fastcgi++ is distributed in the hope that it will be useful, but WITHOUT *
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public *
15 * License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public License *
18 * along with fastcgi++. If not, see <http://www.gnu.org/licenses/>. *
19 ****************************************************************************/
20 
21 
22 #ifndef FCGISTREAM_HPP
23 #define FCGISTREAM_HPP
24 
25 #include <iosfwd>
26 #include <boost/iostreams/filtering_stream.hpp>
27 #include <boost/iostreams/categories.hpp>
28 #include <boost/iostreams/concepts.hpp>
29 
30 #include <fastcgi++/protocol.hpp>
32 
34 namespace Fastcgipp
35 {
37 
170 
172  class FcgistreamSink: public boost::iostreams::device<boost::iostreams::output, char>
173  {
174  private:
178  public:
179  std::streamsize write(const char* s, std::streamsize n);
180 
181  void set(Protocol::FullId id, Transceiver &transceiver, Protocol::RecordType type) {m_id=id, m_type=type, m_transceiver=&transceiver;}
182  void dump(const char* data, size_t size) { write(data, size); }
183  void dump(std::basic_istream<char>& stream);
184  };
185 
187 
197  template <typename charT> class Fcgistream: public boost::iostreams::filtering_stream<boost::iostreams::output, charT>
198  {
199  private:
200  struct Encoder: public boost::iostreams::multichar_filter<boost::iostreams::output, charT>
201  {
202  template<typename Sink> std::streamsize write(Sink& dest, const charT* s, std::streamsize n);
205  };
206 
208 
210 
211  public:
212  Fcgistream();
214  void set(Protocol::FullId id, Transceiver& transceiver, Protocol::RecordType type) { m_sink.set(id, transceiver, type); }
215 
217  void flush() { boost::iostreams::filtering_stream<boost::iostreams::output, charT>::strict_sync(); }
218 
220 
228  void dump(const char* data, size_t size) { flush(); m_sink.dump(data, size); }
230 
237  void dump(std::basic_istream<char>& stream) { flush(); m_sink.dump(stream); }
238 
240 
247  };
248 
250 
258  struct encoding
259  {
262  };
263 
264  template<class charT, class Traits> std::basic_ostream<charT, Traits>& operator<<(std::basic_ostream<charT, Traits>& os, const encoding& enc);
265 }
266 
267 #endif