pion::net::TCPConnection Class Reference

#include <TCPConnection.hpp>

List of all members.


Detailed Description

TCPConnection: represents a single tcp connection

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
ReadBuffergetReadBuffer (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
SocketgetSocket (void)
 returns non-const reference to underlying TCP socket object
SSLSocketgetSSLSocket (void)
 returns non-const reference to underlying SSL socket object
const SocketgetSocket (void) const
 returns const reference to underlying TCP socket object
const SSLSocketgetSSLSocket (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)


Constructor & Destructor Documentation

pion::net::TCPConnection::TCPConnection ( boost::asio::io_service &  io_service,
const bool  ssl_flag = false 
) [inline, explicit]

creates a new TCPConnection object

Parameters:
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

Parameters:
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())

Parameters:
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().


Member Function Documentation

boost::system::error_code pion::net::TCPConnection::accept ( boost::asio::ip::tcp::acceptor &  tcp_acceptor  )  [inline]

accepts a new tcp connection (blocks until established)

Parameters:
tcp_acceptor object used to accept new connections
Returns:
boost::system::error_code contains error code if the connection fails
See also:
boost::asio::basic_socket_acceptor::accept()

Definition at line 203 of file TCPConnection.hpp.

References getSSLFlag().

Referenced by pion::net::TCPStream::accept().

template<typename AcceptHandler>
void pion::net::TCPConnection::async_accept ( boost::asio::ip::tcp::acceptor &  tcp_acceptor,
AcceptHandler  handler 
) [inline]

asynchronously accepts a new tcp connection

Parameters:
tcp_acceptor object used to accept new connections
handler called after a new connection has been accepted
See also:
boost::asio::basic_socket_acceptor::async_accept()

Definition at line 184 of file TCPConnection.hpp.

References getSSLFlag().

template<typename ConnectHandler>
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

Parameters:
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
See also:
boost::asio::basic_socket_acceptor::async_connect()

Definition at line 245 of file TCPConnection.hpp.

References async_connect().

template<typename ConnectHandler>
void pion::net::TCPConnection::async_connect ( boost::asio::ip::tcp::endpoint &  tcp_endpoint,
ConnectHandler  handler 
) [inline]

asynchronously connects to a remote endpoint

Parameters:
tcp_endpoint remote endpoint to connect to
handler called after a new connection has been established
See also:
boost::asio::basic_socket_acceptor::async_connect()

Definition at line 224 of file TCPConnection.hpp.

References getSSLFlag().

Referenced by async_connect().

template<typename SSLHandshakeHandler>
void pion::net::TCPConnection::async_handshake_client ( SSLHandshakeHandler  handler  )  [inline]

asynchronously performs client-side SSL handshake for a new connection

Parameters:
handler called after the ssl handshake has completed
See also:
boost::asio::ssl::stream::async_handshake()

Definition at line 333 of file TCPConnection.hpp.

References getSSLFlag().

template<typename SSLHandshakeHandler>
void pion::net::TCPConnection::async_handshake_server ( SSLHandshakeHandler  handler  )  [inline]

asynchronously performs server-side SSL handshake for a new connection

Parameters:
handler called after the ssl handshake has completed
See also:
boost::asio::ssl::stream::async_handshake()

Definition at line 348 of file TCPConnection.hpp.

References getSSLFlag().

template<typename MutableBufferSequence, typename CompletionCondition, typename ReadHandler>
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

Parameters:
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
See also:
boost::asio::async_read()

Definition at line 497 of file TCPConnection.hpp.

References getSSLFlag().

template<typename CompletionCondition, typename ReadHandler>
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

Parameters:
completion_condition determines if the read operation is complete
handler called after the read operation has completed
See also:
boost::asio::async_read()

Definition at line 473 of file TCPConnection.hpp.

References getSSLFlag().

template<typename ReadBufferType, typename ReadHandler>
void pion::net::TCPConnection::async_read_some ( ReadBufferType  read_buffer,
ReadHandler  handler 
) [inline]

asynchronously reads some data into the connection's read buffer

Parameters:
read_buffer the buffer to read data into
handler called after the read operation has completed
See also:
boost::asio::basic_stream_socket::async_read_some()

Definition at line 415 of file TCPConnection.hpp.

References getSSLFlag().

template<typename ReadHandler>
void pion::net::TCPConnection::async_read_some ( ReadHandler  handler  )  [inline]

asynchronously reads some data into the connection's read buffer

Parameters:
handler called after the read operation has completed
See also:
boost::asio::basic_stream_socket::async_read_some()

Definition at line 395 of file TCPConnection.hpp.

References getSSLFlag().

template<typename ConstBufferSequence, typename WriteHandler>
void pion::net::TCPConnection::async_write ( const ConstBufferSequence &  buffers,
WriteHandler  handler 
) [inline]

asynchronously writes data to the connection

Parameters:
buffers one or more buffers containing the data to be written
handler called after the data has been written
See also:
boost::asio::async_write()

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

Parameters:
remote_server hostname of the remote server to connect to
remote_port remote port number to connect to
Returns:
boost::system::error_code contains error code if the connection fails
See also:
boost::asio::basic_socket_acceptor::connect()

Definition at line 298 of file TCPConnection.hpp.

References close(), and 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)

Parameters:
remote_addr remote IP address (v4) to connect to
remote_port remote port number to connect to
Returns:
boost::system::error_code contains error code if the connection fails
See also:
boost::asio::basic_socket_acceptor::connect()

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)

Parameters:
tcp_endpoint remote endpoint to connect to
Returns:
boost::system::error_code contains error code if the connection fails
See also:
boost::asio::basic_socket_acceptor::connect()

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

Parameters:
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)

Returns:
boost::system::error_code contains error code if the connection fails
See also:
boost::asio::ssl::stream::handshake()

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)

Returns:
boost::system::error_code contains error code if the connection fails
See also:
boost::asio::ssl::stream::handshake()

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

Parameters:
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().

template<typename MutableBufferSequence, typename CompletionCondition>
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)

Parameters:
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
Returns:
std::size_t number of bytes read
See also:
boost::asio::read()

Definition at line 547 of file TCPConnection.hpp.

References getSSLFlag().

template<typename CompletionCondition>
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)

Parameters:
completion_condition determines if the read operation is complete
ec contains error code if the read fails
Returns:
std::size_t number of bytes read
See also:
boost::asio::read()

Definition at line 522 of file TCPConnection.hpp.

References getSSLFlag().

template<typename ReadBufferType>
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)

Parameters:
read_buffer the buffer to read data into
ec contains error code if the read fails
Returns:
std::size_t number of bytes read
See also:
boost::asio::basic_stream_socket::read_some()

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)

Parameters:
ec contains error code if the read fails
Returns:
std::size_t number of bytes read
See also:
boost::asio::basic_stream_socket::read_some()

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

Parameters:
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().

template<typename ConstBufferSequence>
std::size_t pion::net::TCPConnection::write ( const ConstBufferSequence &  buffers,
boost::system::error_code &  ec 
) [inline]

writes data to the connection (blocks until finished)

Parameters:
buffers one or more buffers containing the data to be written
ec contains error code if the write fails
Returns:
std::size_t number of bytes written
See also:
boost::asio::write()

Definition at line 589 of file TCPConnection.hpp.

References getSSLFlag().

Referenced by pion::net::HTTPMessage::send().


The documentation for this class was generated from the following file:
Generated on Fri Apr 30 14:48:54 2010 for pion-net by  doxygen 1.4.7