PionNetworkLibrary
|
#include <connection.hpp>
Classes | |
class | ssl_socket_type |
Public Types | |
enum | lifecycle_type { LIFECYCLE_CLOSE, LIFECYCLE_KEEPALIVE, LIFECYCLE_PIPELINED } |
data type for the connection's lifecycle state More... | |
enum | { READ_BUFFER_SIZE = 8192 } |
size of the read buffer More... | |
typedef boost::function1< void, boost::shared_ptr< connection > > | connection_handler |
data type for a function that handles TCP connection objects More... | |
typedef boost::array< char, READ_BUFFER_SIZE > | read_buffer_type |
data type for an I/O read buffer More... | |
typedef boost::asio::ip::tcp::socket | socket_type |
data type for a socket connection More... | |
typedef int | ssl_context_type |
Public Member Functions | |
connection (boost::asio::io_service &io_service, const bool ssl_flag=false) | |
connection (boost::asio::io_service &io_service, ssl_context_type &ssl_context) | |
bool | is_open (void) const |
returns true if the connection is currently open More... | |
void | close (void) |
closes the tcp socket and cancels any pending asynchronous operations More... | |
void | cancel (void) |
virtual | ~connection () |
virtual destructor More... | |
template<typename AcceptHandler > | |
void | async_accept (boost::asio::ip::tcp::acceptor &tcp_acceptor, AcceptHandler handler) |
boost::system::error_code | accept (boost::asio::ip::tcp::acceptor &tcp_acceptor) |
template<typename ConnectHandler > | |
void | async_connect (const boost::asio::ip::tcp::endpoint &tcp_endpoint, ConnectHandler handler) |
template<typename ConnectHandler > | |
void | async_connect (const boost::asio::ip::address &remote_addr, const unsigned int remote_port, ConnectHandler handler) |
boost::system::error_code | connect (boost::asio::ip::tcp::endpoint &tcp_endpoint) |
boost::system::error_code | connect (const boost::asio::ip::address &remote_addr, const unsigned int remote_port) |
boost::system::error_code | connect (const std::string &remote_server, const unsigned int remote_port) |
template<typename SSLHandshakeHandler > | |
void | async_handshake_client (SSLHandshakeHandler handler) |
template<typename SSLHandshakeHandler > | |
void | async_handshake_server (SSLHandshakeHandler handler) |
boost::system::error_code | handshake_client (void) |
boost::system::error_code | handshake_server (void) |
template<typename ReadHandler > | |
void | async_read_some (ReadHandler handler) |
template<typename ReadBufferType , typename ReadHandler > | |
void | async_read_some (ReadBufferType read_buffer, ReadHandler handler) |
std::size_t | read_some (boost::system::error_code &ec) |
template<typename ReadBufferType > | |
std::size_t | read_some (ReadBufferType read_buffer, boost::system::error_code &ec) |
template<typename CompletionCondition , typename ReadHandler > | |
void | async_read (CompletionCondition completion_condition, ReadHandler handler) |
template<typename MutableBufferSequence , typename CompletionCondition , typename ReadHandler > | |
void | async_read (const MutableBufferSequence &buffers, CompletionCondition completion_condition, ReadHandler handler) |
template<typename CompletionCondition > | |
std::size_t | read (CompletionCondition completion_condition, boost::system::error_code &ec) |
template<typename MutableBufferSequence , typename CompletionCondition > | |
std::size_t | read (const MutableBufferSequence &buffers, CompletionCondition completion_condition, boost::system::error_code &ec) |
template<typename ConstBufferSequence , typename write_handler_t > | |
void | async_write (const ConstBufferSequence &buffers, write_handler_t handler) |
template<typename ConstBufferSequence > | |
std::size_t | write (const ConstBufferSequence &buffers, boost::system::error_code &ec) |
void | finish (void) |
bool | get_ssl_flag (void) const |
returns true if the connection is encrypted using SSL More... | |
void | set_lifecycle (lifecycle_type t) |
sets the lifecycle type for the connection More... | |
lifecycle_type | get_lifecycle (void) const |
returns the lifecycle type for the connection More... | |
bool | get_keep_alive (void) const |
returns true if the connection should be kept alive More... | |
bool | get_pipelined (void) const |
returns true if the HTTP requests are pipelined More... | |
read_buffer_type & | get_read_buffer (void) |
returns the buffer used for reading data from the TCP connection More... | |
void | save_read_pos (const char *read_ptr, const char *read_end_ptr) |
void | load_read_pos (const char *&read_ptr, const char *&read_end_ptr) const |
boost::asio::ip::tcp::endpoint | get_remote_endpoint (void) const |
returns an ASIO endpoint for the client connection More... | |
boost::asio::ip::address | get_remote_ip (void) const |
returns the client's IP address More... | |
unsigned short | get_remote_port (void) const |
returns the client's port number More... | |
boost::asio::io_service & | get_io_service (void) |
returns reference to the io_service used for async operations More... | |
socket_type & | get_socket (void) |
returns non-const reference to underlying TCP socket object More... | |
ssl_socket_type & | get_ssl_socket (void) |
returns non-const reference to underlying SSL socket object More... | |
const socket_type & | get_socket (void) const |
returns const reference to underlying TCP socket object More... | |
const ssl_socket_type & | get_ssl_socket (void) const |
returns const reference to underlying SSL socket object More... | |
Static Public Member Functions | |
static boost::shared_ptr < connection > | create (boost::asio::io_service &io_service, ssl_context_type &ssl_context, const bool ssl_flag, connection_handler finished_handler) |
Protected Member Functions | |
connection (boost::asio::io_service &io_service, ssl_context_type &ssl_context, const bool ssl_flag, connection_handler finished_handler) | |
connection: represents a single tcp connection
typedef boost::function1<void, boost::shared_ptr<connection> > pion::tcp::connection::connection_handler |
data type for a function that handles TCP connection objects
typedef boost::array<char, READ_BUFFER_SIZE> pion::tcp::connection::read_buffer_type |
data type for an I/O read buffer
typedef boost::asio::ip::tcp::socket pion::tcp::connection::socket_type |
data type for a socket connection
typedef int pion::tcp::connection::ssl_context_type |
|
inlineexplicit |
creates a new connection object
io_service | asio service associated with the connection |
ssl_flag | if true then the connection will be encrypted using SSL |
References save_read_pos().
Referenced by create().
|
inline |
creates a new connection object for SSL
io_service | asio service associated with the connection |
ssl_context | asio ssl context associated with the connection |
References save_read_pos().
|
inlinevirtual |
virtual destructor
References close().
|
inlineprotected |
protected constructor restricts creation of objects (use create())
io_service | asio service associated with the connection |
ssl_context | asio ssl context associated with the connection |
ssl_flag | if true then the connection will be encrypted using SSL |
finished_handler | function called when a server has finished handling the connection |
References save_read_pos().
|
inline |
accepts a new tcp connection (blocks until established)
tcp_acceptor | object used to accept new connections |
References pion::tcp::connection::ssl_socket_type::lowest_layer().
Referenced by pion::tcp::stream::accept().
|
inline |
asynchronously accepts a new tcp connection
tcp_acceptor | object used to accept new connections |
handler | called after a new connection has been accepted |
References pion::tcp::connection::ssl_socket_type::lowest_layer().
|
inline |
asynchronously connects to a remote endpoint
tcp_endpoint | remote endpoint to connect to |
handler | called after a new connection has been established |
References pion::tcp::connection::ssl_socket_type::lowest_layer().
Referenced by async_connect().
|
inline |
asynchronously connects to a (IPv4) remote endpoint
remote_addr | remote IP address (v4) to connect to |
remote_port | remote port number to connect to |
handler | called after a new connection has been established |
References async_connect().
|
inline |
asynchronously performs client-side SSL handshake for a new connection
handler | called after the ssl handshake has completed |
|
inline |
asynchronously performs server-side SSL handshake for a new connection
handler | called after the ssl handshake has completed |
|
inline |
asynchronously reads data into the connection's read buffer until completion_condition is met
completion_condition | determines if the read operation is complete |
handler | called after the read operation has completed |
References get_ssl_flag(), and pion::tcp::connection::ssl_socket_type::next_layer().
|
inline |
asynchronously reads data from the connection until completion_condition is met
buffers | one or more buffers into which the data will be read |
completion_condition | determines if the read operation is complete |
handler | called after the read operation has completed |
References get_ssl_flag(), and pion::tcp::connection::ssl_socket_type::next_layer().
|
inline |
asynchronously reads some data into the connection's read buffer
handler | called after the read operation has completed |
References get_ssl_flag(), and pion::tcp::connection::ssl_socket_type::next_layer().
|
inline |
asynchronously reads some data into the connection's read buffer
read_buffer | the buffer to read data into |
handler | called after the read operation has completed |
References get_ssl_flag(), and pion::tcp::connection::ssl_socket_type::next_layer().
|
inline |
asynchronously writes data to the connection
buffers | one or more buffers containing the data to be written |
handler | called after the data has been written |
References get_ssl_flag(), and pion::tcp::connection::ssl_socket_type::next_layer().
|
inline |
cancels any asynchronous operations pending on the socket. there is no good way to do this on windows until vista or later (0x0600) see http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/basic_stream_socket/cancel/overload2.html note that the asio docs are misleading because close() is not thread-safe, and the suggested #define statements cause WAY too much trouble and heartache
References pion::tcp::connection::ssl_socket_type::next_layer().
|
inline |
closes the tcp socket and cancels any pending asynchronous operations
References is_open(), and pion::tcp::connection::ssl_socket_type::next_layer().
Referenced by pion::tcp::stream::close(), connect(), pion::tcp::server::stop(), and ~connection().
|
inline |
connects to a remote endpoint (blocks until established)
tcp_endpoint | remote endpoint to connect to |
References pion::tcp::connection::ssl_socket_type::lowest_layer().
Referenced by connect(), and pion::tcp::stream::connect().
|
inline |
connects to a (IPv4) remote endpoint (blocks until established)
remote_addr | remote IP address (v4) to connect to |
remote_port | remote port number to connect to |
References connect().
|
inline |
connects to a remote endpoint with hostname lookup
remote_server | hostname of the remote server to connect to |
remote_port | remote port number to connect to |
References close(), connect(), and pion::tcp::connection::ssl_socket_type::lowest_layer().
|
inlinestatic |
creates new shared connection objects
io_service | asio service associated with the connection |
ssl_context | asio ssl context associated with the connection |
ssl_flag | if true then the connection will be encrypted using SSL |
finished_handler | function called when a server has finished handling the connection |
References connection().
|
inline |
This function should be called when a server has finished handling the connection
Referenced by pion::http::server::handle_bad_request(), pion::http::server::handle_forbidden_request(), pion::http::server::handle_method_not_allowed(), pion::http::server::handle_not_found_request(), pion::http::cookie_auth::handle_ok(), pion::http::cookie_auth::handle_redirection(), pion::http::server::handle_server_error(), pion::http::basic_auth::handle_unauthorized(), and pion::http::cookie_auth::handle_unauthorized().
|
inline |
returns reference to the io_service used for async operations
References pion::tcp::connection::ssl_socket_type::lowest_layer().
|
inline |
returns true if the connection should be kept alive
References LIFECYCLE_CLOSE.
Referenced by pion::http::message::send().
|
inline |
returns the lifecycle type for the connection
|
inline |
returns true if the HTTP requests are pipelined
References LIFECYCLE_PIPELINED.
Referenced by pion::http::message::receive().
|
inline |
returns the buffer used for reading data from the TCP connection
Referenced by pion::http::message::receive().
|
inline |
returns an ASIO endpoint for the client connection
Referenced by get_remote_ip(), and get_remote_port().
|
inline |
returns the client's IP address
References get_remote_endpoint().
Referenced by pion::tcp::stream::get_remote_ip().
|
inline |
returns the client's port number
References get_remote_endpoint().
|
inline |
returns non-const reference to underlying TCP socket object
References pion::tcp::connection::ssl_socket_type::next_layer().
|
inline |
returns const reference to underlying TCP socket object
|
inline |
returns true if the connection is encrypted using SSL
Referenced by async_read(), async_read_some(), async_write(), pion::tcp::stream::get_ssl_flag(), read(), read_some(), and write().
|
inline |
returns non-const reference to underlying SSL socket object
|
inline |
returns const reference to underlying SSL socket object
|
inline |
performs client-side SSL handshake for a new connection (blocks until finished)
Referenced by pion::tcp::stream::connect().
|
inline |
performs server-side SSL handshake for a new connection (blocks until finished)
Referenced by pion::tcp::stream::accept().
|
inline |
returns true if the connection is currently open
Referenced by close(), and pion::tcp::stream::is_open().
|
inline |
loads a read position bookmark
read_ptr | points to the next character to be consumed in the read_buffer |
read_end_ptr | points to the end of the read_buffer (last byte + 1) |
Referenced by pion::http::message::receive().
|
inline |
reads data into the connection's read buffer until completion_condition is met (blocks until finished)
completion_condition | determines if the read operation is complete |
ec | contains error code if the read fails |
References get_ssl_flag(), and pion::tcp::connection::ssl_socket_type::next_layer().
|
inline |
reads data from the connection until completion_condition is met (blocks until finished)
buffers | one or more buffers into which the data will be read |
completion_condition | determines if the read operation is complete |
ec | contains error code if the read fails |
References get_ssl_flag(), and pion::tcp::connection::ssl_socket_type::next_layer().
|
inline |
reads some data into the connection's read buffer (blocks until finished)
ec | contains error code if the read fails |
References get_ssl_flag(), and pion::tcp::connection::ssl_socket_type::next_layer().
Referenced by pion::http::message::receive().
|
inline |
reads some data into the connection's read buffer (blocks until finished)
read_buffer | the buffer to read data into |
ec | contains error code if the read fails |
References get_ssl_flag(), and pion::tcp::connection::ssl_socket_type::next_layer().
|
inline |
saves a read position bookmark
read_ptr | points to the next character to be consumed in the read_buffer |
read_end_ptr | points to the end of the read_buffer (last byte + 1) |
Referenced by connection(), and pion::http::message::receive().
|
inline |
sets the lifecycle type for the connection
Referenced by pion::http::message::receive().
|
inline |
writes data to the connection (blocks until finished)
buffers | one or more buffers containing the data to be written |
ec | contains error code if the write fails |
References get_ssl_flag(), and pion::tcp::connection::ssl_socket_type::next_layer().
Referenced by pion::http::message::send().