Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
async_web_server_cpp::HttpConnection Class Reference

#include <http_connection.hpp>

Inheritance diagram for async_web_server_cpp::HttpConnection:
Inheritance graph
[legend]

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 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< 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< ResourcePtrpending_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_
 

Detailed Description

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.

Member Typedef Documentation

◆ ReadHandler

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.

◆ ResourcePtr

typedef boost::shared_ptr<const void> async_web_server_cpp::HttpConnection::ResourcePtr

Definition at line 40 of file http_connection.hpp.

Constructor & Destructor Documentation

◆ HttpConnection()

async_web_server_cpp::HttpConnection::HttpConnection ( boost::asio::io_service &  io_service,
HttpServerRequestHandler  request_handler 
)
explicit

Definition at line 9 of file http_connection.cpp.

Member Function Documentation

◆ async_read()

void async_web_server_cpp::HttpConnection::async_read ( ReadHandler  callback)

Perform an async read

Definition at line 72 of file http_connection.cpp.

◆ handle_read()

void async_web_server_cpp::HttpConnection::handle_read ( const char *  begin,
const char *  end 
)
private

Definition at line 27 of file http_connection.cpp.

◆ handle_read_raw()

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 59 of file http_connection.cpp.

◆ handle_write()

void async_web_server_cpp::HttpConnection::handle_write ( const boost::system::error_code &  e,
std::vector< ResourcePtr resources 
)
private

Definition at line 140 of file http_connection.cpp.

◆ socket()

boost::asio::ip::tcp::socket & async_web_server_cpp::HttpConnection::socket ( )

Definition at line 16 of file http_connection.cpp.

◆ start()

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.

◆ write() [1/3]

void async_web_server_cpp::HttpConnection::write ( const std::string &  content)

Definition at line 94 of file http_connection.cpp.

◆ write() [2/3]

void async_web_server_cpp::HttpConnection::write ( const boost::asio::const_buffer &  buffer,
ResourcePtr  resource 
)

Definition at line 100 of file http_connection.cpp.

◆ write() [3/3]

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.

◆ write_and_clear()

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.

◆ write_pending()

void async_web_server_cpp::HttpConnection::write_pending ( )
private

Definition at line 124 of file http_connection.cpp.

Member Data Documentation

◆ buffer_

boost::array<char, 8192> async_web_server_cpp::HttpConnection::buffer_
private

Definition at line 84 of file http_connection.hpp.

◆ last_error_

boost::system::error_code async_web_server_cpp::HttpConnection::last_error_
private

Definition at line 92 of file http_connection.hpp.

◆ pending_write_buffers_

std::vector<boost::asio::const_buffer> async_web_server_cpp::HttpConnection::pending_write_buffers_
private

Definition at line 90 of file http_connection.hpp.

◆ pending_write_resources_

std::vector<ResourcePtr> async_web_server_cpp::HttpConnection::pending_write_resources_
private

Definition at line 91 of file http_connection.hpp.

◆ read_handler_

ReadHandler async_web_server_cpp::HttpConnection::read_handler_
private

Definition at line 93 of file http_connection.hpp.

◆ request_

HttpRequest async_web_server_cpp::HttpConnection::request_
private

Definition at line 85 of file http_connection.hpp.

◆ request_handler_

HttpServerRequestHandler async_web_server_cpp::HttpConnection::request_handler_
private

Definition at line 83 of file http_connection.hpp.

◆ request_parser_

HttpRequestParser async_web_server_cpp::HttpConnection::request_parser_
private

Definition at line 86 of file http_connection.hpp.

◆ socket_

boost::asio::ip::tcp::socket async_web_server_cpp::HttpConnection::socket_
private

Definition at line 82 of file http_connection.hpp.

◆ strand_

boost::asio::io_service::strand async_web_server_cpp::HttpConnection::strand_
private

Definition at line 81 of file http_connection.hpp.

◆ write_in_progress_

bool async_web_server_cpp::HttpConnection::write_in_progress_
private

Definition at line 89 of file http_connection.hpp.

◆ write_mutex_

boost::mutex async_web_server_cpp::HttpConnection::write_mutex_
private

Definition at line 88 of file http_connection.hpp.


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


async_web_server_cpp
Author(s): Mitchell Wills , Russel Toris
autogenerated on Mon Feb 28 2022 21:54:08