Kea 2.2.0
io_service.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2021 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>
10
11#include <unistd.h> // for some IPC/network system calls
12#include <netinet/in.h>
13#include <boost/shared_ptr.hpp>
14#include <sys/socket.h>
15
16namespace isc {
17namespace asiolink {
18
19namespace {
20// A trivial wrapper for std::function. SunStudio doesn't seem to be capable
21// of handling a std::function object if directly passed to
22// io_service::post().
23class CallbackWrapper {
24public:
25
27 CallbackWrapper(const std::function<void()>& callback) :
28 callback_(callback) {}
29
31 void operator()() {
32 callback_();
33 }
34
35private:
36
38 std::function<void()> callback_;
39};
40}
41
43private:
44 IOServiceImpl(const IOService& source);
45 IOServiceImpl& operator=(const IOService& source);
46public:
49 io_service_(),
50 work_(new boost::asio::io_service::work(io_service_)) {
51 };
52
56
61 void run() {
62 io_service_.run();
63 };
64
70 void run_one() {
71 io_service_.run_one();
72 };
73
78 void poll() {
79 io_service_.poll();
80 };
81
85 void stop() {
86 io_service_.stop();
87 }
88
92 bool stopped() const {
93 return (io_service_.stopped());
94 }
95
97 void restart() {
98 io_service_.reset();
99 }
100
103 void stopWork() {
104 work_.reset();
105 }
106
113 boost::asio::io_service& get_io_service() {
114 return (io_service_);
115 }
116
120 void post(const std::function<void ()>& callback) {
121 const CallbackWrapper wrapper(callback);
122 io_service_.post(wrapper);
123 }
124
125private:
126 boost::asio::io_service io_service_;
127 boost::shared_ptr<boost::asio::io_service::work> work_;
128};
129
131}
132
134}
135
136void
138 io_impl_->run();
139}
140
141void
143 io_impl_->run_one();
144}
145
146void
148 io_impl_->poll();
149}
150
151void
153 io_impl_->stop();
154}
155
156bool
158 return (io_impl_->stopped());
159}
160
161void
163 io_impl_->restart();
164}
165
166void
168 io_impl_->stopWork();
169}
170
171boost::asio::io_service&
173 return (io_impl_->get_io_service());
174}
175
176void
177IOService::post(const std::function<void ()>& callback) {
178 return (io_impl_->post(callback));
179}
180
181} // namespace asiolink
182} // namespace isc
Defines the logger used by the top-level component of kea-lfc.