| Kea 3.0.2-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#include <boost/asio/io_context.hpp>
20
21 namespace isc {
22 namespace asiolink {
23
24 class IOServiceImpl;
25 class IOService;
26
28 typedef boost::shared_ptr<IOService> IOServicePtr;
29
32 class IOService {
37
38 private:
39 IOService(const IOService& source);
40 IOService& operator=(const IOService& source);
41 public:
43 IOService();
44
46 ~IOService();
48
53 void run();
54
62 size_t runOne();
63
70 size_t poll();
71
78 size_t pollOne();
79
83 void stop();
84
88 bool stopped() const;
89
91 void restart();
92
95 void stopWork();
96
105 boost::asio::io_context& getInternalIOService();
106
116 void post(const std::function<void ()>& callback);
117
121 void stopAndPoll(bool ignore_errors = true);
122
123 private:
124
126 boost::shared_ptr<IOServiceImpl> io_impl_;
127};
128
129} // namespace asiolink
130} // namespace isc
131
132#endif // ASIOLINK_IO_SERVICE_H
isc::asiolink::IOServiceImpl
Definition io_service.cc:20
isc::asiolink::IOService
The IOService class is a wrapper for the ASIO io_context class.
Definition io_service.h:32
isc::asiolink::IOService::~IOService
~IOService()
The destructor.
Definition io_service.cc:129
isc::asiolink::IOService::run
void run()
Start the underlying event loop.
Definition io_service.cc:133
isc::asiolink::IOService::pollOne
size_t pollOne()
Run the underlying event loop for a ready events.
Definition io_service.cc:148
isc::asiolink::IOService::IOService
IOService()
The constructor.
Definition io_service.cc:126
isc::asiolink::IOService::getInternalIOService
boost::asio::io_context & getInternalIOService()
Return the native io_context object used in this wrapper.
Definition io_service.cc:173
isc::asiolink::IOService::runOne
size_t runOne()
Run the underlying event loop for a single event.
Definition io_service.cc:138
isc::asiolink::IOService::stopAndPoll
void stopAndPoll(bool ignore_errors=true)
Stop and poll to handle all registered events.
Definition io_service.cc:183
isc::asiolink::IOService::stop
void stop()
Stop the underlying event loop.
Definition io_service.cc:153
isc::asiolink::IOService::restart
void restart()
Restarts the IOService in preparation for a subsequent run() invocation.
Definition io_service.cc:163
isc::asiolink::IOService::stopped
bool stopped() const
Indicates if the IOService has been stopped.
Definition io_service.cc:158
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:168
isc::asiolink::IOService::poll
size_t poll()
Run the underlying event loop for a ready events.
Definition io_service.cc:143
isc::asiolink::IOService::post
void post(const std::function< void()> &callback)
Post a callback to the end of the queue.
Definition io_service.cc:178
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:28
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148