pion-net
4.0.9
|
00001 // ------------------------------------------------------------------ 00002 // pion-net: a C++ framework for building lightweight HTTP interfaces 00003 // ------------------------------------------------------------------ 00004 // Copyright (C) 2007-2008 Atomic Labs, Inc. (http://www.atomiclabs.com) 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_HTTPREADER_HEADER__ 00011 #define __PION_HTTPREADER_HEADER__ 00012 00013 #include <boost/asio.hpp> 00014 #include <pion/PionConfig.hpp> 00015 #include <pion/net/HTTPParser.hpp> 00016 #include <pion/net/HTTPMessage.hpp> 00017 #include <pion/net/TCPConnection.hpp> 00018 #include <pion/net/TCPTimer.hpp> 00019 00020 00021 namespace pion { // begin namespace pion 00022 namespace net { // begin namespace net (Pion Network Library) 00023 00024 00028 class PION_NET_API HTTPReader : 00029 public HTTPParser 00030 { 00031 public: 00032 00033 // default destructor 00034 virtual ~HTTPReader() {} 00035 00037 void receive(void); 00038 00040 inline TCPConnectionPtr& getTCPConnection(void) { return m_tcp_conn; } 00041 00043 inline void setTimeout(boost::uint32_t seconds) { m_read_timeout = seconds; } 00044 00045 00046 protected: 00047 00055 HTTPReader(const bool is_request, TCPConnectionPtr& tcp_conn) 00056 : HTTPParser(is_request), m_tcp_conn(tcp_conn), 00057 m_read_timeout(DEFAULT_READ_TIMEOUT) 00058 {} 00059 00066 void consumeBytes(const boost::system::error_code& read_error, 00067 std::size_t bytes_read); 00068 00070 void consumeBytes(void); 00071 00073 virtual void readBytes(void) = 0; 00074 00076 virtual void finishedReading(const boost::system::error_code& ec) = 0; 00077 00079 virtual HTTPMessage& getMessage(void) = 0; 00080 00081 00082 private: 00083 00085 void readBytesWithTimeout(void); 00086 00092 void handleReadError(const boost::system::error_code& read_error); 00093 00094 00096 static const boost::uint32_t DEFAULT_READ_TIMEOUT; 00097 00098 00100 TCPConnectionPtr m_tcp_conn; 00101 00103 TCPTimerPtr m_timer_ptr; 00104 00106 boost::uint32_t m_read_timeout; 00107 }; 00108 00109 00110 } // end namespace net 00111 } // end namespace pion 00112 00113 #endif