Kea 2.7.5
tcp_listener.h
Go to the documentation of this file.
1// Copyright (C) 2022-2024 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_LISTENER_H
8#define TCP_LISTENER_H
9
10#include <asiolink/io_service.h>
11#include <asiolink/io_address.h>
14#include <boost/scoped_ptr.hpp>
15
16namespace isc {
17namespace tcp {
18
21public:
22 TcpListenerError(const char* file, size_t line, const char* what) :
23 isc::Exception(file, line, what) { }
24};
25
29public:
31 struct IdleTimeout {
35 explicit IdleTimeout(long value)
36 : value_(value) {
37 }
38 long value_;
39 };
40
59 TcpListener(const asiolink::IOServicePtr& io_service,
60 const asiolink::IOAddress& server_address,
61 const unsigned short server_port,
62 const asiolink::TlsContextPtr& tls_context,
63 const IdleTimeout& idle_timeout,
64 const TcpConnectionFilterCallback& connection_filter = 0);
65
67 virtual ~TcpListener();
68
71
81 void start();
82
84 void stop();
85
88
90 uint16_t getLocalPort() const;
91
93 long getIdleTimeout() const {
94 return (idle_timeout_);
95 }
96
104 size_t usedByRemoteIp(const asiolink::IOAddress& remote_ip,
105 size_t& total_connections) {
106 return (connections_.usedByRemoteIp(remote_ip, total_connections));
107 }
108
109protected:
110
115 void accept();
116
123 void acceptHandler(const boost::system::error_code& ec);
124
135 const TcpConnectionAcceptorCallback& acceptor_callback,
136 const TcpConnectionFilterCallback& connection_filter);
137
140
143
146
149 boost::scoped_ptr<asiolink::TCPEndpoint> endpoint_;
150
153
157
161};
162
164typedef boost::shared_ptr<TcpListener> TcpListenerPtr;
165
166} // end of namespace isc::asiolink
167} // end of namespace isc
168
169#endif // TCP_LISTENER_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Pool of active TCP connections.
size_t usedByRemoteIp(const asiolink::IOAddress &remote_ip, size_t &total_connections)
Returns the number of connections using a given remote IP address.
A generic error raised by the TcpListener class.
TcpListenerError(const char *file, size_t line, const char *what)
Implements a class that listens for, accepts, and manages TCP connections.
asiolink::IOServicePtr io_service_
Pointer to the IO service.
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.
asiolink::TlsContextPtr tls_context_
TLS context.
TcpConnectionPool connections_
Pool of active connections.
void start()
Starts accepting new connections.
const asiolink::TCPEndpoint & getEndpoint() const
Returns reference to the current listener endpoint.
long getIdleTimeout() const
Returns the idle timeout (in milliseconds).
long idle_timeout_
Timeout after which idle connection is closed by the server.
TcpConnectionAcceptorPtr acceptor_
Acceptor instance.
uint16_t getLocalPort() const
Returns local port on which server is listening.
virtual ~TcpListener()
Virtual destructor.
asiolink::IOAddress getLocalAddress() const
Returns local address on which server is listening.
void accept()
Creates TcpConnection instance and adds it to the pool of active connections.
virtual TcpConnectionPtr createConnection(const TcpConnectionAcceptorCallback &acceptor_callback, const TcpConnectionFilterCallback &connection_filter)
Creates an instance of the TcpConnection.
size_t usedByRemoteIp(const asiolink::IOAddress &remote_ip, size_t &total_connections)
Returns the number of connections using a given remote IP address.
boost::scoped_ptr< asiolink::TCPEndpoint > endpoint_
Pointer to the endpoint representing IP address and port on which the service is running.
void acceptHandler(const boost::system::error_code &ec)
Callback invoked when the new connection is accepted.
TcpConnectionFilterCallback connection_filter_
Callback invoked during acceptance which may reject connections.
void stop()
Stops all active connections and shuts down the service.
boost::shared_ptr< TcpConnectionAcceptor > TcpConnectionAcceptorPtr
Type of shared pointer to TCP acceptors.
std::function< bool(const boost::asio::ip::tcp::endpoint &) TcpConnectionFilterCallback)
Type of the callback for filtering new connections by ip address.
boost::shared_ptr< TcpConnection > TcpConnectionPtr
Pointer to the TcpConnection.
std::function< void(const boost::system::error_code &) TcpConnectionAcceptorCallback)
Type of the callback for the TCP acceptor used in this library.
boost::shared_ptr< TcpListener > TcpListenerPtr
Pointer to a TcpListener.
Defines the logger used by the top-level component of kea-lfc.
Idle connection timeout.
long value_
Connection idle timeout value specified.
IdleTimeout(long value)
Constructor.