# pion::tcp::server Class Reference

`#include <server.hpp>`

Inherited by HelloServer, and pion::http::server.

List of all members.

## Public Member Functions

virtual | ~server ()
| 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 | set_ssl_key_file (const std::string &pem_key_file)
std::size_t | get_connections (void) const
| returns the number of active tcp connections
unsigned int | get_port (void) const
| returns tcp port number that the server listens for connections on
void | set_port (unsigned int p)
| sets tcp port number that the server listens for connections on
boost::asio::ip::address | get_address (void) const
| returns IP address that the server listens for connections on
void | set_address (const boost::asio::ip::address &addr)
| sets IP address that the server listens for connections on
const boost::asio::ip::tcp::endpoint & | get_endpoint (void) const
| returns tcp endpoint that the server listens for connections on
void | set_endpoint (const boost::asio::ip::tcp::endpoint &ep)
| sets tcp endpoint that the server listens for connections on
bool | get_ssl_flag (void) const
| returns true if the server uses SSL to encrypt connections
void | set_ssl_flag (bool b=true)
| sets value of SSL flag (true if the server uses SSL to encrypt connections)
connection::ssl_context_type & | get_ssl_context_type (void)
| returns the SSL context for configuration
bool | is_listening (void) const
| returns true if the server is listening for connections
void | set_logger (logger log_ptr)
| sets the logger to be used
logger | get_logger (void)
| returns the logger currently in use
boost::asio::ip::tcp::acceptor & | get_acceptor (void)
| returns mutable reference to the TCP connection acceptor
const boost::asio::ip::tcp::acceptor & | get_acceptor (void) const
| returns const reference to the TCP connection acceptor

## Protected Member Functions

| server (const unsigned int tcp_port)
| server (const boost::asio::ip::tcp::endpoint &endpoint)
| server (scheduler &sched, const unsigned int tcp_port=0)
| server (scheduler &sched, const boost::asio::ip::tcp::endpoint &endpoint)
virtual void | handle_connection (tcp::connection_ptr &tcp_conn)
virtual void | before_starting (void)
| called before the TCP server starts listening for new connections
virtual void | after_stopping (void)
| called after the TCP server has stopped listing for new connections
boost::asio::io_service & | get_io_service (void)
| returns an async I/O service used to schedule work

## Protected Attributes

logger | m_logger
| primary logging interface used by this class

## Detailed Description

tcp::server: a multi-threaded, asynchronous TCP server

Definition at line 32 of file server.hpp.

## Constructor & Destructor Documentation

pion::tcp::server::server | ( | 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)

Reimplemented in pion::http::server.

Definition at line 47 of file tcp_server.cpp.

pion::tcp::server::server | ( | 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)

Reimplemented in pion::http::server.

Definition at line 59 of file tcp_server.cpp.

pion::tcp::server::server | ( | scheduler & | sched,
|  | const unsigned int | tcp_port = `0` |
| ) |  |  | `[explicit, protected]`

protected constructor so that only derived objects may be created

Parameters:

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

Reimplemented in pion::http::server.

Definition at line 23 of file tcp_server.cpp.

pion::tcp::server::server | ( | scheduler & | sched,
|  | const boost::asio::ip::tcp::endpoint & | endpoint |
| ) |  |  | `[protected]`

protected constructor so that only derived objects may be created

Parameters:

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

Reimplemented in pion::http::server.

Definition at line 35 of file tcp_server.cpp.

## Member Function Documentation

virtual void pion::tcp::server::handle_connection | ( | tcp::connection_ptr & | 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::http::server.

Definition at line 144 of file server.hpp.

void pion::tcp::server::set_ssl_key_file | ( | 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 160 of file tcp_server.cpp.

References set_ssl_flag().

void pion::tcp::server::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 113 of file tcp_server.cpp.

References after_stopping(), pion::tcp::connection::close(), get_port(), m_logger, pion::scheduler::remove_active_user(), and pion::scheduler::sleep().

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

- include/pion/tcp/server.hpp
- src/tcp_server.cpp