13#include <netinet/in.h>
14#include <boost/shared_ptr.hpp>
15#include <sys/socket.h>
19using namespace std::chrono;
32 IOServiceImpl& operator=(
const IOService& source);
37 work_(boost::asio::make_work_guard(io_service_)) {
60 return (
static_cast<size_t>(io_service_.run_one()));
77 size_t runOneFor(
size_t wait_time_usecs,
bool& timed_out) {
78 size_t cnt = io_service_.run_one_for(microseconds(wait_time_usecs));
79 timed_out = (!cnt && !io_service_.stopped());
90 return (
static_cast<size_t>(io_service_.poll()));
100 return (
static_cast<size_t>(io_service_.poll_one()));
114 return (io_service_.stopped());
119 io_service_.restart();
135 return (io_service_);
141 void post(
const std::function<
void ()>& callback) {
142 boost::asio::post(io_service_, callback);
146 boost::asio::io_context io_service_;
147 boost::asio::executor_work_guard<boost::asio::io_context::executor_type> work_;
163 return (io_impl_->runOne());
168 return (io_impl_->runOneFor(wait_time_usecs, timed_out));
173 return (io_impl_->poll());
178 return (io_impl_->pollOne());
188 return (io_impl_->stopped());
198 io_impl_->stopWork();
201boost::asio::io_context&
203 return (io_impl_->getInternalIOService());
208 return (io_impl_->post(callback));
IOServiceImpl()
The constructor.
size_t runOneFor(size_t wait_time_usecs, bool &timed_out)
Run the underlying event loop for a single event or until a wait time expires.
~IOServiceImpl()=default
The destructor.
boost::asio::io_context & getInternalIOService()
Return the native io_context object used in this wrapper.
void run()
Start the underlying event loop.
void stopWork()
Removes IO service work object to let it finish running when all handlers have been invoked.
size_t poll()
Run the underlying event loop for a ready events.
size_t pollOne()
Run the underlying event loop for a ready events.
void stop()
Stop the underlying event loop.
void restart()
Restarts the IOService in preparation for a subsequent run() invocation.
size_t runOne()
Run the underlying event loop for a single event.
void post(const std::function< void()> &callback)
Post a callback on the IO service.
bool stopped() const
Indicates if the IOService has been stopped.
The IOService class is a wrapper for the ASIO io_context class.
~IOService()
The destructor.
void run()
Start the underlying event loop.
size_t pollOne()
Run the underlying event loop for a ready events.
IOService()
The constructor.
boost::asio::io_context & getInternalIOService()
Return the native io_context object used in this wrapper.
size_t runOne()
Run the underlying event loop for a single event.
void stopAndPoll(bool ignore_errors=true)
Stop and poll to handle all registered events.
size_t runOneFor(size_t wait_time_usecs, bool &timed_out)
Run the underlying event loop for a single event or until a wait time expires.
void stop()
Stop the underlying event loop.
void restart()
Restarts the IOService in preparation for a subsequent run() invocation.
bool stopped() const
Indicates if the IOService has been stopped.
void stopWork()
Removes IO service work object to let it finish running when all handlers have been invoked.
size_t poll()
Run the underlying event loop for a ready events.
void post(const std::function< void()> &callback)
Post a callback to the end of the queue.
Defines the logger used by the top-level component of kea-lfc.