Chris@16
|
1 //
|
Chris@16
|
2 // impl/io_service.hpp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@101
|
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_ASIO_IMPL_IO_SERVICE_HPP
|
Chris@16
|
12 #define BOOST_ASIO_IMPL_IO_SERVICE_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
15 # pragma once
|
Chris@16
|
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/asio/detail/handler_type_requirements.hpp>
|
Chris@16
|
19 #include <boost/asio/detail/service_registry.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 namespace boost {
|
Chris@16
|
24 namespace asio {
|
Chris@16
|
25
|
Chris@16
|
26 template <typename Service>
|
Chris@16
|
27 inline Service& use_service(io_service& ios)
|
Chris@16
|
28 {
|
Chris@16
|
29 // Check that Service meets the necessary type requirements.
|
Chris@16
|
30 (void)static_cast<io_service::service*>(static_cast<Service*>(0));
|
Chris@16
|
31 (void)static_cast<const io_service::id*>(&Service::id);
|
Chris@16
|
32
|
Chris@16
|
33 return ios.service_registry_->template use_service<Service>();
|
Chris@16
|
34 }
|
Chris@16
|
35
|
Chris@16
|
36 template <>
|
Chris@16
|
37 inline detail::io_service_impl& use_service<detail::io_service_impl>(
|
Chris@16
|
38 io_service& ios)
|
Chris@16
|
39 {
|
Chris@16
|
40 return ios.impl_;
|
Chris@16
|
41 }
|
Chris@16
|
42
|
Chris@16
|
43 template <typename Service>
|
Chris@16
|
44 inline void add_service(io_service& ios, Service* svc)
|
Chris@16
|
45 {
|
Chris@16
|
46 // Check that Service meets the necessary type requirements.
|
Chris@16
|
47 (void)static_cast<io_service::service*>(static_cast<Service*>(0));
|
Chris@16
|
48 (void)static_cast<const io_service::id*>(&Service::id);
|
Chris@16
|
49
|
Chris@16
|
50 ios.service_registry_->template add_service<Service>(svc);
|
Chris@16
|
51 }
|
Chris@16
|
52
|
Chris@16
|
53 template <typename Service>
|
Chris@16
|
54 inline bool has_service(io_service& ios)
|
Chris@16
|
55 {
|
Chris@16
|
56 // Check that Service meets the necessary type requirements.
|
Chris@16
|
57 (void)static_cast<io_service::service*>(static_cast<Service*>(0));
|
Chris@16
|
58 (void)static_cast<const io_service::id*>(&Service::id);
|
Chris@16
|
59
|
Chris@16
|
60 return ios.service_registry_->template has_service<Service>();
|
Chris@16
|
61 }
|
Chris@16
|
62
|
Chris@16
|
63 } // namespace asio
|
Chris@16
|
64 } // namespace boost
|
Chris@16
|
65
|
Chris@16
|
66 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
67
|
Chris@16
|
68 #if defined(BOOST_ASIO_HAS_IOCP)
|
Chris@16
|
69 # include <boost/asio/detail/win_iocp_io_service.hpp>
|
Chris@16
|
70 #else
|
Chris@16
|
71 # include <boost/asio/detail/task_io_service.hpp>
|
Chris@16
|
72 #endif
|
Chris@16
|
73
|
Chris@16
|
74 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
75
|
Chris@16
|
76 namespace boost {
|
Chris@16
|
77 namespace asio {
|
Chris@16
|
78
|
Chris@16
|
79 template <typename CompletionHandler>
|
Chris@16
|
80 inline BOOST_ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ())
|
Chris@16
|
81 io_service::dispatch(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler)
|
Chris@16
|
82 {
|
Chris@16
|
83 // If you get an error on the following line it means that your handler does
|
Chris@16
|
84 // not meet the documented type requirements for a CompletionHandler.
|
Chris@16
|
85 BOOST_ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check;
|
Chris@16
|
86
|
Chris@16
|
87 detail::async_result_init<
|
Chris@16
|
88 CompletionHandler, void ()> init(
|
Chris@16
|
89 BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler));
|
Chris@16
|
90
|
Chris@16
|
91 impl_.dispatch(init.handler);
|
Chris@16
|
92
|
Chris@16
|
93 return init.result.get();
|
Chris@16
|
94 }
|
Chris@16
|
95
|
Chris@16
|
96 template <typename CompletionHandler>
|
Chris@16
|
97 inline BOOST_ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ())
|
Chris@16
|
98 io_service::post(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler)
|
Chris@16
|
99 {
|
Chris@16
|
100 // If you get an error on the following line it means that your handler does
|
Chris@16
|
101 // not meet the documented type requirements for a CompletionHandler.
|
Chris@16
|
102 BOOST_ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check;
|
Chris@16
|
103
|
Chris@16
|
104 detail::async_result_init<
|
Chris@16
|
105 CompletionHandler, void ()> init(
|
Chris@16
|
106 BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler));
|
Chris@16
|
107
|
Chris@16
|
108 impl_.post(init.handler);
|
Chris@16
|
109
|
Chris@16
|
110 return init.result.get();
|
Chris@16
|
111 }
|
Chris@16
|
112
|
Chris@16
|
113 template <typename Handler>
|
Chris@16
|
114 #if defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
115 unspecified
|
Chris@16
|
116 #else
|
Chris@16
|
117 inline detail::wrapped_handler<io_service&, Handler>
|
Chris@16
|
118 #endif
|
Chris@16
|
119 io_service::wrap(Handler handler)
|
Chris@16
|
120 {
|
Chris@16
|
121 return detail::wrapped_handler<io_service&, Handler>(*this, handler);
|
Chris@16
|
122 }
|
Chris@16
|
123
|
Chris@16
|
124 inline io_service::work::work(boost::asio::io_service& io_service)
|
Chris@16
|
125 : io_service_impl_(io_service.impl_)
|
Chris@16
|
126 {
|
Chris@16
|
127 io_service_impl_.work_started();
|
Chris@16
|
128 }
|
Chris@16
|
129
|
Chris@16
|
130 inline io_service::work::work(const work& other)
|
Chris@16
|
131 : io_service_impl_(other.io_service_impl_)
|
Chris@16
|
132 {
|
Chris@16
|
133 io_service_impl_.work_started();
|
Chris@16
|
134 }
|
Chris@16
|
135
|
Chris@16
|
136 inline io_service::work::~work()
|
Chris@16
|
137 {
|
Chris@16
|
138 io_service_impl_.work_finished();
|
Chris@16
|
139 }
|
Chris@16
|
140
|
Chris@16
|
141 inline boost::asio::io_service& io_service::work::get_io_service()
|
Chris@16
|
142 {
|
Chris@16
|
143 return io_service_impl_.get_io_service();
|
Chris@16
|
144 }
|
Chris@16
|
145
|
Chris@16
|
146 inline boost::asio::io_service& io_service::service::get_io_service()
|
Chris@16
|
147 {
|
Chris@16
|
148 return owner_;
|
Chris@16
|
149 }
|
Chris@16
|
150
|
Chris@16
|
151 } // namespace asio
|
Chris@16
|
152 } // namespace boost
|
Chris@16
|
153
|
Chris@16
|
154 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
155
|
Chris@16
|
156 #endif // BOOST_ASIO_IMPL_IO_SERVICE_HPP
|