| Home | Libraries | People | FAQ | More

# http::server::connection Class Reference

Inherits enable_shared_from_this< http::server::connection >, and noncopyable.

Collaboration diagram for http::server::connection:

List of all members.

## Detailed Description

Represents a single connection from a client.

Definition at line 20 of file connection.hpp.

## Public Member Functions

| connection (boost::asio::io_service &io_service, connection_manager &manager, request_handler &handler)
| Construct a connection with the given io_service.
boost::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 boost::asio::error &e, std::size_t bytes_transferred)
| Handle completion of a read operation.
void | handle_write (const boost::asio::error &e)
| Handle completion of a write operation.

## Private Attributes

boost::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.

## Constructor & Destructor Documentation

http::server::connection::connection | ( | boost::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 }

## Member Function Documentation

boost::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(boost::asio::buffer(buffer_),
    00026       boost::bind(&connection::handle_read, shared_from_this(),
    00027         boost::asio::placeholders::error,
    00028         boost::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().

    00032 {
    00033   socket_.close();
    00034 }

void http::server::connection::handle_read | ( | const boost::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       boost::asio::async_write(socket_, reply_.to_buffers(),
    00049           boost::bind(&connection::handle_write, shared_from_this(),
    00050             boost::asio::placeholders::error));
    00051     }
    00052     else if (!result)
    00053     {
    00054       reply_ = reply::stock_reply(reply::bad_request);
    00055       boost::asio::async_write(socket_, reply_.to_buffers(),
    00056           boost::bind(&connection::handle_write, shared_from_this(),
    00057             boost::asio::placeholders::error));
    00058     }
    00059     else
    00060     {
    00061       socket_.async_read_some(boost::asio::buffer(buffer_),
    00062           boost::bind(&connection::handle_read, shared_from_this(),
    00063             boost::asio::placeholders::error,
    00064             boost::asio::placeholders::bytes_transferred));
    00065     }
    00066   }
    00067   else if (e != boost::asio::error::operation_aborted)
    00068   {
    00069     connection_manager_.stop(shared_from_this());
    00070   }
    00071 }

void http::server::connection::handle_write | ( | const boost::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 != boost::asio::error::operation_aborted)
    00076   {
    00077     connection_manager_.stop(shared_from_this());
    00078   }
    00079 }

## Member Data Documentation

boost::asio::ip::tcp::socket http::server::connection::socket_`[private]`

Socket for the connection.

Definition at line 46 of file connection.hpp.

Referenced by handle_read(), socket(), start(), and stop().

connection_manager& http::server::connection::connection_manager_`[private]`

The manager for this connection.

Definition at line 49 of file connection.hpp.

Referenced by handle_read(), and handle_write().

request_handler& http::server::connection::request_handler_`[private]`

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 incoming request.

Definition at line 58 of file connection.hpp.

Referenced by handle_read().

request_parser http::server::connection::request_parser_`[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().

The documentation for this class was generated from the following files:

- http/server/connection.hpp
- http/server/connection.cpp

| Copyright © 2003 - 2006 Christopher M. Kohlhoff