pion  5.0.6
reader.hpp
1 // ---------------------------------------------------------------------
2 // pion: a Boost C++ framework for building lightweight HTTP interfaces
3 // ---------------------------------------------------------------------
4 // Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion)
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // See http://www.boost.org/LICENSE_1_0.txt
8 //
9 
10 #ifndef __PION_HTTP_READER_HEADER__
11 #define __PION_HTTP_READER_HEADER__
12 
13 #include <boost/asio.hpp>
14 #include <pion/config.hpp>
15 #include <pion/http/parser.hpp>
16 #include <pion/http/message.hpp>
17 #include <pion/tcp/connection.hpp>
18 #include <pion/tcp/timer.hpp>
19 
20 
21 namespace pion { // begin namespace pion
22 namespace http { // begin namespace http
23 
24 
28 class PION_API reader :
29  public http::parser
30 {
31 public:
32 
33  // default destructor
34  virtual ~reader() {}
35 
37  void receive(void);
38 
40  inline tcp::connection_ptr& get_connection(void) { return m_tcp_conn; }
41 
43  inline void set_timeout(boost::uint32_t seconds) { m_read_timeout = seconds; }
44 
45 
46 protected:
47 
55  reader(const bool is_request, tcp::connection_ptr& tcp_conn)
56  : http::parser(is_request), m_tcp_conn(tcp_conn),
57  m_read_timeout(DEFAULT_READ_TIMEOUT)
58  {}
59 
66  void consume_bytes(const boost::system::error_code& read_error,
67  std::size_t bytes_read);
68 
70  void consume_bytes(void);
71 
73  virtual void read_bytes(void) = 0;
74 
76  virtual void finished_reading(const boost::system::error_code& ec) = 0;
77 
79  virtual http::message& get_message(void) = 0;
80 
81 
82 private:
83 
85  void read_bytes_with_timeout(void);
86 
92  void handle_read_error(const boost::system::error_code& read_error);
93 
94 
96  static const boost::uint32_t DEFAULT_READ_TIMEOUT;
97 
98 
100  tcp::connection_ptr m_tcp_conn;
101 
103  tcp::timer_ptr m_timer_ptr;
104 
106  boost::uint32_t m_read_timeout;
107 };
108 
109 
110 } // end namespace http
111 } // end namespace pion
112 
113 #endif
reader(const bool is_request, tcp::connection_ptr &tcp_conn)
Definition: reader.hpp:55
tcp::connection_ptr & get_connection(void)
returns a shared pointer to the TCP connection
Definition: reader.hpp:40
void set_timeout(boost::uint32_t seconds)
sets the maximum number of seconds for read operations
Definition: reader.hpp:43