#include <TCPConnection.hpp>
Definition at line 39 of file TCPConnection.hpp.
Public Types | |
typedef boost::function1< void, boost::shared_ptr< TCPConnection > > | ConnectionHandler |
data type for a function that handles TCP connection objects | |
typedef boost::array< char, READ_BUFFER_SIZE > | ReadBuffer |
data type for an I/O read buffer | |
typedef boost::asio::ip::tcp::socket | Socket |
data type for a socket connection | |
typedef Socket | SSLSocket |
typedef int | SSLContext |
LIFECYCLE_CLOSE | |
LIFECYCLE_KEEPALIVE | |
LIFECYCLE_PIPELINED | |
READ_BUFFER_SIZE = 8192 | |
enum | LifecycleType { LIFECYCLE_CLOSE, LIFECYCLE_KEEPALIVE, LIFECYCLE_PIPELINED } |
data type for the connection's lifecycle state | |
enum | { READ_BUFFER_SIZE = 8192 } |
size of the read buffer | |
Public Member Functions | |
TCPConnection (boost::asio::io_service &io_service, const bool ssl_flag=false) | |
TCPConnection (boost::asio::io_service &io_service, SSLContext &ssl_context) | |
bool | is_open (void) const |
returns true if the connection is currently open | |
void | close (void) |
closes the tcp socket and cancels any pending asynchronous operations | |
virtual | ~TCPConnection () |
virtual destructor | |
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 (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 WriteHandler> | |
void | async_write (const ConstBufferSequence &buffers, WriteHandler handler) |
template<typename ConstBufferSequence> | |
std::size_t | write (const ConstBufferSequence &buffers, boost::system::error_code &ec) |
void | finish (void) |
bool | getSSLFlag (void) const |
returns true if the connection is encrypted using SSL | |
void | setLifecycle (LifecycleType t) |
sets the lifecycle type for the connection | |
LifecycleType | getLifecycle (void) const |
returns the lifecycle type for the connection | |
bool | getKeepAlive (void) const |
returns true if the connection should be kept alive | |
bool | getPipelined (void) const |
returns true if the HTTP requests are pipelined | |
ReadBuffer & | getReadBuffer (void) |
returns the buffer used for reading data from the TCP connection | |
void | saveReadPosition (const char *read_ptr, const char *read_end_ptr) |
void | loadReadPosition (const char *&read_ptr, const char *&read_end_ptr) const |
boost::asio::ip::tcp::endpoint | getRemoteEndpoint (void) const |
returns an ASIO endpoint for the client connection | |
boost::asio::ip::address | getRemoteIp (void) const |
returns the client's IP address | |
unsigned short | getRemotePort (void) const |
returns the client's port number | |
boost::asio::io_service & | getIOService (void) |
returns reference to the io_service used for async operations | |
Socket & | getSocket (void) |
returns non-const reference to underlying TCP socket object | |
SSLSocket & | getSSLSocket (void) |
returns non-const reference to underlying SSL socket object | |
const Socket & | getSocket (void) const |
returns const reference to underlying TCP socket object | |
const SSLSocket & | getSSLSocket (void) const |
returns const reference to underlying SSL socket object | |
Static Public Member Functions | |
static boost::shared_ptr< TCPConnection > | create (boost::asio::io_service &io_service, SSLContext &ssl_context, const bool ssl_flag, ConnectionHandler finished_handler) |
Protected Member Functions | |
TCPConnection (boost::asio::io_service &io_service, SSLContext &ssl_context, const bool ssl_flag, ConnectionHandler finished_handler) |
pion::net::TCPConnection::TCPConnection | ( | boost::asio::io_service & | io_service, | |
const bool | ssl_flag = false | |||
) | [inline, explicit] |
creates a new TCPConnection object
io_service | asio service associated with the connection | |
ssl_flag | if true then the connection will be encrypted using SSL |
Definition at line 98 of file TCPConnection.hpp.
References saveReadPosition().
Referenced by create().
pion::net::TCPConnection::TCPConnection | ( | boost::asio::io_service & | io_service, | |
SSLContext & | ssl_context | |||
) | [inline] |
creates a new TCPConnection object for SSL
io_service | asio service associated with the connection | |
ssl_context | asio ssl context associated with the connection |
Definition at line 120 of file TCPConnection.hpp.
References saveReadPosition().
pion::net::TCPConnection::TCPConnection | ( | boost::asio::io_service & | io_service, | |
SSLContext & | ssl_context, | |||
const bool | ssl_flag, | |||
ConnectionHandler | finished_handler | |||
) | [inline, protected] |
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 |
Definition at line 703 of file TCPConnection.hpp.
References saveReadPosition().
boost::system::error_code pion::net::TCPConnection::accept | ( | boost::asio::ip::tcp::acceptor & | tcp_acceptor | ) | [inline] |
accepts a new tcp connection (blocks until established)
tcp_acceptor | object used to accept new connections |
Definition at line 203 of file TCPConnection.hpp.
References getSSLFlag().
Referenced by pion::net::TCPStream::accept().
void pion::net::TCPConnection::async_accept | ( | boost::asio::ip::tcp::acceptor & | tcp_acceptor, | |
AcceptHandler | handler | |||
) | [inline] |
asynchronously accepts a new tcp connection
tcp_acceptor | object used to accept new connections | |
handler | called after a new connection has been accepted |
Definition at line 184 of file TCPConnection.hpp.
References getSSLFlag().
void pion::net::TCPConnection::async_connect | ( | const boost::asio::ip::address & | remote_addr, | |
const unsigned int | remote_port, | |||
ConnectHandler | handler | |||
) | [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 |
Definition at line 245 of file TCPConnection.hpp.
References async_connect().
void pion::net::TCPConnection::async_connect | ( | boost::asio::ip::tcp::endpoint & | tcp_endpoint, | |
ConnectHandler | handler | |||
) | [inline] |
asynchronously connects to a remote endpoint
tcp_endpoint | remote endpoint to connect to | |
handler | called after a new connection has been established |
Definition at line 224 of file TCPConnection.hpp.
References getSSLFlag().
Referenced by async_connect().
void pion::net::TCPConnection::async_handshake_client | ( | SSLHandshakeHandler | handler | ) | [inline] |
asynchronously performs client-side SSL handshake for a new connection
handler | called after the ssl handshake has completed |
Definition at line 333 of file TCPConnection.hpp.
References getSSLFlag().
void pion::net::TCPConnection::async_handshake_server | ( | SSLHandshakeHandler | handler | ) | [inline] |
asynchronously performs server-side SSL handshake for a new connection
handler | called after the ssl handshake has completed |
Definition at line 348 of file TCPConnection.hpp.
References getSSLFlag().
void pion::net::TCPConnection::async_read | ( | const MutableBufferSequence & | buffers, | |
CompletionCondition | completion_condition, | |||
ReadHandler | handler | |||
) | [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 |
Definition at line 497 of file TCPConnection.hpp.
References getSSLFlag().
void pion::net::TCPConnection::async_read | ( | CompletionCondition | completion_condition, | |
ReadHandler | handler | |||
) | [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 |
Definition at line 473 of file TCPConnection.hpp.
References getSSLFlag().
void pion::net::TCPConnection::async_read_some | ( | ReadBufferType | read_buffer, | |
ReadHandler | handler | |||
) | [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 |
Definition at line 415 of file TCPConnection.hpp.
References getSSLFlag().
void pion::net::TCPConnection::async_read_some | ( | ReadHandler | handler | ) | [inline] |
asynchronously reads some data into the connection's read buffer
handler | called after the read operation has completed |
Definition at line 395 of file TCPConnection.hpp.
References getSSLFlag().
void pion::net::TCPConnection::async_write | ( | const ConstBufferSequence & | buffers, | |
WriteHandler | handler | |||
) | [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 |
Definition at line 570 of file TCPConnection.hpp.
References getSSLFlag().
boost::system::error_code pion::net::TCPConnection::connect | ( | const std::string & | remote_server, | |
const unsigned int | remote_port | |||
) | [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 |
Definition at line 298 of file TCPConnection.hpp.
boost::system::error_code pion::net::TCPConnection::connect | ( | const boost::asio::ip::address & | remote_addr, | |
const unsigned int | remote_port | |||
) | [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 |
Definition at line 282 of file TCPConnection.hpp.
References connect().
boost::system::error_code pion::net::TCPConnection::connect | ( | boost::asio::ip::tcp::endpoint & | tcp_endpoint | ) | [inline] |
connects to a remote endpoint (blocks until established)
tcp_endpoint | remote endpoint to connect to |
Definition at line 261 of file TCPConnection.hpp.
References getSSLFlag().
Referenced by pion::net::TCPStream::connect(), and connect().
static boost::shared_ptr<TCPConnection> pion::net::TCPConnection::create | ( | boost::asio::io_service & | io_service, | |
SSLContext & | ssl_context, | |||
const bool | ssl_flag, | |||
ConnectionHandler | finished_handler | |||
) | [inline, static] |
creates new shared TCPConnection 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 |
Definition at line 83 of file TCPConnection.hpp.
References TCPConnection().
void pion::net::TCPConnection::finish | ( | void | ) | [inline] |
This function should be called when a server has finished handling the connection
Definition at line 605 of file TCPConnection.hpp.
Referenced by pion::net::HTTPServer::handleBadRequest(), pion::net::HTTPServer::handleNotFoundRequest(), pion::net::HTTPCookieAuth::handleOk(), pion::net::HTTPCookieAuth::handleRedirection(), pion::net::HTTPServer::handleServerError(), pion::net::HTTPCookieAuth::handleUnauthorized(), and pion::net::HTTPBasicAuth::handleUnauthorized().
boost::system::error_code pion::net::TCPConnection::handshake_client | ( | void | ) | [inline] |
performs client-side SSL handshake for a new connection (blocks until finished)
Definition at line 362 of file TCPConnection.hpp.
References getSSLFlag().
Referenced by pion::net::TCPStream::connect().
boost::system::error_code pion::net::TCPConnection::handshake_server | ( | void | ) | [inline] |
performs server-side SSL handshake for a new connection (blocks until finished)
Definition at line 378 of file TCPConnection.hpp.
References getSSLFlag().
Referenced by pion::net::TCPStream::accept().
void pion::net::TCPConnection::loadReadPosition | ( | const char *& | read_ptr, | |
const char *& | read_end_ptr | |||
) | const [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) |
Definition at line 642 of file TCPConnection.hpp.
Referenced by pion::net::HTTPMessage::receive().
std::size_t pion::net::TCPConnection::read | ( | const MutableBufferSequence & | buffers, | |
CompletionCondition | completion_condition, | |||
boost::system::error_code & | ec | |||
) | [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 |
Definition at line 547 of file TCPConnection.hpp.
References getSSLFlag().
std::size_t pion::net::TCPConnection::read | ( | CompletionCondition | completion_condition, | |
boost::system::error_code & | ec | |||
) | [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 |
Definition at line 522 of file TCPConnection.hpp.
References getSSLFlag().
std::size_t pion::net::TCPConnection::read_some | ( | ReadBufferType | read_buffer, | |
boost::system::error_code & | ec | |||
) | [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 |
Definition at line 452 of file TCPConnection.hpp.
References getSSLFlag().
std::size_t pion::net::TCPConnection::read_some | ( | boost::system::error_code & | ec | ) | [inline] |
reads some data into the connection's read buffer (blocks until finished)
ec | contains error code if the read fails |
Definition at line 433 of file TCPConnection.hpp.
References getSSLFlag().
Referenced by pion::net::HTTPMessage::receive().
void pion::net::TCPConnection::saveReadPosition | ( | const char * | read_ptr, | |
const char * | read_end_ptr | |||
) | [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) |
Definition at line 631 of file TCPConnection.hpp.
Referenced by pion::net::HTTPMessage::receive(), and TCPConnection().
std::size_t pion::net::TCPConnection::write | ( | const ConstBufferSequence & | buffers, | |
boost::system::error_code & | ec | |||
) | [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 |
Definition at line 589 of file TCPConnection.hpp.
References getSSLFlag().
Referenced by pion::net::HTTPMessage::send().