annotate DEPENDENCIES/generic/include/boost/asio/windows/basic_handle.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // windows/basic_handle.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_BASIC_HANDLE_HPP
Chris@16 12 #define BOOST_ASIO_WINDOWS_BASIC_HANDLE_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_RANDOM_ACCESS_HANDLE) \
Chris@16 21 || defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE) \
Chris@16 22 || defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) \
Chris@16 23 || defined(GENERATING_DOCUMENTATION)
Chris@16 24
Chris@16 25 #include <boost/asio/basic_io_object.hpp>
Chris@16 26 #include <boost/asio/detail/throw_error.hpp>
Chris@16 27 #include <boost/asio/error.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 /// Provides Windows handle functionality.
Chris@16 36 /**
Chris@16 37 * The windows::basic_handle class template provides the ability to wrap a
Chris@16 38 * Windows handle.
Chris@16 39 *
Chris@16 40 * @par Thread Safety
Chris@16 41 * @e Distinct @e objects: Safe.@n
Chris@16 42 * @e Shared @e objects: Unsafe.
Chris@16 43 */
Chris@16 44 template <typename HandleService>
Chris@16 45 class basic_handle
Chris@16 46 : public basic_io_object<HandleService>
Chris@16 47 {
Chris@16 48 public:
Chris@16 49 /// (Deprecated: Use native_handle_type.) The native representation of a
Chris@16 50 /// handle.
Chris@16 51 typedef typename HandleService::native_handle_type native_type;
Chris@16 52
Chris@16 53 /// The native representation of a handle.
Chris@16 54 typedef typename HandleService::native_handle_type native_handle_type;
Chris@16 55
Chris@16 56 /// A basic_handle is always the lowest layer.
Chris@16 57 typedef basic_handle<HandleService> lowest_layer_type;
Chris@16 58
Chris@16 59 /// Construct a basic_handle without opening it.
Chris@16 60 /**
Chris@16 61 * This constructor creates a handle without opening it.
Chris@16 62 *
Chris@16 63 * @param io_service The io_service object that the handle will use to
Chris@16 64 * dispatch handlers for any asynchronous operations performed on the handle.
Chris@16 65 */
Chris@16 66 explicit basic_handle(boost::asio::io_service& io_service)
Chris@16 67 : basic_io_object<HandleService>(io_service)
Chris@16 68 {
Chris@16 69 }
Chris@16 70
Chris@16 71 /// Construct a basic_handle on an existing native handle.
Chris@16 72 /**
Chris@16 73 * This constructor creates a handle object to hold an existing native handle.
Chris@16 74 *
Chris@16 75 * @param io_service The io_service object that the handle will use to
Chris@16 76 * dispatch handlers for any asynchronous operations performed on the handle.
Chris@16 77 *
Chris@16 78 * @param handle A native handle.
Chris@16 79 *
Chris@16 80 * @throws boost::system::system_error Thrown on failure.
Chris@16 81 */
Chris@16 82 basic_handle(boost::asio::io_service& io_service,
Chris@16 83 const native_handle_type& handle)
Chris@16 84 : basic_io_object<HandleService>(io_service)
Chris@16 85 {
Chris@16 86 boost::system::error_code ec;
Chris@16 87 this->get_service().assign(this->get_implementation(), handle, ec);
Chris@16 88 boost::asio::detail::throw_error(ec, "assign");
Chris@16 89 }
Chris@16 90
Chris@16 91 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
Chris@16 92 /// Move-construct a basic_handle from another.
Chris@16 93 /**
Chris@16 94 * This constructor moves a handle from one object to another.
Chris@16 95 *
Chris@16 96 * @param other The other basic_handle object from which the move will occur.
Chris@16 97 *
Chris@16 98 * @note Following the move, the moved-from object is in the same state as if
Chris@16 99 * constructed using the @c basic_handle(io_service&) constructor.
Chris@16 100 */
Chris@16 101 basic_handle(basic_handle&& other)
Chris@16 102 : basic_io_object<HandleService>(
Chris@16 103 BOOST_ASIO_MOVE_CAST(basic_handle)(other))
Chris@16 104 {
Chris@16 105 }
Chris@16 106
Chris@16 107 /// Move-assign a basic_handle from another.
Chris@16 108 /**
Chris@16 109 * This assignment operator moves a handle from one object to another.
Chris@16 110 *
Chris@16 111 * @param other The other basic_handle object from which the move will occur.
Chris@16 112 *
Chris@16 113 * @note Following the move, the moved-from object is in the same state as if
Chris@16 114 * constructed using the @c basic_handle(io_service&) constructor.
Chris@16 115 */
Chris@16 116 basic_handle& operator=(basic_handle&& other)
Chris@16 117 {
Chris@16 118 basic_io_object<HandleService>::operator=(
Chris@16 119 BOOST_ASIO_MOVE_CAST(basic_handle)(other));
Chris@16 120 return *this;
Chris@16 121 }
Chris@16 122 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
Chris@16 123
Chris@16 124 /// Get a reference to the lowest layer.
Chris@16 125 /**
Chris@16 126 * This function returns a reference to the lowest layer in a stack of
Chris@16 127 * layers. Since a basic_handle cannot contain any further layers, it simply
Chris@16 128 * returns a reference to itself.
Chris@16 129 *
Chris@16 130 * @return A reference to the lowest layer in the stack of layers. Ownership
Chris@16 131 * is not transferred to the caller.
Chris@16 132 */
Chris@16 133 lowest_layer_type& lowest_layer()
Chris@16 134 {
Chris@16 135 return *this;
Chris@16 136 }
Chris@16 137
Chris@16 138 /// Get a const reference to the lowest layer.
Chris@16 139 /**
Chris@16 140 * This function returns a const reference to the lowest layer in a stack of
Chris@16 141 * layers. Since a basic_handle cannot contain any further layers, it simply
Chris@16 142 * returns a reference to itself.
Chris@16 143 *
Chris@16 144 * @return A const reference to the lowest layer in the stack of layers.
Chris@16 145 * Ownership is not transferred to the caller.
Chris@16 146 */
Chris@16 147 const lowest_layer_type& lowest_layer() const
Chris@16 148 {
Chris@16 149 return *this;
Chris@16 150 }
Chris@16 151
Chris@16 152 /// Assign an existing native handle to the handle.
Chris@16 153 /*
Chris@16 154 * This function opens the handle to hold an existing native handle.
Chris@16 155 *
Chris@16 156 * @param handle A native handle.
Chris@16 157 *
Chris@16 158 * @throws boost::system::system_error Thrown on failure.
Chris@16 159 */
Chris@16 160 void assign(const native_handle_type& handle)
Chris@16 161 {
Chris@16 162 boost::system::error_code ec;
Chris@16 163 this->get_service().assign(this->get_implementation(), handle, ec);
Chris@16 164 boost::asio::detail::throw_error(ec, "assign");
Chris@16 165 }
Chris@16 166
Chris@16 167 /// Assign an existing native handle to the handle.
Chris@16 168 /*
Chris@16 169 * This function opens the handle to hold an existing native handle.
Chris@16 170 *
Chris@16 171 * @param handle A native handle.
Chris@16 172 *
Chris@16 173 * @param ec Set to indicate what error occurred, if any.
Chris@16 174 */
Chris@16 175 boost::system::error_code assign(const native_handle_type& handle,
Chris@16 176 boost::system::error_code& ec)
Chris@16 177 {
Chris@16 178 return this->get_service().assign(this->get_implementation(), handle, ec);
Chris@16 179 }
Chris@16 180
Chris@16 181 /// Determine whether the handle is open.
Chris@16 182 bool is_open() const
Chris@16 183 {
Chris@16 184 return this->get_service().is_open(this->get_implementation());
Chris@16 185 }
Chris@16 186
Chris@16 187 /// Close the handle.
Chris@16 188 /**
Chris@16 189 * This function is used to close the handle. Any asynchronous read or write
Chris@16 190 * operations will be cancelled immediately, and will complete with the
Chris@16 191 * boost::asio::error::operation_aborted error.
Chris@16 192 *
Chris@16 193 * @throws boost::system::system_error Thrown on failure.
Chris@16 194 */
Chris@16 195 void close()
Chris@16 196 {
Chris@16 197 boost::system::error_code ec;
Chris@16 198 this->get_service().close(this->get_implementation(), ec);
Chris@16 199 boost::asio::detail::throw_error(ec, "close");
Chris@16 200 }
Chris@16 201
Chris@16 202 /// Close the handle.
Chris@16 203 /**
Chris@16 204 * This function is used to close the handle. Any asynchronous read or write
Chris@16 205 * operations will be cancelled immediately, and will complete with the
Chris@16 206 * boost::asio::error::operation_aborted error.
Chris@16 207 *
Chris@16 208 * @param ec Set to indicate what error occurred, if any.
Chris@16 209 */
Chris@16 210 boost::system::error_code close(boost::system::error_code& ec)
Chris@16 211 {
Chris@16 212 return this->get_service().close(this->get_implementation(), ec);
Chris@16 213 }
Chris@16 214
Chris@16 215 /// (Deprecated: Use native_handle().) Get the native handle representation.
Chris@16 216 /**
Chris@16 217 * This function may be used to obtain the underlying representation of the
Chris@16 218 * handle. This is intended to allow access to native handle functionality
Chris@16 219 * that is not otherwise provided.
Chris@16 220 */
Chris@16 221 native_type native()
Chris@16 222 {
Chris@16 223 return this->get_service().native_handle(this->get_implementation());
Chris@16 224 }
Chris@16 225
Chris@16 226 /// Get the native handle representation.
Chris@16 227 /**
Chris@16 228 * This function may be used to obtain the underlying representation of the
Chris@16 229 * handle. This is intended to allow access to native handle functionality
Chris@16 230 * that is not otherwise provided.
Chris@16 231 */
Chris@16 232 native_handle_type native_handle()
Chris@16 233 {
Chris@16 234 return this->get_service().native_handle(this->get_implementation());
Chris@16 235 }
Chris@16 236
Chris@16 237 /// Cancel all asynchronous operations associated with the handle.
Chris@16 238 /**
Chris@16 239 * This function causes all outstanding asynchronous read or write operations
Chris@16 240 * to finish immediately, and the handlers for cancelled operations will be
Chris@16 241 * passed the boost::asio::error::operation_aborted error.
Chris@16 242 *
Chris@16 243 * @throws boost::system::system_error Thrown on failure.
Chris@16 244 */
Chris@16 245 void cancel()
Chris@16 246 {
Chris@16 247 boost::system::error_code ec;
Chris@16 248 this->get_service().cancel(this->get_implementation(), ec);
Chris@16 249 boost::asio::detail::throw_error(ec, "cancel");
Chris@16 250 }
Chris@16 251
Chris@16 252 /// Cancel all asynchronous operations associated with the handle.
Chris@16 253 /**
Chris@16 254 * This function causes all outstanding asynchronous read or write operations
Chris@16 255 * to finish immediately, and the handlers for cancelled operations will be
Chris@16 256 * passed the boost::asio::error::operation_aborted error.
Chris@16 257 *
Chris@16 258 * @param ec Set to indicate what error occurred, if any.
Chris@16 259 */
Chris@16 260 boost::system::error_code cancel(boost::system::error_code& ec)
Chris@16 261 {
Chris@16 262 return this->get_service().cancel(this->get_implementation(), ec);
Chris@16 263 }
Chris@16 264
Chris@16 265 protected:
Chris@16 266 /// Protected destructor to prevent deletion through this type.
Chris@16 267 ~basic_handle()
Chris@16 268 {
Chris@16 269 }
Chris@16 270 };
Chris@16 271
Chris@16 272 } // namespace windows
Chris@16 273 } // namespace asio
Chris@16 274 } // namespace boost
Chris@16 275
Chris@16 276 #include <boost/asio/detail/pop_options.hpp>
Chris@16 277
Chris@16 278 #endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
Chris@16 279 // || defined(BOOST_ASIO_HAS_WINDOWS_STREAM_HANDLE)
Chris@16 280 // || defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
Chris@16 281 // || defined(GENERATING_DOCUMENTATION)
Chris@16 282
Chris@16 283 #endif // BOOST_ASIO_WINDOWS_BASIC_HANDLE_HPP