Kea 2.7.6
|
Pool of active TCP connections. More...
#include <tcp_connection_pool.h>
Public Member Functions | |
void | shutdown (const TcpConnectionPtr &connection) |
Removes a connection from the pool and shutdown it. | |
void | start (const TcpConnectionPtr &connection) |
Start new connection. | |
void | stop (const TcpConnectionPtr &connection) |
Removes a connection from the pool and stops it. | |
void | stopAll () |
Stops all connections and removes them from the pool. | |
size_t | usedByRemoteIp (const asiolink::IOAddress &remote_ip, size_t &total_connections) |
Returns the number of connections using a given remote IP address. | |
Static Public Attributes | |
static std::atomic< uint64_t > | rejected_counter_ |
Class/static rejected (by the accept filter) connection counter. | |
static std::atomic< uint64_t > | started_counter_ |
Class/static started (i.e. added to pool) connection counter. | |
static std::atomic< uint64_t > | stopped_counter_ |
Class/static stopped (i.e. removed from pool) connection counter. | |
Protected Member Functions | |
void | stopAllInternal () |
Stops all connections and removes them from the pool. | |
size_t | usedByRemoteIpInternal (const asiolink::IOAddress &remote_ip, size_t &total_connections) |
Returns the number of connections using a given remote IP address. | |
Protected Attributes | |
TcpConnectionList | connections_ |
Set of connections. | |
std::mutex | mutex_ |
Mutex to protect the internal state. | |
Pool of active TCP connections.
The TCP server is designed to handle many connections simultaneously. The communication between the client and the server may take long time and the server must be able to react on other events while the communication with the clients is in progress. Thus, the server must track active connections and gracefully close them when needed. An obvious case when the connections must be terminated by the server is when the shutdown signal is received.
This object is a simple container for the server connections which provides means to terminate them on request.
Definition at line 33 of file tcp_connection_pool.h.
void isc::tcp::TcpConnectionPool::shutdown | ( | const TcpConnectionPtr & | connection | ) |
Removes a connection from the pool and shutdown it.
Shutdown is specific to TLS and is a first part of graceful close (note it is NOT the same as TCP shutdown system call).
connection | Pointer to the connection. |
Definition at line 60 of file tcp_connection_pool.cc.
References connections_, isc::util::MultiThreadingMgr::instance(), mutex_, and stopped_counter_.
Referenced by isc::tcp::TcpConnection::shutdownConnection().
void isc::tcp::TcpConnectionPool::start | ( | const TcpConnectionPtr & | connection | ) |
Start new connection.
The connection is inserted to the pool and the TcpConnection::asyncAccept is invoked.
connection | Pointer to the new connection. |
Definition at line 28 of file tcp_connection_pool.cc.
References connections_, isc::util::MultiThreadingMgr::instance(), mutex_, and started_counter_.
Referenced by isc::tcp::TcpListener::accept().
void isc::tcp::TcpConnectionPool::stop | ( | const TcpConnectionPtr & | connection | ) |
Removes a connection from the pool and stops it.
connection | Pointer to the connection. |
Definition at line 42 of file tcp_connection_pool.cc.
References connections_, isc::util::MultiThreadingMgr::instance(), mutex_, and stopped_counter_.
Referenced by isc::tcp::TcpConnection::stopThisConnection().
void isc::tcp::TcpConnectionPool::stopAll | ( | ) |
Stops all connections and removes them from the pool.
Definition at line 78 of file tcp_connection_pool.cc.
References isc::util::MultiThreadingMgr::instance(), mutex_, and stopAllInternal().
Referenced by isc::tcp::TcpListener::stop().
|
protected |
Stops all connections and removes them from the pool.
Must be called from with a thread-safe context.
Definition at line 88 of file tcp_connection_pool.cc.
References connections_, and stopped_counter_.
Referenced by stopAll().
size_t isc::tcp::TcpConnectionPool::usedByRemoteIp | ( | const asiolink::IOAddress & | remote_ip, |
size_t & | total_connections ) |
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 99 of file tcp_connection_pool.cc.
References isc::util::MultiThreadingMgr::instance(), mutex_, and usedByRemoteIpInternal().
Referenced by isc::tcp::TcpListener::usedByRemoteIp().
|
protected |
Returns the number of connections using a given remote IP address.
Used to limit the number of connections when accepting a new one. Must be called from with a thread-safe context.
remote_ip | The remote IP address. | |
[out] | total_connections | Size of the connection pool. |
Definition at line 110 of file tcp_connection_pool.cc.
References connections_, and isc::tcp::TcpConnection::NO_ENDPOINT().
Referenced by usedByRemoteIp().
|
protected |
Set of connections.
Definition at line 104 of file tcp_connection_pool.h.
Referenced by shutdown(), start(), stop(), stopAllInternal(), and usedByRemoteIpInternal().
|
protected |
Mutex to protect the internal state.
Definition at line 107 of file tcp_connection_pool.h.
Referenced by shutdown(), start(), stop(), stopAll(), and usedByRemoteIp().
|
static |
Class/static rejected (by the accept filter) connection counter.
Definition at line 83 of file tcp_connection_pool.h.
Referenced by isc::tcp::TcpConnection::acceptorCallback().
|
static |
Class/static started (i.e. added to pool) connection counter.
Definition at line 77 of file tcp_connection_pool.h.
Referenced by start().
|
static |
Class/static stopped (i.e. removed from pool) connection counter.
Definition at line 80 of file tcp_connection_pool.h.
Referenced by shutdown(), stop(), and stopAllInternal().