Kea 2.7.1
io_service.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2024 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#include <config.h>
8
10#include <asiolink/io_service.h>
11
12#include <unistd.h> // for some IPC/network system calls
13#include <netinet/in.h>
14#include <boost/shared_ptr.hpp>
15#include <sys/socket.h>
16
17namespace isc {
18namespace asiolink {
19
25
26private:
27 IOServiceImpl(const IOService& source);
28 IOServiceImpl& operator=(const IOService& source);
29public:
32 io_service_(),
33 work_(new boost::asio::io_service::work(io_service_)) {
34 };
35
37 ~IOServiceImpl() = default;
39
44 void run() {
45 io_service_.run();
46 };
47
55 size_t runOne() {
56 return (static_cast<size_t>(io_service_.run_one()));
57 };
58
65 size_t poll() {
66 return (static_cast<size_t>(io_service_.poll()));
67 };
68
75 size_t pollOne() {
76 return (static_cast<size_t>(io_service_.poll_one()));
77 };
78
82 void stop() {
83 io_service_.stop();
84 }
85
89 bool stopped() const {
90 return (io_service_.stopped());
91 }
92
94 void restart() {
95 io_service_.reset();
96 }
97
100 void stopWork() {
101 work_.reset();
102 }
103
110 boost::asio::io_service& getInternalIOService() {
111 return (io_service_);
112 }
113
117 void post(const std::function<void ()>& callback) {
118 io_service_.post(callback);
119 }
120
121private:
122 boost::asio::io_service io_service_;
123 boost::shared_ptr<boost::asio::io_service::work> work_;
124};
125
127}
128
131
132void
134 io_impl_->run();
135}
136
137size_t
139 return (io_impl_->runOne());
140}
141
142size_t
144 return (io_impl_->poll());
145}
146
147size_t
149 return (io_impl_->pollOne());
150}
151
152void
154 io_impl_->stop();
155}
156
157bool
159 return (io_impl_->stopped());
160}
161
162void
164 io_impl_->restart();
165}
166
167void
169 io_impl_->stopWork();
170}
171
172boost::asio::io_service&
174 return (io_impl_->getInternalIOService());
175}
176
177void
178IOService::post(const std::function<void ()>& callback) {
179 return (io_impl_->post(callback));
180}
181
182void
183IOService::stopAndPoll(bool ignore_errors) {
184 stop();
185 restart();
186 if (ignore_errors) {
187 try {
188 poll();
189 } catch (...) {
190 // Ignore all exceptions.
191 }
192 } else {
193 poll();
194 }
195}
196
197} // namespace asiolink
198} // namespace isc
Defines the logger used by the top-level component of kea-lfc.