Kea  2.3.2-git
io_service.cc
Go to the documentation of this file.
1 // Copyright (C) 2011-2022 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 
17 namespace isc {
18 namespace asiolink {
19 
21 private:
22  IOServiceImpl(const IOService& source);
23  IOServiceImpl& operator=(const IOService& source);
24 public:
27  io_service_(),
28  work_(new boost::asio::io_service::work(io_service_)) {
29  };
30 
34 
39  void run() {
40  io_service_.run();
41  };
42 
48  void run_one() {
49  io_service_.run_one();
50  };
51 
56  void poll() {
57  io_service_.poll();
58  };
59 
63  void stop() {
64  io_service_.stop();
65  }
66 
70  bool stopped() const {
71  return (io_service_.stopped());
72  }
73 
75  void restart() {
76  io_service_.reset();
77  }
78 
81  void stopWork() {
82  work_.reset();
83  }
84 
91  boost::asio::io_service& get_io_service() {
92  return (io_service_);
93  }
94 
98  void post(const std::function<void ()>& callback) {
99  io_service_.post(callback);
100  }
101 
102 private:
103  boost::asio::io_service io_service_;
104  boost::shared_ptr<boost::asio::io_service::work> work_;
105 };
106 
107 IOService::IOService() : io_impl_(new IOServiceImpl()) {
108 }
109 
111 }
112 
113 void
115  io_impl_->run();
116 }
117 
118 void
120  io_impl_->run_one();
121 }
122 
123 void
125  io_impl_->poll();
126 }
127 
128 void
130  io_impl_->stop();
131 }
132 
133 bool
135  return (io_impl_->stopped());
136 }
137 
138 void
140  io_impl_->restart();
141 }
142 
143 void
145  io_impl_->stopWork();
146 }
147 
148 boost::asio::io_service&
150  return (io_impl_->get_io_service());
151 }
152 
153 void
154 IOService::post(const std::function<void ()>& callback) {
155  return (io_impl_->post(callback));
156 }
157 
158 } // namespace asiolink
159 } // namespace isc
Defines the logger used by the top-level component of kea-lfc.