fastcgi++
A C++ FastCGI/Web API
fcgistreambuf.hpp
Go to the documentation of this file.
1 
10 /*******************************************************************************
11 * Copyright (C) 2017 Eddie Carle [eddie@isatec.ca] *
12 * *
13 * This file is part of fastcgi++. *
14 * *
15 * fastcgi++ is free software: you can redistribute it and/or modify it under *
16 * the terms of the GNU Lesser General Public License as published by the Free *
17 * Software Foundation, either version 3 of the License, or (at your option) *
18 * any later version. *
19 * *
20 * fastcgi++ is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
23 * more details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with fastcgi++. If not, see <http://www.gnu.org/licenses/>. *
27 *******************************************************************************/
28 
29 #ifndef FASTCGIPP_FCGISTREAMBUF_HPP
30 #define FASTCGIPP_FCGISTREAMBUF_HPP
31 
32 #include "fastcgi++/protocol.hpp"
34 #include "fastcgi++/block.hpp"
35 
36 #include <istream>
37 #include <functional>
38 
40 namespace Fastcgipp
41 {
43 
54  template <class charT, class traits = std::char_traits<charT>>
55  class FcgiStreambuf: public WebStreambuf<charT, traits>
56  {
57  public:
59  {
60  this->setp(m_buffer, m_buffer+s_buffSize);
61  }
62 
64 
72  void configure(
73  const Protocol::RequestId& id,
74  const Protocol::RecordType& type,
75  const std::function<void(const Socket&, Block&&)>
76  send_)
77  {
78  m_id = id;
79  m_type = type;
80  send = send_;
81  }
82 
83  virtual ~FcgiStreambuf()
84  {
85  sync();
86  }
87 
89 
97  void dump(const char* data, size_t size);
98 
100 
109  void dump(std::basic_istream<char>& stream);
110 
111  private:
112  typedef typename std::basic_streambuf<charT, traits>::int_type int_type;
113  typedef typename std::basic_streambuf<charT, traits>::traits_type traits_type;
114  typedef typename std::basic_streambuf<charT, traits>::char_type char_type;
115 
116  int_type overflow(int_type c = traits_type::eof());
117 
118  int sync()
119  {
120  return emptyBuffer()?0:-1;
121  }
122 
124  bool emptyBuffer();
125 
127  static const int s_buffSize = 8192;
128 
131 
134 
137 
139  std::function<void(const Socket&, Block&&)> send;
140  };
141 }
142 
143 #endif
Topmost namespace for the fastcgi++ library.
Stream buffer class for output of HTML/Web stream.
char_type m_buffer[s_buffSize]
The buffer.
std::basic_streambuf< charT, traits >::traits_type traits_type
bool emptyBuffer()
Code converts, packages and transmits all data in the stream buffer.
void configure(const Protocol::RequestId &id, const Protocol::RecordType &type, const std::function< void(const Socket &, Block &&)> send_)
Configure the stream buffer.
Declares everything for relating to the FastCGI protocol itself.
static const int s_buffSize
Size of the internal stream buffer.
Protocol::RequestId m_id
ID associated with the request.
Stream buffer class for output of client data through FastCGI.
Class for representing an OS level I/O socket.
Definition: sockets.hpp:83
A unique identifier for each FastCGI request.
Definition: protocol.hpp:71
std::basic_streambuf< charT, traits >::int_type int_type
Protocol::RecordType m_type
Type of output stream (ERR or OUT)
Declares the WebStreambuf stuff.
RecordType
Defines the types of records within the FastCGI protocol.
Definition: protocol.hpp:141
std::basic_streambuf< charT, traits >::char_type char_type
Declares the Block data structure.
std::function< void(const Socket &, Block &&)> send
Function to actually send the record.
int_type overflow(int_type c=traits_type::eof())
void dump(const char *data, size_t size)
Dumps raw data directly into the FastCGI protocol.
Data structure to hold a block of raw data.
Definition: block.hpp:44