staticlib_pion  2.0.2
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | List of all members
staticlib::pion::tcp_connection Class Reference

Represents a single tcp connection. More...

#include <staticlib/pion/tcp_connection.hpp>

Public Types

enum  lifecycle
 Data type for the connection's current_lifecycle state. More...

Public Member Functions

 tcp_connection (asio::io_service &io_service, ssl_context_type &ssl_context, const bool ssl_flag_in, connection_handler finished_handler_in)
 Constructor to be used with std::make_shared
 tcp_connection (const tcp_connection &)
 Deleted copy constructor.
tcp_connection & operator= (const tcp_connection &)
 Deleted copy assignment operator.
virtual ~tcp_connection ()
 Virtual destructor.
bool is_open () const
 Returns true if the connection is currently open.
void close ()
 Closes the tcp socket and cancels any pending asynchronous operations.
void cancel ()
 Cancels any asynchronous operations pending on the socket.
void cancel_timer ()
 Cancels timer.
template<typename AcceptHandler >
void async_accept (asio::ip::tcp::acceptor &tcp_acceptor, AcceptHandler handler)
 Asynchronously accepts a new tcp connection.
template<typename SSLHandshakeHandler >
void async_handshake_server (SSLHandshakeHandler handler)
 Asynchronously performs server-side SSL handshake for a new connection.
template<typename ReadHandler >
void async_read_some (ReadHandler handler)
 Asynchronously reads some data into the connection's read buffer.
template<typename ConstBufferSequence , typename write_handler_t >
void async_write (const ConstBufferSequence &buffers, write_handler_t handler)
 Asynchronously writes data to the connection.
void finish ()
 This function should be called when a server has finished handling the connection.
bool get_ssl_flag () const
 Returns true if the connection is encrypted using SSL.
void set_lifecycle (lifecycle lcycle)
 Sets the lifecycle for the connection.
bool get_keep_alive () const
 Returns true if the connection should be kept alive.
bool is_pipelined () const
 Returns true if the HTTP requests are pipelined.
read_buffer_type & get_read_buffer ()
 Returns the buffer used for reading data from the TCP connection.
void save_read_pos (const char *read_ptr, const char *read_end_ptr)
 Saves a read position bookmark.
void load_read_pos (const char *&read_ptr, const char *&read_end_ptr) const
 Loads a read position bookmark.
asio::ip::tcp::endpoint get_remote_endpoint () const
 Returns an ASIO endpoint for the client connection.
asio::ip::address get_remote_ip () const
 Returns the client's IP address.
unsigned short get_remote_port () const
 Returns the client's port number.
asio::io_service & get_io_service ()
 Returns reference to the io_service used for async operations.
socket_type & get_socket ()
 Returns non-const reference to underlying TCP socket object.
ssl_socket_type & get_ssl_socket ()
 Returns non-const reference to underlying SSL socket object.
asio::io_service::strand & get_strand ()
 Returns the strand that can be used with this connection.
asio::steady_timer & get_timer ()
 Returns the timer that can be used with this connection.

Detailed Description

Represents a single tcp connection.

Member Enumeration Documentation

Data type for the connection's current_lifecycle state.

Constructor & Destructor Documentation

staticlib::pion::tcp_connection::tcp_connection ( asio::io_service &  io_service,
ssl_context_type &  ssl_context,
const bool  ssl_flag_in,
connection_handler  finished_handler_in 
)
inline

Constructor to be used with std::make_shared

Parameters
io_serviceasio service associated with the connection
ssl_contextasio ssl context associated with the connection
ssl_flagif true then the connection will be encrypted using SSL
finished_handlerfunction called when a server has finished handling the connection
staticlib::pion::tcp_connection::tcp_connection ( const tcp_connection &  )

Deleted copy constructor.

virtual staticlib::pion::tcp_connection::~tcp_connection ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

template<typename AcceptHandler >
void staticlib::pion::tcp_connection::async_accept ( asio::ip::tcp::acceptor &  tcp_acceptor,
AcceptHandler  handler 
)
inline

Asynchronously accepts a new tcp connection.

Parameters
tcp_acceptorobject used to accept new connections
handlercalled after a new connection has been accepted
See Also
asio::basic_socket_acceptor::async_accept()
template<typename SSLHandshakeHandler >
void staticlib::pion::tcp_connection::async_handshake_server ( SSLHandshakeHandler  handler)
inline

