# pion::net::TCPServer Class Reference

`#include <TCPServer.hpp>`

Inherited by HelloServer, and pion::net::HTTPServer.

List of all members.

## Detailed Description

TCPServer: a multi-threaded, asynchronous TCP server

Definition at line 31 of file TCPServer.hpp.

## Public Member Functions

virtual | ~TCPServer ()
| default destructor
void | start (void)
| starts listening for new connections
void | stop (bool wait_until_finished=false)
void | join (void)
| the calling thread will sleep until the server has stopped listening for connections
void | setSSLKeyFile (const std::string &pem_key_file)
std::size_t | getConnections (void) const
| returns the number of active tcp connections
unsigned int | getPort (void) const
| returns tcp port number that the server listens for connections on
void | setPort (unsigned int p)
| sets tcp port number that the server listens for connections on
boost::asio::ip::address | getAddress (void) const
| returns IP address that the server listens for connections on
void | setAddress (const boost::asio::ip::address &addr)
| sets IP address that the server listens for connections on
const boost::asio::ip::tcp::endpoint & | getEndpoint (void) const
| returns tcp endpoint that the server listens for connections on
void | setEndpoint (const boost::asio::ip::tcp::endpoint &ep)
| sets tcp endpoint that the server listens for connections on
bool | getSSLFlag (void) const
| returns true if the server uses SSL to encrypt connections
void | setSSLFlag (bool b=true)
| sets value of SSL flag (true if the server uses SSL to encrypt connections)
TCPConnection::SSLContext & | getSSLContext (void)
| returns the SSL context for configuration
bool | isListening (void) const
| returns true if the server is listening for connections
void | setLogger (PionLogger log_ptr)
| sets the logger to be used
PionLogger | getLogger (void)
| returns the logger currently in use

## Protected Member Functions

| TCPServer (const unsigned int tcp_port)
| TCPServer (const boost::asio::ip::tcp::endpoint &endpoint)
| TCPServer (PionScheduler &scheduler, const unsigned int tcp_port=0)
| TCPServer (PionScheduler &scheduler, const boost::asio::ip::tcp::endpoint &endpoint)
virtual void | handleConnection (TCPConnectionPtr &tcp_conn)
virtual void | beforeStarting (void)
| called before the TCP server starts listening for new connections
virtual void | afterStopping (void)
| called after the TCP server has stopped listing for new connections
boost::asio::io_service & | getIOService (void)
| returns an async I/O service used to schedule work

## Protected Attributes

PionLogger | m_logger
| primary logging interface used by this class

## Constructor & Destructor Documentation

pion::net::TCPServer::TCPServer | ( | const unsigned int | tcp_port | ) | `[explicit, protected]`

protected constructor so that only derived objects may be created

Parameters:

  | tcp_port | port number used to listen for new connections (IPv4)

Definition at line 49 of file TCPServer.cpp.

pion::net::TCPServer::TCPServer | ( | const boost::asio::ip::tcp::endpoint & | endpoint | ) | `[explicit, protected]`

protected constructor so that only derived objects may be created

Parameters:

  | endpoint | TCP endpoint used to listen for new connections (see ASIO docs)

pion::net::TCPServer::TCPServer | ( | PionScheduler & | scheduler,
|  | const unsigned int | tcp_port = `0` |
| ) |  |  | `[explicit, protected]`

protected constructor so that only derived objects may be created

Parameters:

  | scheduler | the PionScheduler that will be used to manage worker threads
  | tcp_port | port number used to listen for new connections (IPv4)

Definition at line 25 of file TCPServer.cpp.

pion::net::TCPServer::TCPServer | ( | PionScheduler & | scheduler,
|  | const boost::asio::ip::tcp::endpoint & | endpoint |
| ) |  |  | `[protected]`

protected constructor so that only derived objects may be created

Parameters:

  | scheduler | the PionScheduler that will be used to manage worker threads
  | endpoint | TCP endpoint used to listen for new connections (see ASIO docs)

## Member Function Documentation

virtual void pion::net::TCPServer::handleConnection | ( | TCPConnectionPtr & | tcp_conn | ) | `[inline, protected, virtual]`

handles a new TCP connection; derived classes SHOULD override this since the default behavior does nothing

Parameters:

  | tcp_conn | the new TCP connection to handle

Reimplemented in pion::net::HTTPServer, and HelloServer.

Definition at line 137 of file TCPServer.hpp.

void pion::net::TCPServer::setSSLKeyFile | ( | const std::string & | pem_key_file | ) |

configures server for SSL using a PEM-encoded RSA private key file

Parameters:

  | pem_key_file | name of the file containing a PEM-encoded private key

Definition at line 162 of file TCPServer.cpp.

References setSSLFlag().

void pion::net::TCPServer::stop | ( | bool | wait_until_finished = `false` | ) |

stops listening for new connections

Parameters:

  | wait_until_finished | if true, blocks until all pending connections have closed

Definition at line 115 of file TCPServer.cpp.

References afterStopping(), pion::net::TCPConnection::close(), getPort(), m_logger, pion::PionScheduler::removeActiveUser(), and pion::PionScheduler::sleep().

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

- net/include/pion/net/TCPServer.hpp
- net/src/TCPServer.cpp