10 #include <boost/asio.hpp> 11 #include <boost/logic/tribool.hpp> 12 #include <pion/http/reader.hpp> 13 #include <pion/http/request.hpp> 22 const boost::uint32_t reader::DEFAULT_READ_TIMEOUT = 10;
29 if (m_tcp_conn->get_pipelined()) {
31 m_tcp_conn->set_lifecycle(tcp::connection::LIFECYCLE_CLOSE);
36 m_tcp_conn->set_lifecycle(tcp::connection::LIFECYCLE_CLOSE);
37 read_bytes_with_timeout();
42 std::size_t bytes_read)
46 m_timer_ptr->cancel();
52 handle_read_error(read_error);
56 PION_LOG_DEBUG(
m_logger,
"Read " << bytes_read <<
" bytes from HTTP " 76 boost::system::error_code ec;
91 m_tcp_conn->set_lifecycle(tcp::connection::LIFECYCLE_KEEPALIVE);
94 m_tcp_conn->set_lifecycle(tcp::connection::LIFECYCLE_PIPELINED);
101 PION_LOG_DEBUG(
m_logger,
"HTTP pipelined " 106 m_tcp_conn->set_lifecycle(tcp::connection::LIFECYCLE_CLOSE);
112 }
else if (result ==
false) {
114 m_tcp_conn->set_lifecycle(tcp::connection::LIFECYCLE_CLOSE);
119 read_bytes_with_timeout();
123 void reader::read_bytes_with_timeout(
void)
125 if (m_read_timeout > 0) {
126 m_timer_ptr.reset(
new tcp::timer(m_tcp_conn));
127 m_timer_ptr->start(m_read_timeout);
128 }
else if (m_timer_ptr) {
134 void reader::handle_read_error(
const boost::system::error_code& read_error)
137 m_tcp_conn->set_lifecycle(tcp::connection::LIFECYCLE_CLOSE);
141 boost::system::error_code ec;
148 if (read_error == boost::asio::error::operation_aborted) {
152 <<
" parsing aborted (shutting down)");
155 <<
" parsing aborted (" << read_error.message() <<
')');
void receive(void)
Incrementally reads & parses the HTTP message.
void consume_bytes(void)
Consumes bytes that have been read using an HTTP parser.
const char * m_read_end_ptr
points to the end of the read_buffer (last byte + 1)
logger m_logger
primary logging interface used by this class
void set_is_valid(bool b=true)
sets whether or not the message is valid
virtual http::message & get_message(void)=0
Returns a reference to the HTTP message being parsed.
bool eof(void) const
returns true if there are no more bytes available in the read buffer
virtual void finished_reading(const boost::system::error_code &ec)=0
Called after we have finished reading/parsing the HTTP message.
virtual void read_bytes(void)=0
Reads more bytes from the TCP connection.
std::size_t bytes_available(void) const
returns the number of bytes available in the read buffer
boost::tribool parse(http::message &http_msg, boost::system::error_code &ec)
std::size_t gcount(void) const
returns the number of bytes read during the last parse operation
bool is_parsing_request(void) const
returns true if the parser is being used to parse an HTTP request
const char * m_read_ptr
points to the next character to be consumed in the read_buffer
std::size_t get_total_bytes_read(void) const
returns the total number of bytes read while parsing the HTTP message
bool check_premature_eof(http::message &http_msg)
void set_read_buffer(const char *ptr, size_t len)