| Kea 3.0.2-git

tcp_connection_pool.h
Go to the documentation of this file.
1// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef TCP_CONNECTION_POOL_H
8#define TCP_CONNECTION_POOL_H
9
10#include <tcp/tcp_connection.h>
11
12#include <list>
13#include <mutex>
14
15 namespace isc {
16 namespace tcp {
17
19 typedef std::list<TcpConnectionPtr> TcpConnectionList;
20
33 class TcpConnectionPool {
34 public:
35
42 void start(const TcpConnectionPtr& connection);
43
53 void shutdown(const TcpConnectionPtr& connection);
54
58 void stop(const TcpConnectionPtr& connection);
59
64 void stopAll();
65
73 size_t usedByRemoteIp(const asiolink::IOAddress& remote_ip,
74 size_t& total_connections);
75
77 static std::atomic<uint64_t> started_counter_;
78
80 static std::atomic<uint64_t> stopped_counter_;
81
83 static std::atomic<uint64_t> rejected_counter_;
84
85 protected:
86
90 void stopAllInternal();
91
100 size_t usedByRemoteIpInternal(const asiolink::IOAddress& remote_ip,
101 size_t& total_connections);
102
104 TcpConnectionList connections_;
105
107 std::mutex mutex_;
108};
109
110}
111}
112
113#endif
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:45
isc::tcp::TcpConnectionPool
Pool of active TCP connections.
Definition tcp_connection_pool.h:33
isc::tcp::TcpConnectionPool::stopAll
void stopAll()
Stops all connections and removes them from the pool.
Definition tcp_connection_pool.cc:78
isc::tcp::TcpConnectionPool::stop
void stop(const TcpConnectionPtr &connection)
Removes a connection from the pool and stops it.
Definition tcp_connection_pool.cc:42
isc::tcp::TcpConnectionPool::stopAllInternal
void stopAllInternal()
Stops all connections and removes them from the pool.
Definition tcp_connection_pool.cc:88
isc::tcp::TcpConnectionPool::usedByRemoteIp
size_t usedByRemoteIp(const asiolink::IOAddress &remote_ip, size_t &total_connections)
Returns the number of connections using a given remote IP address.
Definition tcp_connection_pool.cc:99
isc::tcp::TcpConnectionPool::rejected_counter_
static std::atomic< uint64_t > rejected_counter_
Class/static rejected (by the accept filter) connection counter.
Definition tcp_connection_pool.h:83
isc::tcp::TcpConnectionPool::usedByRemoteIpInternal
size_t usedByRemoteIpInternal(const asiolink::IOAddress &remote_ip, size_t &total_connections)
Returns the number of connections using a given remote IP address.
Definition tcp_connection_pool.cc:110
isc::tcp::TcpConnectionPool::stopped_counter_
static std::atomic< uint64_t > stopped_counter_
Class/static stopped (i.e. removed from pool) connection counter.
Definition tcp_connection_pool.h:80
isc::tcp::TcpConnectionPool::shutdown
void shutdown(const TcpConnectionPtr &connection)
Removes a connection from the pool and shutdown it.
Definition tcp_connection_pool.cc:60
isc::tcp::TcpConnectionPool::mutex_
std::mutex mutex_
Mutex to protect the internal state.
Definition tcp_connection_pool.h:107
isc::tcp::TcpConnectionPool::start
void start(const TcpConnectionPtr &connection)
Start new connection.
Definition tcp_connection_pool.cc:28
isc::tcp::TcpConnectionPool::started_counter_
static std::atomic< uint64_t > started_counter_
Class/static started (i.e. added to pool) connection counter.
Definition tcp_connection_pool.h:77
isc::tcp::TcpConnectionPool::connections_
TcpConnectionList connections_
Set of connections.
Definition tcp_connection_pool.h:104
isc::tcp
Definition mt_tcp_listener_mgr.cc:23
isc::tcp::TcpConnectionPtr
boost::shared_ptr< TcpConnection > TcpConnectionPtr
Pointer to the TcpConnection.
Definition tcp_connection.h:467
isc::tcp::TcpConnectionList
std::list< TcpConnectionPtr > TcpConnectionList
Type of TCP connection pointer list.
Definition tcp_connection_pool.h:19
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
tcp_connection.h