pion
5.0.6
|
00001 // --------------------------------------------------------------------- 00002 // pion: a Boost C++ framework for building lightweight HTTP interfaces 00003 // --------------------------------------------------------------------- 00004 // Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion) 00005 // 00006 // Distributed under the Boost Software License, Version 1.0. 00007 // See http://www.boost.org/LICENSE_1_0.txt 00008 // 00009 00010 #ifndef __PION_HTTP_READER_HEADER__ 00011 #define __PION_HTTP_READER_HEADER__ 00012 00013 #include <boost/asio.hpp> 00014 #include <pion/config.hpp> 00015 #include <pion/http/parser.hpp> 00016 #include <pion/http/message.hpp> 00017 #include <pion/tcp/connection.hpp> 00018 #include <pion/tcp/timer.hpp> 00019 00020 00021 namespace pion { // begin namespace pion 00022 namespace http { // begin namespace http 00023 00024 00028 class PION_API reader : 00029 public http::parser 00030 { 00031 public: 00032 00033 // default destructor 00034 virtual ~reader() {} 00035 00037 void receive(void); 00038 00040 inline tcp::connection_ptr& get_connection(void) { return m_tcp_conn; } 00041 00043 inline void set_timeout(boost::uint32_t seconds) { m_read_timeout = seconds; } 00044 00045 00046 protected: 00047 00055 reader(const bool is_request, tcp::connection_ptr& tcp_conn) 00056 : http::parser(is_request), m_tcp_conn(tcp_conn), 00057 m_read_timeout(DEFAULT_READ_TIMEOUT) 00058 {} 00059 00066 void consume_bytes(const boost::system::error_code& read_error, 00067 std::size_t bytes_read); 00068 00070 void consume_bytes(void); 00071 00073 virtual void read_bytes(void) = 0; 00074 00076 virtual void finished_reading(const boost::system::error_code& ec) = 0; 00077 00079 virtual http::message& get_message(void) = 0; 00080 00081 00082 private: 00083 00085 void read_bytes_with_timeout(void); 00086 00092 void handle_read_error(const boost::system::error_code& read_error); 00093 00094 00096 static const boost::uint32_t DEFAULT_READ_TIMEOUT; 00097 00098 00100 tcp::connection_ptr m_tcp_conn; 00101 00103 tcp::timer_ptr m_timer_ptr; 00104 00106 boost::uint32_t m_read_timeout; 00107 }; 00108 00109 00110 } // end namespace http 00111 } // end namespace pion 00112 00113 #endif