16#include <boost/pointer_cast.hpp>
28 const uint16_t thread_pool_size ,
31 : listener_factory_(listener_factory), address_(address), port_(port),
32 thread_io_service_(), tcp_listener_(), thread_pool_size_(thread_pool_size),
33 thread_pool_(), tls_context_(context), connection_filter_(connection_filter),
49 " when multi-threading is disabled");
59 thread_io_service_.reset(
new IOService());
62 tcp_listener_ = listener_factory_(thread_io_service_,
71 tcp_listener_->start();
78 .arg(thread_pool_size_)
81 .arg(tls_context_ ?
"true" :
"false");
82 }
catch (
const std::exception& ex) {
90 tcp_listener_->stop();
93 if (thread_io_service_) {
94 thread_io_service_->stopAndPoll();
95 thread_io_service_->stop();
102 tcp_listener_.reset();
105 thread_io_service_.reset();
114 thread_pool_->checkPausePermissions();
121 thread_pool_->pause();
135 if (!thread_io_service_) {
144 thread_pool_->stop();
147 tcp_listener_->stop();
149 thread_io_service_->stopAndPoll();
150 thread_io_service_->stop();
153 thread_pool_.reset();
156 tcp_listener_.reset();
159 thread_io_service_.reset();
169 return (thread_pool_->isRunning());
178 return (thread_pool_->isStopped());
187 return (thread_pool_->isPaused());
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
The IOService class is a wrapper for the ASIO io_context class.
Implements a pausable pool of IOService driven threads.
void pause()
Pauses the listener's thread pool.
void start()
Starts running the listener's thread pool.
bool isPaused()
Indicates if the thread pool is paused.
void checkPermissions()
Check if the current thread can perform thread pool state transition.
bool isStopped()
Indicates if the thread pool is stopped.
MtTcpListenerMgr(TcpListenerFactory listener_factory, const asiolink::IOAddress &address, const uint16_t port, const uint16_t thread_pool_size=1, asiolink::TlsContextPtr context=asiolink::TlsContextPtr(), TcpConnectionFilterCallback connection_filter=0)
Constructor.
void resume()
Resumes running the listener's thread pool.
void stop()
Stops the listener's thread pool.
virtual ~MtTcpListenerMgr()
Destructor.
bool isRunning()
Indicates if the thread pool is running.
static MultiThreadingMgr & instance()
Returns a single instance of Multi Threading Manager.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< TlsContext > TlsContextPtr
The type of shared pointers to TlsContext objects.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
std::function< bool(const boost::asio::ip::tcp::endpoint &)> TcpConnectionFilterCallback
Type of the callback for filtering new connections by ip address.
const long TCP_IDLE_CONNECTION_TIMEOUT
Default connection idle timeout in milliseconds.
std::function< TcpListenerPtr(const asiolink::IOServicePtr &io_service, const asiolink::IOAddress &server_address, const unsigned short server_port, const asiolink::TlsContextPtr &tls_context, const TcpListener::IdleTimeout &idle_timeout, const TcpConnectionFilterCallback &connection_filter) > TcpListenerFactory
Defines a factory function for creating TcpListeners.
const isc::log::MessageID MT_TCP_LISTENER_MGR_STARTED
const isc::log::MessageID MT_TCP_LISTENER_MGR_STOPPING
isc::log::Logger tcp_logger("tcp")
Defines the logger used within libkea-tcp library.
const isc::log::MessageID MT_TCP_LISTENER_MGR_STOPPED
Defines the logger used by the top-level component of kea-lfc.