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) {
81 thread_io_service_.reset();
82 tcp_listener_.reset();
91 thread_pool_->checkPausePermissions();
98 thread_pool_->pause();
112 if (!thread_io_service_) {
121 thread_pool_->stop();
124 tcp_listener_.reset();
127 thread_io_service_.reset();
137 return (thread_pool_->isRunning());
146 return (thread_pool_->isStopped());
155 return (thread_pool_->isPaused());
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
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_service 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.
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.
#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.
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
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.
Defines the logger used by the top-level component of kea-lfc.