]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/windows/basic_object_handle.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / windows / basic_object_handle.hpp
1 //
2 // windows/basic_object_handle.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Copyright (c) 2011 Boris Schaeling (boris@highscore.de)
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 //
11
12 #ifndef BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_HPP
13 #define BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_HPP
14
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 # pragma once
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
19 #include <boost/asio/detail/config.hpp>
20
21 #if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
22
23 #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) \
24 || defined(GENERATING_DOCUMENTATION)
25
26 #include <boost/asio/detail/throw_error.hpp>
27 #include <boost/asio/error.hpp>
28 #include <boost/asio/windows/basic_handle.hpp>
29 #include <boost/asio/windows/object_handle_service.hpp>
30
31 #include <boost/asio/detail/push_options.hpp>
32
33 namespace boost {
34 namespace asio {
35 namespace windows {
36
37 /// Provides object-oriented handle functionality.
38 /**
39 * The windows::basic_object_handle class template provides asynchronous and
40 * blocking object-oriented handle functionality.
41 *
42 * @par Thread Safety
43 * @e Distinct @e objects: Safe.@n
44 * @e Shared @e objects: Unsafe.
45 */
46 template <typename ObjectHandleService = object_handle_service>
47 class basic_object_handle
48 : public basic_handle<ObjectHandleService>
49 {
50 public:
51 /// The native representation of a handle.
52 typedef typename ObjectHandleService::native_handle_type native_handle_type;
53
54 /// Construct a basic_object_handle without opening it.
55 /**
56 * This constructor creates an object handle without opening it.
57 *
58 * @param io_context The io_context object that the object handle will use to
59 * dispatch handlers for any asynchronous operations performed on the handle.
60 */
61 explicit basic_object_handle(boost::asio::io_context& io_context)
62 : basic_handle<ObjectHandleService>(io_context)
63 {
64 }
65
66 /// Construct a basic_object_handle on an existing native handle.
67 /**
68 * This constructor creates an object handle object to hold an existing native
69 * handle.
70 *
71 * @param io_context The io_context object that the object handle will use to
72 * dispatch handlers for any asynchronous operations performed on the handle.
73 *
74 * @param native_handle The new underlying handle implementation.
75 *
76 * @throws boost::system::system_error Thrown on failure.
77 */
78 basic_object_handle(boost::asio::io_context& io_context,
79 const native_handle_type& native_handle)
80 : basic_handle<ObjectHandleService>(io_context, native_handle)
81 {
82 }
83
84 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
85 /// Move-construct a basic_object_handle from another.
86 /**
87 * This constructor moves an object handle from one object to another.
88 *
89 * @param other The other basic_object_handle object from which the move will
90 * occur.
91 *
92 * @note Following the move, the moved-from object is in the same state as if
93 * constructed using the @c basic_object_handle(io_context&) constructor.
94 */
95 basic_object_handle(basic_object_handle&& other)
96 : basic_handle<ObjectHandleService>(
97 BOOST_ASIO_MOVE_CAST(basic_object_handle)(other))
98 {
99 }
100
101 /// Move-assign a basic_object_handle from another.
102 /**
103 * This assignment operator moves an object handle from one object to another.
104 *
105 * @param other The other basic_object_handle object from which the move will
106 * occur.
107 *
108 * @note Following the move, the moved-from object is in the same state as if
109 * constructed using the @c basic_object_handle(io_context&) constructor.
110 */
111 basic_object_handle& operator=(basic_object_handle&& other)
112 {
113 basic_handle<ObjectHandleService>::operator=(
114 BOOST_ASIO_MOVE_CAST(basic_object_handle)(other));
115 return *this;
116 }
117 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
118
119 /// Perform a blocking wait on the object handle.
120 /**
121 * This function is used to wait for the object handle to be set to the
122 * signalled state. This function blocks and does not return until the object
123 * handle has been set to the signalled state.
124 *
125 * @throws boost::system::system_error Thrown on failure.
126 */
127 void wait()
128 {
129 boost::system::error_code ec;
130 this->get_service().wait(this->get_implementation(), ec);
131 boost::asio::detail::throw_error(ec, "wait");
132 }
133
134 /// Perform a blocking wait on the object handle.
135 /**
136 * This function is used to wait for the object handle to be set to the
137 * signalled state. This function blocks and does not return until the object
138 * handle has been set to the signalled state.
139 *
140 * @param ec Set to indicate what error occurred, if any.
141 */
142 void wait(boost::system::error_code& ec)
143 {
144 this->get_service().wait(this->get_implementation(), ec);
145 }
146
147 /// Start an asynchronous wait on the object handle.
148 /**
149 * This function is be used to initiate an asynchronous wait against the
150 * object handle. It always returns immediately.
151 *
152 * @param handler The handler to be called when the object handle is set to
153 * the signalled state. Copies will be made of the handler as required. The
154 * function signature of the handler must be:
155 * @code void handler(
156 * const boost::system::error_code& error // Result of operation.
157 * ); @endcode
158 * Regardless of whether the asynchronous operation completes immediately or
159 * not, the handler will not be invoked from within this function. Invocation
160 * of the handler will be performed in a manner equivalent to using
161 * boost::asio::io_context::post().
162 */
163 template <typename WaitHandler>
164 BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
165 void (boost::system::error_code))
166 async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
167 {
168 return this->get_service().async_wait(this->get_implementation(),
169 BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
170 }
171 };
172
173 } // namespace windows
174 } // namespace asio
175 } // namespace boost
176
177 #include <boost/asio/detail/pop_options.hpp>
178
179 #endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
180 // || defined(GENERATING_DOCUMENTATION)
181
182 #endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
183
184 #endif // BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_HPP