1 | // |
2 | // windows/random_access_handle_service.hpp |
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_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP |
12 | #define BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP |
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 | |
20 | #if defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) \ |
21 | || defined(GENERATING_DOCUMENTATION) |
22 | |
23 | #include <cstddef> |
24 | #include <boost/asio/async_result.hpp> |
25 | #include <boost/asio/detail/cstdint.hpp> |
26 | #include <boost/asio/detail/win_iocp_handle_service.hpp> |
27 | #include <boost/asio/error.hpp> |
28 | #include <boost/asio/io_service.hpp> |
29 | |
30 | #include <boost/asio/detail/push_options.hpp> |
31 | |
32 | namespace boost { |
33 | namespace asio { |
34 | namespace windows { |
35 | |
36 | /// Default service implementation for a random-access handle. |
37 | class random_access_handle_service |
38 | #if defined(GENERATING_DOCUMENTATION) |
39 | : public boost::asio::io_service::service |
40 | #else |
41 | : public boost::asio::detail::service_base<random_access_handle_service> |
42 | #endif |
43 | { |
44 | public: |
45 | #if defined(GENERATING_DOCUMENTATION) |
46 | /// The unique service identifier. |
47 | static boost::asio::io_service::id id; |
48 | #endif |
49 | |
50 | private: |
51 | // The type of the platform-specific implementation. |
52 | typedef detail::win_iocp_handle_service service_impl_type; |
53 | |
54 | public: |
55 | /// The type of a random-access handle implementation. |
56 | #if defined(GENERATING_DOCUMENTATION) |
57 | typedef implementation_defined implementation_type; |
58 | #else |
59 | typedef service_impl_type::implementation_type implementation_type; |
60 | #endif |
61 | |
62 | /// (Deprecated: Use native_handle_type.) The native handle type. |
63 | #if defined(GENERATING_DOCUMENTATION) |
64 | typedef implementation_defined native_type; |
65 | #else |
66 | typedef service_impl_type::native_handle_type native_type; |
67 | #endif |
68 | |
69 | /// The native handle type. |
70 | #if defined(GENERATING_DOCUMENTATION) |
71 | typedef implementation_defined native_handle_type; |
72 | #else |
73 | typedef service_impl_type::native_handle_type native_handle_type; |
74 | #endif |
75 | |
76 | /// Construct a new random-access handle service for the specified io_service. |
77 | explicit random_access_handle_service(boost::asio::io_service& io_service) |
78 | : boost::asio::detail::service_base< |
79 | random_access_handle_service>(io_service), |
80 | service_impl_(io_service) |
81 | { |
82 | } |
83 | |
84 | /// Construct a new random-access handle implementation. |
85 | void construct(implementation_type& impl) |
86 | { |
87 | service_impl_.construct(impl); |
88 | } |
89 | |
90 | #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) |
91 | /// Move-construct a new random-access handle implementation. |
92 | void move_construct(implementation_type& impl, |
93 | implementation_type& other_impl) |
94 | { |
95 | service_impl_.move_construct(impl, other_impl); |
96 | } |
97 | |
98 | /// Move-assign from another random-access handle implementation. |
99 | void move_assign(implementation_type& impl, |
100 | random_access_handle_service& other_service, |
101 | implementation_type& other_impl) |
102 | { |
103 | service_impl_.move_assign(impl, other_service.service_impl_, other_impl); |
104 | } |
105 | #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) |
106 | |
107 | /// Destroy a random-access handle implementation. |
108 | void destroy(implementation_type& impl) |
109 | { |
110 | service_impl_.destroy(impl); |
111 | } |
112 | |
113 | /// Assign an existing native handle to a random-access handle. |
114 | boost::system::error_code assign(implementation_type& impl, |
115 | const native_handle_type& handle, boost::system::error_code& ec) |
116 | { |
117 | return service_impl_.assign(impl, handle, ec); |
118 | } |
119 | |
120 | /// Determine whether the handle is open. |
121 | bool is_open(const implementation_type& impl) const |
122 | { |
123 | return service_impl_.is_open(impl); |
124 | } |
125 | |
126 | /// Close a random-access handle implementation. |
127 | boost::system::error_code close(implementation_type& impl, |
128 | boost::system::error_code& ec) |
129 | { |
130 | return service_impl_.close(impl, ec); |
131 | } |
132 | |
133 | /// (Deprecated: Use native_handle().) Get the native handle implementation. |
134 | native_type native(implementation_type& impl) |
135 | { |
136 | return service_impl_.native_handle(impl); |
137 | } |
138 | |
139 | /// Get the native handle implementation. |
140 | native_handle_type native_handle(implementation_type& impl) |
141 | { |
142 | return service_impl_.native_handle(impl); |
143 | } |
144 | |
145 | /// Cancel all asynchronous operations associated with the handle. |
146 | boost::system::error_code cancel(implementation_type& impl, |
147 | boost::system::error_code& ec) |
148 | { |
149 | return service_impl_.cancel(impl, ec); |
150 | } |
151 | |
152 | /// Write the given data at the specified offset. |
153 | template <typename ConstBufferSequence> |
154 | std::size_t write_some_at(implementation_type& impl, uint64_t offset, |
155 | const ConstBufferSequence& buffers, boost::system::error_code& ec) |
156 | { |
157 | return service_impl_.write_some_at(impl, offset, buffers, ec); |
158 | } |
159 | |
160 | /// Start an asynchronous write at the specified offset. |
161 | template <typename ConstBufferSequence, typename WriteHandler> |
162 | BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, |
163 | void (boost::system::error_code, std::size_t)) |
164 | async_write_some_at(implementation_type& impl, |
165 | uint64_t offset, const ConstBufferSequence& buffers, |
166 | BOOST_ASIO_MOVE_ARG(WriteHandler) handler) |
167 | { |
168 | boost::asio::detail::async_result_init< |
169 | WriteHandler, void (boost::system::error_code, std::size_t)> init( |
170 | BOOST_ASIO_MOVE_CAST(WriteHandler)(handler)); |
171 | |
172 | service_impl_.async_write_some_at(impl, offset, buffers, init.handler); |
173 | |
174 | return init.result.get(); |
175 | } |
176 | |
177 | /// Read some data from the specified offset. |
178 | template <typename MutableBufferSequence> |
179 | std::size_t read_some_at(implementation_type& impl, uint64_t offset, |
180 | const MutableBufferSequence& buffers, boost::system::error_code& ec) |
181 | { |
182 | return service_impl_.read_some_at(impl, offset, buffers, ec); |
183 | } |
184 | |
185 | /// Start an asynchronous read at the specified offset. |
186 | template <typename MutableBufferSequence, typename ReadHandler> |
187 | BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, |
188 | void (boost::system::error_code, std::size_t)) |
189 | async_read_some_at(implementation_type& impl, |
190 | uint64_t offset, const MutableBufferSequence& buffers, |
191 | BOOST_ASIO_MOVE_ARG(ReadHandler) handler) |
192 | { |
193 | boost::asio::detail::async_result_init< |
194 | ReadHandler, void (boost::system::error_code, std::size_t)> init( |
195 | BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)); |
196 | |
197 | service_impl_.async_read_some_at(impl, offset, buffers, init.handler); |
198 | |
199 | return init.result.get(); |
200 | } |
201 | |
202 | private: |
203 | // Destroy all user-defined handler objects owned by the service. |
204 | void shutdown_service() |
205 | { |
206 | service_impl_.shutdown_service(); |
207 | } |
208 | |
209 | // The platform-specific implementation. |
210 | service_impl_type service_impl_; |
211 | }; |
212 | |
213 | } // namespace windows |
214 | } // namespace asio |
215 | } // namespace boost |
216 | |
217 | #include <boost/asio/detail/pop_options.hpp> |
218 | |
219 | #endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) |
220 | // || defined(GENERATING_DOCUMENTATION) |
221 | |
222 | #endif // BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP |
223 | |