pion-net
4.0.9
|
#include <TCPConnection.hpp>
Inherits noncopyable.
Classes | |
class | SSLSocket |
Public Types | |
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 | |
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 int | SSLContext |
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) |
TCPConnection: represents a single tcp connection
Definition at line 39 of file TCPConnection.hpp.
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 107 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 129 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 669 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 189 of file TCPConnection.hpp.
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 175 of file TCPConnection.hpp.
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 205 of file TCPConnection.hpp.
Referenced by async_connect().
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 221 of file TCPConnection.hpp.
References 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 304 of file TCPConnection.hpp.
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 319 of file TCPConnection.hpp.
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 444 of file TCPConnection.hpp.
References getSSLFlag().
Referenced by async_read(), and read().
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 468 of file TCPConnection.hpp.
References async_read(), and 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 366 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 386 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 541 of file TCPConnection.hpp.
References getSSLFlag().
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 237 of file TCPConnection.hpp.
Referenced by connect(), and pion::net::TCPStream::connect().
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 253 of file TCPConnection.hpp.
References connect().
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 269 of file TCPConnection.hpp.
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 92 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 576 of file TCPConnection.hpp.
Referenced by pion::net::HTTPServer::handleBadRequest(), pion::net::HTTPServer::handleForbiddenRequest(), pion::net::HTTPServer::handleMethodNotAllowed(), pion::net::HTTPServer::handleNotFoundRequest(), pion::net::HTTPCookieAuth::handleOk(), pion::net::HTTPCookieAuth::handleRedirection(), pion::net::HTTPServer::handleServerError(), pion::net::HTTPBasicAuth::handleUnauthorized(), and pion::net::HTTPCookieAuth::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 333 of file TCPConnection.hpp.
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 349 of file TCPConnection.hpp.
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 613 of file TCPConnection.hpp.
Referenced by pion::net::HTTPMessage::receive().
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 493 of file TCPConnection.hpp.
References async_read(), and getSSLFlag().
Referenced by read().
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 518 of file TCPConnection.hpp.
References getSSLFlag(), and read().
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 404 of file TCPConnection.hpp.
References getSSLFlag().
Referenced by pion::net::HTTPMessage::receive().
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 423 of file TCPConnection.hpp.
References getSSLFlag().
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 602 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 560 of file TCPConnection.hpp.
References getSSLFlag().
Referenced by pion::net::HTTPMessage::send().