2 // windows/random_access_handle_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP
12 #define BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) \
21 || defined(GENERATING_DOCUMENTATION)
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>
30 #include <boost/asio/detail/push_options.hpp>
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
41 : public boost::asio::detail::service_base<random_access_handle_service>
45 #if defined(GENERATING_DOCUMENTATION)
46 /// The unique service identifier.
47 static boost::asio::io_service::id id;
51 // The type of the platform-specific implementation.
52 typedef detail::win_iocp_handle_service service_impl_type;
55 /// The type of a random-access handle implementation.
56 #if defined(GENERATING_DOCUMENTATION)
57 typedef implementation_defined implementation_type;
59 typedef service_impl_type::implementation_type implementation_type;
62 /// (Deprecated: Use native_handle_type.) The native handle type.
63 #if defined(GENERATING_DOCUMENTATION)
64 typedef implementation_defined native_type;
66 typedef service_impl_type::native_handle_type native_type;
69 /// The native handle type.
70 #if defined(GENERATING_DOCUMENTATION)
71 typedef implementation_defined native_handle_type;
73 typedef service_impl_type::native_handle_type native_handle_type;
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)
84 /// Construct a new random-access handle implementation.
85 void construct(implementation_type& impl)
87 service_impl_.construct(impl);
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)
95 service_impl_.move_construct(impl, other_impl);
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)
103 service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
105 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
107 /// Destroy a random-access handle implementation.
108 void destroy(implementation_type& impl)
110 service_impl_.destroy(impl);
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)
117 return service_impl_.assign(impl, handle, ec);
120 /// Determine whether the handle is open.
121 bool is_open(const implementation_type& impl) const
123 return service_impl_.is_open(impl);
126 /// Close a random-access handle implementation.
127 boost::system::error_code close(implementation_type& impl,
128 boost::system::error_code& ec)
130 return service_impl_.close(impl, ec);
133 /// (Deprecated: Use native_handle().) Get the native handle implementation.
134 native_type native(implementation_type& impl)
136 return service_impl_.native_handle(impl);
139 /// Get the native handle implementation.
140 native_handle_type native_handle(implementation_type& impl)
142 return service_impl_.native_handle(impl);
145 /// Cancel all asynchronous operations associated with the handle.
146 boost::system::error_code cancel(implementation_type& impl,
147 boost::system::error_code& ec)
149 return service_impl_.cancel(impl, ec);
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)
157 return service_impl_.write_some_at(impl, offset, buffers, ec);
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)
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));
172 service_impl_.async_write_some_at(impl, offset, buffers, init.handler);
174 return init.result.get();
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)
182 return service_impl_.read_some_at(impl, offset, buffers, ec);
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)
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));
197 service_impl_.async_read_some_at(impl, offset, buffers, init.handler);
199 return init.result.get();
203 // Destroy all user-defined handler objects owned by the service.
204 void shutdown_service()
206 service_impl_.shutdown_service();
209 // The platform-specific implementation.
210 service_impl_type service_impl_;
213 } // namespace windows
217 #include <boost/asio/detail/pop_options.hpp>
219 #endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
220 // || defined(GENERATING_DOCUMENTATION)
222 #endif // BOOST_ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP