Kea 2.5.8
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
21private:
22 IOServiceImpl(const IOService& source);
23 IOServiceImpl& operator=(const IOService& source);
24public:
27 io_service_(),
28 work_(new boost::asio::io_service::work(io_service_)) {
29 };
30
33 };
35
40 void run() {
41 io_service_.run();
42 };
43
51 size_t runOne() {
52 return (static_cast<size_t>(io_service_.run_one()));
53 };
54
61 size_t poll() {
62 return (static_cast<size_t>(io_service_.poll()));
63 };
64
71 size_t pollOne() {
72 return (static_cast<size_t>(io_service_.poll_one()));
73 };
74
78 void stop() {
79 io_service_.stop();
80 }
81
85 bool stopped() const {
86 return (io_service_.stopped());
87 }
88
90 void restart() {
91 io_service_.reset();
92 }
93
96 void stopWork() {
97 work_.reset();
98 }
99
106 boost::asio::io_service& getInternalIOService() {
107 return (io_service_);
108 }
109
113 void post(const std::function<void ()>& callback) {
114 io_service_.post(callback);
115 }
116
117private:
118 boost::asio::io_service io_service_;
119 boost::shared_ptr<boost::asio::io_service::work> work_;
120};
121
123}
124
126}
127
128void
130 io_impl_->run();
131}
132
133size_t
135 return (io_impl_->runOne());
136}
137
138size_t
140 return (io_impl_->poll());
141}
142
143size_t
145 return (io_impl_->pollOne());
146}
147
148void
150 io_impl_->stop();
151}
152
153bool
155 return (io_impl_->stopped());
156}
157
158void
160 io_impl_->restart();
161}
162
163void
165 io_impl_->stopWork();
166}
167
168boost::asio::io_service&
170 return (io_impl_->getInternalIOService());
171}
172
173void
174IOService::post(const std::function<void ()>& callback) {
175 return (io_impl_->post(callback));
176}
177
178} // namespace asiolink
179} // namespace isc
Defines the logger used by the top-level component of kea-lfc.