pion-net  4.0.9
HTTPReader.hpp
1 // ------------------------------------------------------------------
2 // pion-net: a C++ framework for building lightweight HTTP interfaces
3 // ------------------------------------------------------------------
4 // Copyright (C) 2007-2008 Atomic Labs, Inc. (http://www.atomiclabs.com)
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_HTTPREADER_HEADER__
11 #define __PION_HTTPREADER_HEADER__
12 
13 #include <boost/asio.hpp>
14 #include <pion/PionConfig.hpp>
15 #include <pion/net/HTTPParser.hpp>
16 #include <pion/net/HTTPMessage.hpp>
17 #include <pion/net/TCPConnection.hpp>
18 #include <pion/net/TCPTimer.hpp>
19 
20 
21 namespace pion { // begin namespace pion
22 namespace net { // begin namespace net (Pion Network Library)
23 
24 
28 class PION_NET_API HTTPReader :
29  public HTTPParser
30 {
31 public:
32 
33  // default destructor
34  virtual ~HTTPReader() {}
35 
37  void receive(void);
38 
40  inline TCPConnectionPtr& getTCPConnection(void) { return m_tcp_conn; }
41 
43  inline void setTimeout(boost::uint32_t seconds) { m_read_timeout = seconds; }
44 
45 
46 protected:
47 
55  HTTPReader(const bool is_request, TCPConnectionPtr& tcp_conn)
56  : HTTPParser(is_request), m_tcp_conn(tcp_conn),
57  m_read_timeout(DEFAULT_READ_TIMEOUT)
58  {}
59 
66  void consumeBytes(const boost::system::error_code& read_error,
67  std::size_t bytes_read);
68 
70  void consumeBytes(void);
71 
73  virtual void readBytes(void) = 0;
74 
76  virtual void finishedReading(const boost::system::error_code& ec) = 0;
77 
79  virtual HTTPMessage& getMessage(void) = 0;
80 
81 
82 private:
83 
85  void readBytesWithTimeout(void);
86 
92  void handleReadError(const boost::system::error_code& read_error);
93 
94 
96  static const boost::uint32_t DEFAULT_READ_TIMEOUT;
97 
98 
100  TCPConnectionPtr m_tcp_conn;
101 
103  TCPTimerPtr m_timer_ptr;
104 
106  boost::uint32_t m_read_timeout;
107 };
108 
109 
110 } // end namespace net
111 } // end namespace pion
112 
113 #endif
TCPConnectionPtr & getTCPConnection(void)
returns a shared pointer to the TCP connection
Definition: HTTPReader.hpp:40
void setTimeout(boost::uint32_t seconds)
sets the maximum number of seconds for read operations
Definition: HTTPReader.hpp:43
the following enables use of the lock-free cache
HTTPReader(const bool is_request, TCPConnectionPtr &tcp_conn)
Definition: HTTPReader.hpp:55