#include <http_connection.hpp>
Public Types | |
typedef boost::function< void(const char *begin, const char *end) | ReadHandler ) |
typedef boost::shared_ptr< 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 std::string &) |
void | write (const boost::asio::const_buffer &buffer, ResourcePtr resource) |
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< boost::shared_ptr< void > > 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 33 of file http_connection.hpp.
typedef boost::function<void(const char* begin, const char* end) async_web_server_cpp::HttpConnection::ReadHandler) |
Definition at line 37 of file http_connection.hpp.
typedef boost::shared_ptr<void> async_web_server_cpp::HttpConnection::ResourcePtr |
Definition at line 38 of file http_connection.hpp.
async_web_server_cpp::HttpConnection::HttpConnection | ( | boost::asio::io_service & | io_service, |
HttpServerRequestHandler | request_handler | ||
) | [explicit] |
Definition at line 8 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::async_read | ( | ReadHandler | callback | ) |
Perform an async read
Definition at line 69 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::handle_read | ( | const char * | begin, |
const char * | end | ||
) | [private] |
Definition at line 27 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::handle_read_raw | ( | ReadHandler | callback, |
const boost::system::error_code & | e, | ||
std::size_t | bytes_transferred | ||
) | [private] |
Definition at line 56 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::handle_write | ( | const boost::system::error_code & | e, |
std::vector< boost::shared_ptr< void > > | resources | ||
) | [private] |
Definition at line 134 of file http_connection.cpp.
boost::asio::ip::tcp::socket & async_web_server_cpp::HttpConnection::socket | ( | ) |
Definition at line 17 of file http_connection.cpp.
Start async operation to read request (normally called by server)
Definition at line 22 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::write | ( | const std::string & | content | ) |
Definition at line 89 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::write | ( | const boost::asio::const_buffer & | buffer, |
ResourcePtr | resource | ||
) |
Definition at line 95 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 106 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 82 of file http_connection.cpp.
void async_web_server_cpp::HttpConnection::write_pending | ( | ) | [private] |
Definition at line 119 of file http_connection.cpp.
boost::array<char, 8192> async_web_server_cpp::HttpConnection::buffer_ [private] |
Definition at line 83 of file http_connection.hpp.
boost::system::error_code async_web_server_cpp::HttpConnection::last_error_ [private] |
Definition at line 91 of file http_connection.hpp.
std::vector<boost::asio::const_buffer> async_web_server_cpp::HttpConnection::pending_write_buffers_ [private] |
Definition at line 89 of file http_connection.hpp.
std::vector<ResourcePtr> async_web_server_cpp::HttpConnection::pending_write_resources_ [private] |
Definition at line 90 of file http_connection.hpp.
Definition at line 92 of file http_connection.hpp.
Definition at line 84 of file http_connection.hpp.
Definition at line 82 of file http_connection.hpp.
Definition at line 85 of file http_connection.hpp.
boost::asio::ip::tcp::socket async_web_server_cpp::HttpConnection::socket_ [private] |
Definition at line 81 of file http_connection.hpp.
boost::asio::io_service::strand async_web_server_cpp::HttpConnection::strand_ [private] |
Definition at line 80 of file http_connection.hpp.
bool async_web_server_cpp::HttpConnection::write_in_progress_ [private] |
Definition at line 88 of file http_connection.hpp.
boost::mutex async_web_server_cpp::HttpConnection::write_mutex_ [private] |
Definition at line 87 of file http_connection.hpp.