Asynchronously performs server-side SSL handshake for a new connection.

Parameters
handlercalled after the ssl handshake has completed
See Also
asio::ssl::stream::async_handshake()
template<typename ReadHandler >
void staticlib::pion::tcp_connection::async_read_some ( ReadHandler  handler)
inline

Asynchronously reads some data into the connection's read buffer.

Parameters
handlercalled after the read operation has completed
See Also
asio::basic_stream_socket::async_read_some()
template<typename ConstBufferSequence , typename write_handler_t >
void staticlib::pion::tcp_connection::async_write ( const ConstBufferSequence &  buffers,
write_handler_t  handler 
)
inline

Asynchronously writes data to the connection.

Parameters
buffersone or more buffers containing the data to be written
handlercalled after the data has been written
See Also
asio::async_write()
void staticlib::pion::tcp_connection::cancel ( )
inline

Cancels any asynchronous operations pending on the socket.

void staticlib::pion::tcp_connection::cancel_timer ( )
inline

Cancels timer.

void staticlib::pion::tcp_connection::close ( )
inline

Closes the tcp socket and cancels any pending asynchronous operations.

void staticlib::pion::tcp_connection::finish ( )
inline

This function should be called when a server has finished handling the connection.

asio::io_service& staticlib::pion::tcp_connection::get_io_service ( )
inline

Returns reference to the io_service used for async operations.

Returns
io_service used for async operations
bool staticlib::pion::tcp_connection::get_keep_alive ( ) const
inline

Returns true if the connection should be kept alive.

Returns
read_buffer_type& staticlib::pion::tcp_connection::get_read_buffer ( )
inline

Returns the buffer used for reading data from the TCP connection.

Returns
buffer used for reading data from the TCP connection
asio::ip::tcp::endpoint staticlib::pion::tcp_connection::get_remote_endpoint ( ) const
inline

Returns an ASIO endpoint for the client connection.

Returns
endpoint
asio::ip::address staticlib::pion::tcp_connection::get_remote_ip ( ) const
inline

Returns the client's IP address.

Returns
client's IP address
unsigned short staticlib::pion::tcp_connection::get_remote_port ( ) const
inline

Returns the client's port number.

Returns
client's port number
socket_type& staticlib::pion::tcp_connection::get_socket ( )
inline

Returns non-const reference to underlying TCP socket object.

Returns
underlying TCP socket object
bool staticlib::pion::tcp_connection::get_ssl_flag ( ) const
inline

Returns true if the connection is encrypted using SSL.

Returns
true if the connection is encrypted using SSL
ssl_socket_type& staticlib::pion::tcp_connection::get_ssl_socket ( )
inline

Returns non-const reference to underlying SSL socket object.

Returns
underlying SSL socket object
asio::io_service::strand& staticlib::pion::tcp_connection::get_strand ( )
inline

Returns the strand that can be used with this connection.

Returns
the strand that can be used with this connection
asio::steady_timer& staticlib::pion::tcp_connection::get_timer ( )
inline

Returns the timer that can be used with this connection.

Returns
the timer that can be used with this connection
bool staticlib::pion::tcp_connection::is_open ( ) const
inline

Returns true if the connection is currently open.

Returns
true if the connection is currently open
bool staticlib::pion::tcp_connection::is_pipelined ( ) const
inline

Returns true if the HTTP requests are pipelined.

Returns
true if the HTTP requests are pipelined
void staticlib::pion::tcp_connection::load_read_pos ( const char *&  read_ptr,
const char *&  read_end_ptr 
) const
inline

Loads a read position bookmark.

Parameters
read_ptrpoints to the next character to be consumed in the read_buffer
read_end_ptrpoints to the end of the read_buffer (last byte + 1)
tcp_connection& staticlib::pion::tcp_connection::operator= ( const tcp_connection &  )

Deleted copy assignment operator.

void staticlib::pion::tcp_connection::save_read_pos ( const char *  read_ptr,
const char *  read_end_ptr 
)
inline

Saves a read position bookmark.

Parameters
read_ptrpoints to the next character to be consumed in the read_buffer
read_end_ptrpoints to the end of the read_buffer (last byte + 1)
void staticlib::pion::tcp_connection::set_lifecycle ( lifecycle  lcycle)
inline

Sets the lifecycle for the connection.

Parameters
lcyclelifecycle type name

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