16 #include <boost/pointer_cast.hpp> 28 const uint16_t thread_pool_size ,
31 : listener_factory_(listener_factory),
32 address_(address), port_(port), thread_io_service_(), tcp_listener_(),
33 thread_pool_size_(thread_pool_size), thread_pool_(),
34 tls_context_(context), connection_filter_(connection_filter),
45 if (!MultiThreadingMgr::instance().getMode()) {
47 " when multi-threading is disabled");
57 thread_io_service_.reset(
new IOService());
60 tcp_listener_ = listener_factory_(*thread_io_service_,
69 tcp_listener_->start();
76 .arg(thread_pool_size_)
79 .arg(tls_context_ ?
"true" :
"false");
80 }
catch (
const std::exception& ex) {
88 thread_pool_->checkPausePermissions();
95 thread_pool_->pause();
109 if (!thread_io_service_) {
118 thread_pool_->stop();
121 tcp_listener_.reset();
124 thread_io_service_.reset();
134 return (thread_pool_->isRunning());
143 return (thread_pool_->isStopped());
152 return (thread_pool_->isPaused());
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.
std::function< TcpListenerPtr(asiolink::IOService &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.
bool isPaused()
Indicates if the thread pool is paused.
const long TCP_IDLE_CONNECTION_TIMEOUT
Default connection idle timeout in milliseconds.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
The IOService class is a wrapper for the ASIO io_service class.
boost::shared_ptr< TlsContext > TlsContextPtr
The type of shared pointers to TlsContext objects.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
bool isRunning()
Indicates if the thread pool is running.
const isc::log::MessageID MT_TCP_LISTENER_MGR_STOPPING
A generic exception that is thrown when an unexpected error condition occurs.
void resume()
Resumes running the listener's thread pool.
Defines the logger used by the top-level component of kea-lfc.
virtual ~MtTcpListenerMgr()
Destructor.
A generic exception that is thrown if a function is called in a prohibited way.
const isc::log::MessageID MT_TCP_LISTENER_MGR_STOPPED
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
void stop()
Stops the listener's thread pool.
The IOAddress class represents an IP addresses (version agnostic)
void pause()
Pauses the listener's thread pool.
isc::log::Logger tcp_logger("tcp")
Defines the logger used within libkea-tcp library.
const isc::log::MessageID MT_TCP_LISTENER_MGR_STARTED
void start()
Starts running the listener's thread pool.
void checkPermissions()
Check if the current thread can perform thread pool state transition.
bool isStopped()
Indicates if the thread pool is stopped.
Implements a pausable pool of IOService driven threads.