Examples |
Collaboration diagram for http::server::connection:
Definition at line 20 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 &e, std::size_t bytes_transferred) |
Handle completion of a read operation. | |
void | handle_write (const asio::error &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 10 of file connection.cpp.
00012 : socket_(io_service), 00013 connection_manager_(manager), 00014 request_handler_(handler) 00015 { 00016 }
asio::ip::tcp::socket & http::server::connection::socket | ( | ) |
Get the socket associated with the connection.
Definition at line 18 of file connection.cpp.
00019 { 00020 return socket_; 00021 }
void http::server::connection::start | ( | ) |
Start the first asynchronous operation for the connection.
Definition at line 23 of file connection.cpp.
00024 { 00025 socket_.async_read_some(asio::buffer(buffer_), 00026 boost::bind(&connection::handle_read, shared_from_this(), 00027 asio::placeholders::error, 00028 asio::placeholders::bytes_transferred)); 00029 }
void http::server::connection::stop | ( | ) |
Stop all asynchronous operations associated with the connection.
Definition at line 31 of file connection.cpp.
Referenced by http::server::connection_manager::stop_all().
void http::server::connection::handle_read | ( | const asio::error & | e, | |
std::size_t | bytes_transferred | |||
) | [private] |
Handle completion of a read operation.
Definition at line 36 of file connection.cpp.
Referenced by start().
00038 { 00039 if (!e) 00040 { 00041 boost::tribool result; 00042 boost::tie(result, boost::tuples::ignore) = request_parser_.parse( 00043 request_, buffer_.data(), buffer_.data() + bytes_transferred); 00044 00045 if (result) 00046 { 00047 request_handler_.handle_request(request_, reply_); 00048 asio::async_write(socket_, reply_.to_buffers(), 00049 boost::bind(&connection::handle_write, shared_from_this(), 00050 asio::placeholders::error)); 00051 } 00052 else if (!result) 00053 { 00054 reply_ = reply::stock_reply(reply::bad_request); 00055 asio::async_write(socket_, reply_.to_buffers(), 00056 boost::bind(&connection::handle_write, shared_from_this(), 00057 asio::placeholders::error)); 00058 } 00059 else 00060 { 00061 socket_.async_read_some(asio::buffer(buffer_), 00062 boost::bind(&connection::handle_read, shared_from_this(), 00063 asio::placeholders::error, 00064 asio::placeholders::bytes_transferred)); 00065 } 00066 } 00067 else if (e != asio::error::operation_aborted) 00068 { 00069 connection_manager_.stop(shared_from_this()); 00070 } 00071 }
void http::server::connection::handle_write | ( | const asio::error & | e | ) | [private] |
Handle completion of a write operation.
Definition at line 73 of file connection.cpp.
Referenced by handle_read().
00074 { 00075 if (e != asio::error::operation_aborted) 00076 { 00077 connection_manager_.stop(shared_from_this()); 00078 } 00079 }
Socket for the connection.
Definition at line 46 of file connection.hpp.
Referenced by handle_read(), socket(), start(), and stop().
The manager for this connection.
Definition at line 49 of file connection.hpp.
Referenced by handle_read(), and handle_write().
The handler used to process the incoming request.
Definition at line 52 of file connection.hpp.
Referenced by handle_read().
boost::array<char, 8192> http::server::connection::buffer_ [private] |
Buffer for incoming data.
Definition at line 55 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 61 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 64 of file connection.hpp.
Referenced by handle_read().