Kea: io_service.h Source File

| Kea 3.2.0-git

io_service.h
Go to the documentation of this file.
1// Copyright (C) 2011-2025 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 ASIOLINK_IO_SERVICE_H
8#define ASIOLINK_IO_SERVICE_H
9
10#include <boost/version.hpp>
11#include <boost/shared_ptr.hpp>
12#include <functional>
13#include <list>
14
15#if BOOST_VERSION < 106600
16#error "Boost ASIO older than 1.66 are not supported"
17#endif
18
19#ifdef __GNUC__
20#pragma GCC diagnostic push
21#pragma GCC diagnostic ignored "-Woverloaded-virtual"
22#endif
23#include <boost/asio/io_context.hpp>
24#ifdef __GNUC__
25#pragma GCC diagnostic pop
26#endif
27
28namespace isc {
29namespace asiolink {
30
31class IOServiceImpl;
32class IOService;
33
35 typedef boost::shared_ptr<IOService> IOServicePtr;
36
39 class IOService {
44
45private:
46 IOService(const IOService& source);
47 IOService& operator=(const IOService& source);
48public:
50 IOService();
51
53 ~IOService();
55
60 void run();
61
69 size_t runOne();
70
85 size_t runOneFor(size_t wait_time_usecs, bool& timed_out);
86
93 size_t poll();
94
101 size_t pollOne();
102
106 void stop();
107
111 bool stopped() const;
112
114 void restart();
115
118 void stopWork();
119
128 boost::asio::io_context& getInternalIOService();
129
139 void post(const std::function<void ()>& callback);
140
144 void stopAndPoll(bool ignore_errors = true);
145
146private:
147
149 boost::shared_ptr<IOServiceImpl> io_impl_;
150};
151
152} // namespace asiolink
153} // namespace isc
154
155#endif // ASIOLINK_IO_SERVICE_H
isc::asiolink::IOServiceImpl
Definition io_service.cc:24
isc::asiolink::IOService
The IOService class is a wrapper for the ASIO io_context class.
Definition io_service.h:39
isc::asiolink::IOService::~IOService
~IOService()
The destructor.
Definition io_service.cc:153
isc::asiolink::IOService::run
void run()
Start the underlying event loop.
Definition io_service.cc:157
isc::asiolink::IOService::pollOne
size_t pollOne()
Run the underlying event loop for a ready events.
Definition io_service.cc:177
isc::asiolink::IOService::IOService
IOService()
The constructor.
Definition io_service.cc:150
isc::asiolink::IOService::getInternalIOService
boost::asio::io_context & getInternalIOService()
Return the native io_context object used in this wrapper.
Definition io_service.cc:202
isc::asiolink::IOService::runOne
size_t runOne()
Run the underlying event loop for a single event.
Definition io_service.cc:162
isc::asiolink::IOService::stopAndPoll
void stopAndPoll(bool ignore_errors=true)
Stop and poll to handle all registered events.
Definition io_service.cc:212
isc::asiolink::IOService::runOneFor
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.
Definition io_service.cc:167
isc::asiolink::IOService::stop
void stop()
Stop the underlying event loop.
Definition io_service.cc:182
isc::asiolink::IOService::restart
void restart()
Restarts the IOService in preparation for a subsequent run() invocation.
Definition io_service.cc:192
isc::asiolink::IOService::stopped
bool stopped() const
Indicates if the IOService has been stopped.
Definition io_service.cc:187
isc::asiolink::IOService::stopWork
void stopWork()
Removes IO service work object to let it finish running when all handlers have been invoked.
Definition io_service.cc:197
isc::asiolink::IOService::poll
size_t poll()
Run the underlying event loop for a ready events.
Definition io_service.cc:172
isc::asiolink::IOService::post
void post(const std::function< void()> &callback)
Post a callback to the end of the queue.
Definition io_service.cc:207
isc::asiolink
Definition addr_utilities.cc:170
isc::asiolink::IOServicePtr
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Definition io_service.h:35
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18