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