Kea 2.7.5
|
Implements a class that listens for, accepts, and manages TCP connections. More...
#include <tcp_listener.h>
Classes | |
struct | IdleTimeout |
Idle connection timeout. More... | |
Public Member Functions | |
TcpListener (const asiolink::IOServicePtr &io_service, const asiolink::IOAddress &server_address, const unsigned short server_port, const asiolink::TlsContextPtr &tls_context, const IdleTimeout &idle_timeout, const TcpConnectionFilterCallback &connection_filter=0) | |
Constructor. | |
virtual | ~TcpListener () |
Virtual destructor. | |
const asiolink::TCPEndpoint & | getEndpoint () const |
Returns reference to the current listener endpoint. | |
long | getIdleTimeout () const |
Returns the idle timeout (in milliseconds). | |
asiolink::IOAddress | getLocalAddress () const |
Returns local address on which server is listening. | |
uint16_t | getLocalPort () const |
Returns local port on which server is listening. | |
void | start () |
Starts accepting new connections. | |
void | stop () |
Stops all active connections and shuts down the service. | |
size_t | usedByRemoteIp (const asiolink::IOAddress &remote_ip, size_t &total_connections) |
Returns the number of connections using a given remote IP address. | |
Protected Member Functions | |
void | accept () |
Creates TcpConnection instance and adds it to the pool of active connections. | |
void | acceptHandler (const boost::system::error_code &ec) |
Callback invoked when the new connection is accepted. | |
virtual TcpConnectionPtr | createConnection (const TcpConnectionAcceptorCallback &acceptor_callback, const TcpConnectionFilterCallback &connection_filter) |
Creates an instance of the TcpConnection . | |
Protected Attributes | |
TcpConnectionAcceptorPtr | acceptor_ |
Acceptor instance. | |
TcpConnectionFilterCallback | connection_filter_ |
Callback invoked during acceptance which may reject connections. | |
TcpConnectionPool | connections_ |
Pool of active connections. | |
boost::scoped_ptr< asiolink::TCPEndpoint > | endpoint_ |
Pointer to the endpoint representing IP address and port on which the service is running. | |
long | idle_timeout_ |
Timeout after which idle connection is closed by the server. | |
asiolink::IOServicePtr | io_service_ |
Pointer to the IO service. | |
asiolink::TlsContextPtr | tls_context_ |
TLS context. | |
Implements a class that listens for, accepts, and manages TCP connections.
Definition at line 28 of file tcp_listener.h.
isc::tcp::TcpListener::TcpListener | ( | const asiolink::IOServicePtr & | io_service, |
const asiolink::IOAddress & | server_address, | ||
const unsigned short | server_port, | ||
const asiolink::TlsContextPtr & | tls_context, | ||
const IdleTimeout & | idle_timeout, | ||
const TcpConnectionFilterCallback & | connection_filter = 0 ) |
Constructor.
This constructor creates new server endpoint using the specified IP address and port. It also validates other specified parameters.
This constructor does not start accepting new connections! To start accepting connections run TcpListener::start.
io_service | IO service to be used by the listener. |
server_address | Address on which the TCP service should run. |
server_port | Port number on which the TCP service should run. |
tls_context | TLS context. |
idle_timeout | Timeout after which an idle TCP connection is |
connection_filter | Callback invoked during connection acceptance that can allow or deny connections based on the remote endpoint. |
TcpListenerError | when any of the specified parameters is invalid. |
Definition at line 17 of file tcp_listener.cc.
References acceptor_, endpoint_, idle_timeout_, and isc_throw.
|
virtual |
Virtual destructor.
Definition at line 48 of file tcp_listener.cc.
References stop().
|
protected |
Creates TcpConnection instance and adds it to the pool of active connections.
The next accepted connection will be handled by this instance.
Definition at line 81 of file tcp_listener.cc.
References acceptHandler(), connection_filter_, connections_, createConnection(), and isc::tcp::TcpConnectionPool::start().
Referenced by acceptHandler(), and start().
|
protected |
Callback invoked when the new connection is accepted.
It calls TcpListener::accept
to create new TcpConnection
instance.
ec | Error code passed to the handler. This is currently ignored. |
Definition at line 92 of file tcp_listener.cc.
References accept().
Referenced by accept().
|
protectedvirtual |
Creates an instance of the TcpConnection
.
This method is virtual so as it can be overridden when customized connections are to be used, e.g. in case of unit testing.
acceptor_callback | Callback invoked when new connection is accepted. |
connection_filter | Callback invoked during acceptance which may allow of deny connections based on their remote address. |
Definition at line 99 of file tcp_listener.cc.
References isc_throw.
Referenced by accept().
const TCPEndpoint & isc::tcp::TcpListener::getEndpoint | ( | ) | const |
Returns reference to the current listener endpoint.
Definition at line 53 of file tcp_listener.cc.
References endpoint_.
Referenced by getLocalAddress(), and getLocalPort().
|
inline |
Returns the idle timeout (in milliseconds).
Definition at line 93 of file tcp_listener.h.
References idle_timeout_.
IOAddress isc::tcp::TcpListener::getLocalAddress | ( | ) | const |
Returns local address on which server is listening.
Definition at line 105 of file tcp_listener.cc.
References getEndpoint().
uint16_t isc::tcp::TcpListener::getLocalPort | ( | ) | const |
Returns local port on which server is listening.
Definition at line 110 of file tcp_listener.cc.
References getEndpoint().
void isc::tcp::TcpListener::start | ( | ) |
Starts accepting new connections.
This method starts accepting and handling new TCP connections on the IP address and port number specified in the constructor.
If the method is invoked successfully, it must not be invoked again until TcpListener::stop is called.
TcpListenerError | if an error occurred. |
Definition at line 58 of file tcp_listener.cc.
References accept(), acceptor_, endpoint_, isc_throw, stop(), and isc::Exception::what().
void isc::tcp::TcpListener::stop | ( | ) |
Stops all active connections and shuts down the service.
Definition at line 75 of file tcp_listener.cc.
References acceptor_, connections_, and isc::tcp::TcpConnectionPool::stopAll().
Referenced by ~TcpListener(), and start().
|
inline |
Returns the number of connections using a given remote IP address.
Used to limit the number of connections when accepting a new one.
remote_ip | The remote IP address. | |
[out] | total_connections | Size of the connection pool. |
Definition at line 104 of file tcp_listener.h.
References connections_, and isc::tcp::TcpConnectionPool::usedByRemoteIp().
|
protected |
Acceptor instance.
Definition at line 145 of file tcp_listener.h.
Referenced by TcpListener(), start(), and stop().
|
protected |
Callback invoked during acceptance which may reject connections.
Definition at line 160 of file tcp_listener.h.
Referenced by accept().
|
protected |
Pool of active connections.
Definition at line 152 of file tcp_listener.h.
Referenced by accept(), stop(), and usedByRemoteIp().
|
protected |
Pointer to the endpoint representing IP address and port on which the service is running.
Definition at line 149 of file tcp_listener.h.
Referenced by TcpListener(), getEndpoint(), and start().
|
protected |
Timeout after which idle connection is closed by the server.
Definition at line 156 of file tcp_listener.h.
Referenced by TcpListener(), and getIdleTimeout().
|
protected |
Pointer to the IO service.
Definition at line 139 of file tcp_listener.h.
|
protected |
TLS context.
Definition at line 142 of file tcp_listener.h.