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