Examples |
Collaboration diagram for http::server::connection:
Definition at line 30 of file connection.hpp.
Public Member Functions | |
connection (asio::io_service &io_service, connection_manager &manager, request_handler &handler) | |
Construct a connection with the given io_service. | |
asio::ip::tcp::socket & | socket () |
Get the socket associated with the connection. | |
void | start () |
Start the first asynchronous operation for the connection. | |
void | stop () |
Stop all asynchronous operations associated with the connection. | |
Private Member Functions | |
void | handle_read (const asio::error_code &e, std::size_t bytes_transferred) |
Handle completion of a read operation. | |
void | handle_write (const asio::error_code &e) |
Handle completion of a write operation. | |
Private Attributes | |
asio::ip::tcp::socket | socket_ |
Socket for the connection. | |
connection_manager & | connection_manager_ |
The manager for this connection. | |
request_handler & | request_handler_ |
The handler used to process the incoming request. | |
boost::array< char, 8192 > | buffer_ |
Buffer for incoming data. | |
request | request_ |
The incoming request. | |
request_parser | request_parser_ |
The parser for the incoming request. | |
reply | reply_ |
The reply to be sent back to the client. |
http::server::connection::connection | ( | asio::io_service & | io_service, | |
connection_manager & | manager, | |||
request_handler & | handler | |||
) | [explicit] |
Construct a connection with the given io_service.
Definition at line 20 of file connection.cpp.
00022 : socket_(io_service), 00023 connection_manager_(manager), 00024 request_handler_(handler) 00025 { 00026 }
asio::ip::tcp::socket & http::server::connection::socket | ( | ) |
Get the socket associated with the connection.
Definition at line 28 of file connection.cpp.
00029 { 00030 return socket_; 00031 }
void http::server::connection::start | ( | ) |
Start the first asynchronous operation for the connection.
Definition at line 33 of file connection.cpp.
00034 { 00035 socket_.async_read_some(asio::buffer(buffer_), 00036 boost::bind(&connection::handle_read, shared_from_this(), 00037 asio::placeholders::error, 00038 asio::placeholders::bytes_transferred)); 00039 }
void http::server::connection::stop | ( | ) |
Stop all asynchronous operations associated with the connection.
Definition at line 41 of file connection.cpp.
Referenced by http::server::connection_manager::stop_all().
void http::server::connection::handle_read | ( | const asio::error_code & | e, | |
std::size_t | bytes_transferred | |||
) | [private] |
Handle completion of a read operation.
Definition at line 46 of file connection.cpp.
Referenced by start().
00048 { 00049 if (!e) 00050 { 00051 boost::tribool result; 00052 boost::tie(result, boost::tuples::ignore) = request_parser_.parse( 00053 request_, buffer_.data(), buffer_.data() + bytes_transferred); 00054 00055 if (result) 00056 { 00057 request_handler_.handle_request(request_, reply_); 00058 asio::async_write(socket_, reply_.to_buffers(), 00059 boost::bind(&connection::handle_write, shared_from_this(), 00060 asio::placeholders::error)); 00061 } 00062 else if (!result) 00063 { 00064 reply_ = reply::stock_reply(reply::bad_request); 00065 asio::async_write(socket_, reply_.to_buffers(), 00066 boost::bind(&connection::handle_write, shared_from_this(), 00067 asio::placeholders::error)); 00068 } 00069 else 00070 { 00071 socket_.async_read_some(asio::buffer(buffer_), 00072 boost::bind(&connection::handle_read, shared_from_this(), 00073 asio::placeholders::error, 00074 asio::placeholders::bytes_transferred)); 00075 } 00076 } 00077 else if (e != asio::error::operation_aborted) 00078 { 00079 connection_manager_.stop(shared_from_this()); 00080 } 00081 }
void http::server::connection::handle_write | ( | const asio::error_code & | e | ) | [private] |
Handle completion of a write operation.
Definition at line 83 of file connection.cpp.
Referenced by handle_read().
00084 { 00085 if (e != asio::error::operation_aborted) 00086 { 00087 connection_manager_.stop(shared_from_this()); 00088 } 00089 }
Socket for the connection.
Definition at line 57 of file connection.hpp.
Referenced by handle_read(), socket(), start(), and stop().
The manager for this connection.
Definition at line 60 of file connection.hpp.
Referenced by handle_read(), and handle_write().
The handler used to process the incoming request.
Definition at line 63 of file connection.hpp.
Referenced by handle_read().
boost::array<char, 8192> http::server::connection::buffer_ [private] |
Buffer for incoming data.
Definition at line 66 of file connection.hpp.
Referenced by handle_read(), and start().
request http::server::connection::request_ [private] |
The parser for the incoming request.
Definition at line 72 of file connection.hpp.
Referenced by handle_read().
reply http::server::connection::reply_ [private] |
The reply to be sent back to the client.
Definition at line 75 of file connection.hpp.
Referenced by handle_read().