1 | // |
---|---|
2 | // impl/io_service.ipp |
3 | // ~~~~~~~~~~~~~~~~~~~ |
4 | // |
5 | // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
6 | // |
7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
9 | // |
10 | |
11 | #ifndef BOOST_ASIO_IMPL_IO_SERVICE_IPP |
12 | #define BOOST_ASIO_IMPL_IO_SERVICE_IPP |
13 | |
14 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) |
15 | # pragma once |
16 | #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) |
17 | |
18 | #include <boost/asio/detail/config.hpp> |
19 | #include <boost/asio/io_service.hpp> |
20 | #include <boost/asio/detail/limits.hpp> |
21 | #include <boost/asio/detail/scoped_ptr.hpp> |
22 | #include <boost/asio/detail/service_registry.hpp> |
23 | #include <boost/asio/detail/throw_error.hpp> |
24 | |
25 | #if defined(BOOST_ASIO_HAS_IOCP) |
26 | # include <boost/asio/detail/win_iocp_io_service.hpp> |
27 | #else |
28 | # include <boost/asio/detail/task_io_service.hpp> |
29 | #endif |
30 | |
31 | #include <boost/asio/detail/push_options.hpp> |
32 | |
33 | namespace boost { |
34 | namespace asio { |
35 | |
36 | io_service::io_service() |
37 | : service_registry_(new boost::asio::detail::service_registry( |
38 | *this, static_cast<impl_type*>(0), |
39 | (std::numeric_limits<std::size_t>::max)())), |
40 | impl_(service_registry_->first_service<impl_type>()) |
41 | { |
42 | } |
43 | |
44 | io_service::io_service(std::size_t concurrency_hint) |
45 | : service_registry_(new boost::asio::detail::service_registry( |
46 | *this, static_cast<impl_type*>(0), concurrency_hint)), |
47 | impl_(service_registry_->first_service<impl_type>()) |
48 | { |
49 | } |
50 | |
51 | io_service::~io_service() |
52 | { |
53 | delete service_registry_; |
54 | } |
55 | |
56 | std::size_t io_service::run() |
57 | { |
58 | boost::system::error_code ec; |
59 | std::size_t s = impl_.run(ec); |
60 | boost::asio::detail::throw_error(ec); |
61 | return s; |
62 | } |
63 | |
64 | std::size_t io_service::run(boost::system::error_code& ec) |
65 | { |
66 | return impl_.run(ec); |
67 | } |
68 | |
69 | std::size_t io_service::run_one() |
70 | { |
71 | boost::system::error_code ec; |
72 | std::size_t s = impl_.run_one(ec); |
73 | boost::asio::detail::throw_error(ec); |
74 | return s; |
75 | } |
76 | |
77 | std::size_t io_service::run_one(boost::system::error_code& ec) |
78 | { |
79 | return impl_.run_one(ec); |
80 | } |
81 | |
82 | std::size_t io_service::poll() |
83 | { |
84 | boost::system::error_code ec; |
85 | std::size_t s = impl_.poll(ec); |
86 | boost::asio::detail::throw_error(ec); |
87 | return s; |
88 | } |
89 | |
90 | std::size_t io_service::poll(boost::system::error_code& ec) |
91 | { |
92 | return impl_.poll(ec); |
93 | } |
94 | |
95 | std::size_t io_service::poll_one() |
96 | { |
97 | boost::system::error_code ec; |
98 | std::size_t s = impl_.poll_one(ec); |
99 | boost::asio::detail::throw_error(ec); |
100 | return s; |
101 | } |
102 | |
103 | std::size_t io_service::poll_one(boost::system::error_code& ec) |
104 | { |
105 | return impl_.poll_one(ec); |
106 | } |
107 | |
108 | void io_service::stop() |
109 | { |
110 | impl_.stop(); |
111 | } |
112 | |
113 | bool io_service::stopped() const |
114 | { |
115 | return impl_.stopped(); |
116 | } |
117 | |
118 | void io_service::reset() |
119 | { |
120 | impl_.reset(); |
121 | } |
122 | |
123 | void io_service::notify_fork(boost::asio::io_service::fork_event event) |
124 | { |
125 | service_registry_->notify_fork(event); |
126 | } |
127 | |
128 | io_service::service::service(boost::asio::io_service& owner) |
129 | : owner_(owner), |
130 | next_(0) |
131 | { |
132 | } |
133 | |
134 | io_service::service::~service() |
135 | { |
136 | } |
137 | |
138 | void io_service::service::fork_service(boost::asio::io_service::fork_event) |
139 | { |
140 | } |
141 | |
142 | service_already_exists::service_already_exists() |
143 | : std::logic_error("Service already exists.") |
144 | { |
145 | } |
146 | |
147 | invalid_service_owner::invalid_service_owner() |
148 | : std::logic_error("Invalid service owner.") |
149 | { |
150 | } |
151 | |
152 | } // namespace asio |
153 | } // namespace boost |
154 | |
155 | #include <boost/asio/detail/pop_options.hpp> |
156 | |
157 | #endif // BOOST_ASIO_IMPL_IO_SERVICE_IPP |
158 |