]> jfr.im git - irc/gameservirc.git/blob - gameserv-2.0/asio/asio/windows/random_access_handle_service.hpp
Added the asio framework to start developing a GameServ server
[irc/gameservirc.git] / gameserv-2.0 / asio / asio / windows / random_access_handle_service.hpp
1 //
2 // windows/random_access_handle_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2011 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 ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP
12 #define 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 "asio/detail/config.hpp"
19
20 #if defined(ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE) \
21 || defined(GENERATING_DOCUMENTATION)
22
23 #include <cstddef>
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"
29
30 #include "asio/detail/push_options.hpp"
31
32 namespace asio {
33 namespace windows {
34
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
39 #else
40 : public asio::detail::service_base<random_access_handle_service>
41 #endif
42 {
43 public:
44 #if defined(GENERATING_DOCUMENTATION)
45 /// The unique service identifier.
46 static asio::io_service::id id;
47 #endif
48
49 private:
50 // The type of the platform-specific implementation.
51 typedef detail::win_iocp_handle_service service_impl_type;
52
53 public:
54 /// The type of a random-access handle implementation.
55 #if defined(GENERATING_DOCUMENTATION)
56 typedef implementation_defined implementation_type;
57 #else
58 typedef service_impl_type::implementation_type implementation_type;
59 #endif
60
61 /// The native handle type.
62 #if defined(GENERATING_DOCUMENTATION)
63 typedef implementation_defined native_type;
64 #else
65 typedef service_impl_type::native_type native_type;
66 #endif
67
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)
73 {
74 }
75
76 /// Destroy all user-defined handler objects owned by the service.
77 void shutdown_service()
78 {
79 service_impl_.shutdown_service();
80 }
81
82 /// Construct a new random-access handle implementation.
83 void construct(implementation_type& impl)
84 {
85 service_impl_.construct(impl);
86 }
87
88 /// Destroy a random-access handle implementation.
89 void destroy(implementation_type& impl)
90 {
91 service_impl_.destroy(impl);
92 }
93
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)
97 {
98 return service_impl_.assign(impl, native_handle, ec);
99 }
100
101 /// Determine whether the handle is open.
102 bool is_open(const implementation_type& impl) const
103 {
104 return service_impl_.is_open(impl);
105 }
106
107 /// Close a random-access handle implementation.
108 asio::error_code close(implementation_type& impl,
109 asio::error_code& ec)
110 {
111 return service_impl_.close(impl, ec);
112 }
113
114 /// Get the native handle implementation.
115 native_type native(implementation_type& impl)
116 {
117 return service_impl_.native(impl);
118 }
119
120 /// Cancel all asynchronous operations associated with the handle.
121 asio::error_code cancel(implementation_type& impl,
122 asio::error_code& ec)
123 {
124 return service_impl_.cancel(impl, ec);
125 }
126
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)
131 {
132 return service_impl_.write_some_at(impl, offset, buffers, ec);
133 }
134
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)
139 {
140 service_impl_.async_write_some_at(impl, offset, buffers, handler);
141 }
142
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)
147 {
148 return service_impl_.read_some_at(impl, offset, buffers, ec);
149 }
150
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)
155 {
156 service_impl_.async_read_some_at(impl, offset, buffers, handler);
157 }
158
159 private:
160 // The platform-specific implementation.
161 service_impl_type service_impl_;
162 };
163
164 } // namespace windows
165 } // namespace asio
166
167 #include "asio/detail/pop_options.hpp"
168
169 #endif // defined(ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
170 // || defined(GENERATING_DOCUMENTATION)
171
172 #endif // ASIO_WINDOWS_RANDOM_ACCESS_HANDLE_SERVICE_HPP