#include <http_connection.hpp>
Public Types | |
typedef boost::function< void(const char *begin, const char *end)> | ReadHandler |
typedef boost::shared_ptr< const void > | ResourcePtr |
Public Member Functions | |
void | async_read (ReadHandler callback) |
HttpConnection (boost::asio::io_service &io_service, HttpServerRequestHandler request_handler) | |
boost::asio::ip::tcp::socket & | socket () |
void | start () |
void | write (const boost::asio::const_buffer &buffer, ResourcePtr resource) |
void | write (const std::string &) |
void | write (const std::vector< boost::asio::const_buffer > &buffer, ResourcePtr resource) |
void | write_and_clear (std::vector< unsigned char > &data) |
Private Member Functions | |
void | handle_read (const char *begin, const char *end) |
void | handle_read_raw (ReadHandler callback, const boost::system::error_code &e, std::size_t bytes_transferred) |
void | handle_write (const boost::system::error_code &e, std::vector< ResourcePtr > resources) |
void | write_pending () |
Private Attributes | |
boost::array< char, 8192 > | buffer_ |
boost::system::error_code | last_error_ |
std::vector< boost::asio::const_buffer > | pending_write_buffers_ |
std::vector< ResourcePtr > | pending_write_resources_ |
ReadHandler | read_handler_ |
HttpRequest | request_ |
HttpServerRequestHandler | request_handler_ |
HttpRequestParser | request_parser_ |
boost::asio::ip::tcp::socket | socket_ |
boost::asio::io_service::strand | strand_ |
bool | write_in_progress_ |
boost::mutex | write_mutex_ |
Represents a connection to a client The connection to the client is maintained as long as there is a shared pointer to the connection object. If supplying the response is simple then it can be done in the request handler callback from the server. However, if the response will take time to generate or must be supplied over a long period of time then a shared_ptr to the connection can be held and used later. While reading and writing from multiple threads is supported, care should be taken to ensure that proper external synchronization is done as needed. For example, while write can be called from two threads, if two calls to write need to be unseperated then calls to write should be locked to prevent interleaving of different write calls.
Definition at line 34 of file http_connection.hpp.
typedef boost::function<void(const char* begin, const char* end)> async_web_server_cpp::HttpConnection::ReadHandler |
Definition at line 39 of file http_connection.hpp.
typedef boost::shared_ptr<const void> async_web_server_cpp::HttpConnection::ResourcePtr |
Definition at line 40 of file http_connection.hpp.
|
explicit |
Definition at line 9 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::async_read | ( | ReadHandler | callback | ) |
Perform an async read
Definition at line 72 of file http_connection.cpp.
|
private |
Definition at line 27 of file http_connection.cpp.
|
private |
Definition at line 59 of file http_connection.cpp.
|
private |
Definition at line 140 of file http_connection.cpp.
boost::asio::ip::tcp::socket & async_web_server_cpp::HttpConnection::socket | ( | ) |
Definition at line 16 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::start | ( | ) |
Start async operation to read request (normally called by server)
Definition at line 21 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::write | ( | const boost::asio::const_buffer & | buffer, |
ResourcePtr | resource | ||
) |
Definition at line 100 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::write | ( | const std::string & | content | ) |
Definition at line 94 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::write | ( | const std::vector< boost::asio::const_buffer > & | buffer, |
ResourcePtr | resource | ||
) |
Definition at line 111 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::write_and_clear | ( | std::vector< unsigned char > & | data | ) |
Write the given bytes to the socket and clear the vector
Definition at line 86 of file http_connection.cpp.
|
private |
Definition at line 124 of file http_connection.cpp.
|
private |
Definition at line 84 of file http_connection.hpp.
|
private |
Definition at line 92 of file http_connection.hpp.
|
private |
Definition at line 90 of file http_connection.hpp.
|
private |
Definition at line 91 of file http_connection.hpp.
|
private |
Definition at line 93 of file http_connection.hpp.
|
private |
Definition at line 85 of file http_connection.hpp.
|
private |
Definition at line 83 of file http_connection.hpp.
|
private |
Definition at line 86 of file http_connection.hpp.
|
private |
Definition at line 82 of file http_connection.hpp.
|
private |
Definition at line 81 of file http_connection.hpp.
|
private |
Definition at line 89 of file http_connection.hpp.
|
private |
Definition at line 88 of file http_connection.hpp.