2 // windows/random_access_handle_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2011 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 ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP
12 #define 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 "asio/detail/config.hpp"
20 #if defined(ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) \
21 || defined(GENERATING_DOCUMENTATION)
24 #include <boost/config.hpp>
25 #include <boost/cstdint.hpp>
26 #include "asio/detail/win_iocp_handle_service.hpp"
27 #include "asio/error.hpp"
28 #include "asio/io_service.hpp"
30 #include "asio/detail/push_options.hpp"
35 /// Default service implementation for a random-access handle.
36 class random_access_handle_service
37 #if defined(GENERATING_DOCUMENTATION)
38 : public asio::io_service::service
40 : public asio::detail::service_base<random_access_handle_service>
44 #if defined(GENERATING_DOCUMENTATION)
45 /// The unique service identifier.
46 static asio::io_service::id id;
50 // The type of the platform-specific implementation.
51 typedef detail::win_iocp_handle_service service_impl_type;
54 /// The type of a random-access handle implementation.
55 #if defined(GENERATING_DOCUMENTATION)
56 typedef implementation_defined implementation_type;
58 typedef service_impl_type::implementation_type implementation_type;
61 /// The native handle type.
62 #if defined(GENERATING_DOCUMENTATION)
63 typedef implementation_defined native_type;
65 typedef service_impl_type::native_type native_type;
68 /// Construct a new random-access handle service for the specified io_service.
69 explicit random_access_handle_service(asio::io_service& io_service)
70 : asio::detail::service_base<
71 random_access_handle_service>(io_service),
72 service_impl_(io_service)
76 /// Destroy all user-defined handler objects owned by the service.
77 void shutdown_service()
79 service_impl_.shutdown_service();
82 /// Construct a new random-access handle implementation.
83 void construct(implementation_type& impl)
85 service_impl_.construct(impl);
88 /// Destroy a random-access handle implementation.
89 void destroy(implementation_type& impl)
91 service_impl_.destroy(impl);
94 /// Assign an existing native handle to a random-access handle.
95 asio::error_code assign(implementation_type& impl,
96 const native_type& native_handle, asio::error_code& ec)
98 return service_impl_.assign(impl, native_handle, ec);
101 /// Determine whether the handle is open.
102 bool is_open(const implementation_type& impl) const
104 return service_impl_.is_open(impl);
107 /// Close a random-access handle implementation.
108 asio::error_code close(implementation_type& impl,
109 asio::error_code& ec)
111 return service_impl_.close(impl, ec);
114 /// Get the native handle implementation.
115 native_type native(implementation_type& impl)
117 return service_impl_.native(impl);
120 /// Cancel all asynchronous operations associated with the handle.
121 asio::error_code cancel(implementation_type& impl,
122 asio::error_code& ec)
124 return service_impl_.cancel(impl, ec);
127 /// Write the given data at the specified offset.
128 template <typename ConstBufferSequence>
129 std::size_t write_some_at(implementation_type& impl, boost::uint64_t offset,
130 const ConstBufferSequence& buffers, asio::error_code& ec)
132 return service_impl_.write_some_at(impl, offset, buffers, ec);
135 /// Start an asynchronous write at the specified offset.
136 template <typename ConstBufferSequence, typename WriteHandler>
137 void async_write_some_at(implementation_type& impl, boost::uint64_t offset,
138 const ConstBufferSequence& buffers, WriteHandler handler)
140 service_impl_.async_write_some_at(impl, offset, buffers, handler);
143 /// Read some data from the specified offset.
144 template <typename MutableBufferSequence>
145 std::size_t read_some_at(implementation_type& impl, boost::uint64_t offset,
146 const MutableBufferSequence& buffers, asio::error_code& ec)
148 return service_impl_.read_some_at(impl, offset, buffers, ec);
151 /// Start an asynchronous read at the specified offset.
152 template <typename MutableBufferSequence, typename ReadHandler>
153 void async_read_some_at(implementation_type& impl, boost::uint64_t offset,
154 const MutableBufferSequence& buffers, ReadHandler handler)
156 service_impl_.async_read_some_at(impl, offset, buffers, handler);
160 // The platform-specific implementation.
161 service_impl_type service_impl_;
164 } // namespace windows
167 #include "asio/detail/pop_options.hpp"
169 #endif // defined(ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
170 // || defined(GENERATING_DOCUMENTATION)
172 #endif // ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP