Kea 1.5.0
io_service.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2017 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 boost::function. SunStudio doesn't seem to be capable
21// of handling a boost::function object if directly passed to
22// io_service::post().
23class CallbackWrapper {
24public:
25 CallbackWrapper(const boost::function<void()>& callback) :
26 callback_(callback)
27 {}
28 void operator()() {
29 callback_();
30 }
31private:
32 boost::function<void()> callback_;
33};
34}
35
37private:
38 IOServiceImpl(const IOService& source);
39 IOServiceImpl& operator=(const IOService& source);
40public:
43 io_service_(),
44 work_(new boost::asio::io_service::work(io_service_))
45 {};
49
54 void run() {
55 io_service_.run();
56 };
57
63 void run_one() {
64 io_service_.run_one();
65 };
66
71 void poll() {
72 io_service_.poll();
73 };
74
78 void stop() { io_service_.stop();} ;
79
82 void stopWork() {
83 work_.reset();
84 }
85
92 boost::asio::io_service& get_io_service() { return io_service_; };
93 void post(const boost::function<void ()>& callback) {
94 const CallbackWrapper wrapper(callback);
95 io_service_.post(wrapper);
96 }
97private:
98 boost::asio::io_service io_service_;
99 boost::shared_ptr<boost::asio::io_service::work> work_;
100};
101
103 io_impl_ = new IOServiceImpl();
104}
105
107 delete io_impl_;
108}
109
110void
112 io_impl_->run();
113}
114
115void
117 io_impl_->run_one();
118}
119
120void
122 io_impl_->poll();
123}
124
125void
127 io_impl_->stop();
128}
129
130void
132 io_impl_->stopWork();
133}
134
135boost::asio::io_service&
137 return (io_impl_->get_io_service());
138}
139
140void
141IOService::post(const boost::function<void ()>& callback) {
142 return (io_impl_->post(callback));
143}
144
145} // namespace asiolink
146} // namespace isc
Defines the logger used by the top-level component of kea-dhcp-ddns.