Kea: isc::tcp::TcpConnectionPool Class Reference

| Kea 3.2.0-git

isc::tcp::TcpConnectionPool Class Reference

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.

## Detailed Description

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.

## Member Function Documentation

## ◆ shutdown()

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).

Note
  if the TLS connection stalls e.g. the peer does not try I/O on it the connection has to be explicitly stopped.

Parameters

  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_.

Here is the call graph for this function:

## ◆ start()

void isc::tcp::TcpConnectionPool::start | ( | const TcpConnectionPtr & | connection | ) |

Start new connection.

The connection is inserted to the pool and the TcpConnection::asyncAccept is invoked.

Parameters

  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_.

Here is the call graph for this function:

## ◆ stop()

void isc::tcp::TcpConnectionPool::stop | ( | const TcpConnectionPtr & | connection | ) |

Removes a connection from the pool and stops it.

Parameters

  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_.

Here is the call graph for this function:

## ◆ stopAll()

void isc::tcp::TcpConnectionPool::stopAll | ( |  | ) |

Stops all connections and removes them from the pool.

Note
  This function is not thread-safe so should be called when the thread pool is stopped.

Definition at line 78 of file tcp_connection_pool.cc.

References isc::util::MultiThreadingMgr::instance(), mutex_, and stopAllInternal().

Here is the call graph for this function:

## ◆ stopAllInternal()

void isc::tcp::TcpConnectionPool::stopAllInternal | ( |  | ) |
| 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().

## ◆ usedByRemoteIp()

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.

Parameters

  | remote_ip | The remote IP address.
  [out] | total_connections | Size of the connection pool.

Returns
  The number of connections using a given remote IP address.

Definition at line 99 of file tcp_connection_pool.cc.

References isc::util::MultiThreadingMgr::instance(), mutex_, and usedByRemoteIpInternal().

Here is the call graph for this function:

## ◆ usedByRemoteIpInternal()

size_t isc::tcp::TcpConnectionPool::usedByRemoteIpInternal | ( | const asiolink::IOAddress & | remote_ip,
|  | size_t & | total_connections )
| 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.

Parameters

  | remote_ip | The remote IP address.
  [out] | total_connections | Size of the connection pool.

Returns
  The number of connections using a given remote IP address.

Definition at line 110 of file tcp_connection_pool.cc.

References connections_, and isc::tcp::TcpConnection::NO_ENDPOINT().

Referenced by usedByRemoteIp().

Here is the call graph for this function:

## Member Data Documentation

## ◆ connections_

TcpConnectionList isc::tcp::TcpConnectionPool::connections_
| protected

Set of connections.

Definition at line 104 of file tcp_connection_pool.h.

Referenced by shutdown(), start(), stop(), stopAllInternal(), and usedByRemoteIpInternal().

## ◆ mutex_

std::mutex isc::tcp::TcpConnectionPool::mutex_
| 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().

## ◆ rejected_counter_

std::atomic< uint64_t > isc::tcp::TcpConnectionPool::rejected_counter_
| 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().

## ◆ started_counter_

std::atomic< uint64_t > isc::tcp::TcpConnectionPool::started_counter_
| static

Class/static started (i.e. added to pool) connection counter.

Definition at line 77 of file tcp_connection_pool.h.

Referenced by start().

## ◆ stopped_counter_

std::atomic< uint64_t > isc::tcp::TcpConnectionPool::stopped_counter_
| 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().

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

- tcp_connection_pool.h
- tcp_connection_pool.cc