summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/asio/include/asio/posix/basic_descriptor.hpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/asio/include/asio/posix/basic_descriptor.hpp')
-rw-r--r--3rdparty/asio/include/asio/posix/basic_descriptor.hpp274
1 files changed, 200 insertions, 74 deletions
diff --git a/3rdparty/asio/include/asio/posix/basic_descriptor.hpp b/3rdparty/asio/include/asio/posix/basic_descriptor.hpp
index 27db872c338..e7152798a4e 100644
--- a/3rdparty/asio/include/asio/posix/basic_descriptor.hpp
+++ b/3rdparty/asio/include/asio/posix/basic_descriptor.hpp
@@ -2,7 +2,7 @@
// posix/basic_descriptor.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,16 +17,24 @@
#include "asio/detail/config.hpp"
-#if defined(ASIO_ENABLE_OLD_SERVICES)
-
#if defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) \
|| defined(GENERATING_DOCUMENTATION)
-#include "asio/basic_io_object.hpp"
+#include "asio/any_io_executor.hpp"
+#include "asio/async_result.hpp"
+#include "asio/detail/handler_type_requirements.hpp"
+#include "asio/detail/io_object_impl.hpp"
+#include "asio/detail/non_const_lvalue.hpp"
+#include "asio/detail/reactive_descriptor_service.hpp"
#include "asio/detail/throw_error.hpp"
#include "asio/error.hpp"
+#include "asio/execution_context.hpp"
#include "asio/posix/descriptor_base.hpp"
+#if defined(ASIO_HAS_MOVE)
+# include <utility>
+#endif // defined(ASIO_HAS_MOVE)
+
#include "asio/detail/push_options.hpp"
namespace asio {
@@ -41,37 +49,70 @@ namespace posix {
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
-template <typename DescriptorService>
+template <typename Executor = any_io_executor>
class basic_descriptor
- : public basic_io_object<DescriptorService>,
- public descriptor_base
+ : public descriptor_base
{
public:
+ /// The type of the executor associated with the object.
+ typedef Executor executor_type;
+
+ /// Rebinds the descriptor type to another executor.
+ template <typename Executor1>
+ struct rebind_executor
+ {
+ /// The descriptor type when rebound to the specified executor.
+ typedef basic_descriptor<Executor1> other;
+ };
+
/// The native representation of a descriptor.
- typedef typename DescriptorService::native_handle_type native_handle_type;
+#if defined(GENERATING_DOCUMENTATION)
+ typedef implementation_defined native_handle_type;
+#else
+ typedef detail::reactive_descriptor_service::native_handle_type
+ native_handle_type;
+#endif
- /// A basic_descriptor is always the lowest layer.
- typedef basic_descriptor<DescriptorService> lowest_layer_type;
+ /// A descriptor is always the lowest layer.
+ typedef basic_descriptor lowest_layer_type;
- /// Construct a basic_descriptor without opening it.
+ /// Construct a descriptor without opening it.
/**
* This constructor creates a descriptor without opening it.
*
- * @param io_context The io_context object that the descriptor will use to
+ * @param ex The I/O executor that the descriptor will use, by default, to
* dispatch handlers for any asynchronous operations performed on the
* descriptor.
*/
- explicit basic_descriptor(asio::io_context& io_context)
- : basic_io_object<DescriptorService>(io_context)
+ explicit basic_descriptor(const executor_type& ex)
+ : impl_(0, ex)
{
}
- /// Construct a basic_descriptor on an existing native descriptor.
+ /// Construct a descriptor without opening it.
+ /**
+ * This constructor creates a descriptor without opening it.
+ *
+ * @param context An execution context which provides the I/O executor that
+ * the descriptor will use, by default, to dispatch handlers for any
+ * asynchronous operations performed on the descriptor.
+ */
+ template <typename ExecutionContext>
+ explicit basic_descriptor(ExecutionContext& context,
+ typename constraint<
+ is_convertible<ExecutionContext&, execution_context&>::value,
+ defaulted_constraint
+ >::type = defaulted_constraint())
+ : impl_(0, 0, context)
+ {
+ }
+
+ /// Construct a descriptor on an existing native descriptor.
/**
* This constructor creates a descriptor object to hold an existing native
* descriptor.
*
- * @param io_context The io_context object that the descriptor will use to
+ * @param ex The I/O executor that the descriptor will use, by default, to
* dispatch handlers for any asynchronous operations performed on the
* descriptor.
*
@@ -79,55 +120,88 @@ public:
*
* @throws asio::system_error Thrown on failure.
*/
- basic_descriptor(asio::io_context& io_context,
+ basic_descriptor(const executor_type& ex,
const native_handle_type& native_descriptor)
- : basic_io_object<DescriptorService>(io_context)
+ : impl_(0, ex)
+ {
+ asio::error_code ec;
+ impl_.get_service().assign(impl_.get_implementation(),
+ native_descriptor, ec);
+ asio::detail::throw_error(ec, "assign");
+ }
+
+ /// Construct a descriptor on an existing native descriptor.
+ /**
+ * This constructor creates a descriptor object to hold an existing native
+ * descriptor.
+ *
+ * @param context An execution context which provides the I/O executor that
+ * the descriptor will use, by default, to dispatch handlers for any
+ * asynchronous operations performed on the descriptor.
+ *
+ * @param native_descriptor A native descriptor.
+ *
+ * @throws asio::system_error Thrown on failure.
+ */
+ template <typename ExecutionContext>
+ basic_descriptor(ExecutionContext& context,
+ const native_handle_type& native_descriptor,
+ typename constraint<
+ is_convertible<ExecutionContext&, execution_context&>::value
+ >::type = 0)
+ : impl_(0, 0, context)
{
asio::error_code ec;
- this->get_service().assign(this->get_implementation(),
+ impl_.get_service().assign(impl_.get_implementation(),
native_descriptor, ec);
asio::detail::throw_error(ec, "assign");
}
#if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
- /// Move-construct a basic_descriptor from another.
+ /// Move-construct a descriptor from another.
/**
* This constructor moves a descriptor from one object to another.
*
- * @param other The other basic_descriptor object from which the move will
+ * @param other The other descriptor object from which the move will
* occur.
*
* @note Following the move, the moved-from object is in the same state as if
- * constructed using the @c basic_descriptor(io_context&) constructor.
+ * constructed using the @c basic_descriptor(const executor_type&)
+ * constructor.
*/
- basic_descriptor(basic_descriptor&& other)
- : basic_io_object<DescriptorService>(
- ASIO_MOVE_CAST(basic_descriptor)(other))
+ basic_descriptor(basic_descriptor&& other) ASIO_NOEXCEPT
+ : impl_(std::move(other.impl_))
{
}
- /// Move-assign a basic_descriptor from another.
+ /// Move-assign a descriptor from another.
/**
* This assignment operator moves a descriptor from one object to another.
*
- * @param other The other basic_descriptor object from which the move will
+ * @param other The other descriptor object from which the move will
* occur.
*
* @note Following the move, the moved-from object is in the same state as if
- * constructed using the @c basic_descriptor(io_context&) constructor.
+ * constructed using the @c basic_descriptor(const executor_type&)
+ * constructor.
*/
basic_descriptor& operator=(basic_descriptor&& other)
{
- basic_io_object<DescriptorService>::operator=(
- ASIO_MOVE_CAST(basic_descriptor)(other));
+ impl_ = std::move(other.impl_);
return *this;
}
#endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
+ /// Get the executor associated with the object.
+ executor_type get_executor() ASIO_NOEXCEPT
+ {
+ return impl_.get_executor();
+ }
+
/// Get a reference to the lowest layer.
/**
* This function returns a reference to the lowest layer in a stack of
- * layers. Since a basic_descriptor cannot contain any further layers, it
+ * layers. Since a descriptor cannot contain any further layers, it
* simply returns a reference to itself.
*
* @return A reference to the lowest layer in the stack of layers. Ownership
@@ -141,7 +215,7 @@ public:
/// Get a const reference to the lowest layer.
/**
* This function returns a const reference to the lowest layer in a stack of
- * layers. Since a basic_descriptor cannot contain any further layers, it
+ * layers. Since a descriptor cannot contain any further layers, it
* simply returns a reference to itself.
*
* @return A const reference to the lowest layer in the stack of layers.
@@ -163,7 +237,7 @@ public:
void assign(const native_handle_type& native_descriptor)
{
asio::error_code ec;
- this->get_service().assign(this->get_implementation(),
+ impl_.get_service().assign(impl_.get_implementation(),
native_descriptor, ec);
asio::detail::throw_error(ec, "assign");
}
@@ -179,15 +253,15 @@ public:
ASIO_SYNC_OP_VOID assign(const native_handle_type& native_descriptor,
asio::error_code& ec)
{
- this->get_service().assign(
- this->get_implementation(), native_descriptor, ec);
+ impl_.get_service().assign(
+ impl_.get_implementation(), native_descriptor, ec);
ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Determine whether the descriptor is open.
bool is_open() const
{
- return this->get_service().is_open(this->get_implementation());
+ return impl_.get_service().is_open(impl_.get_implementation());
}
/// Close the descriptor.
@@ -202,7 +276,7 @@ public:
void close()
{
asio::error_code ec;
- this->get_service().close(this->get_implementation(), ec);
+ impl_.get_service().close(impl_.get_implementation(), ec);
asio::detail::throw_error(ec, "close");
}
@@ -217,7 +291,7 @@ public:
*/
ASIO_SYNC_OP_VOID close(asio::error_code& ec)
{
- this->get_service().close(this->get_implementation(), ec);
+ impl_.get_service().close(impl_.get_implementation(), ec);
ASIO_SYNC_OP_VOID_RETURN(ec);
}
@@ -229,7 +303,7 @@ public:
*/
native_handle_type native_handle()
{
- return this->get_service().native_handle(this->get_implementation());
+ return impl_.get_service().native_handle(impl_.get_implementation());
}
/// Release ownership of the native descriptor implementation.
@@ -244,7 +318,7 @@ public:
*/
native_handle_type release()
{
- return this->get_service().release(this->get_implementation());
+ return impl_.get_service().release(impl_.get_implementation());
}
/// Cancel all asynchronous operations associated with the descriptor.
@@ -258,7 +332,7 @@ public:
void cancel()
{
asio::error_code ec;
- this->get_service().cancel(this->get_implementation(), ec);
+ impl_.get_service().cancel(impl_.get_implementation(), ec);
asio::detail::throw_error(ec, "cancel");
}
@@ -272,7 +346,7 @@ public:
*/
ASIO_SYNC_OP_VOID cancel(asio::error_code& ec)
{
- this->get_service().cancel(this->get_implementation(), ec);
+ impl_.get_service().cancel(impl_.get_implementation(), ec);
ASIO_SYNC_OP_VOID_RETURN(ec);
}
@@ -291,7 +365,7 @@ public:
* @par Example
* Getting the number of bytes ready to read:
* @code
- * asio::posix::stream_descriptor descriptor(io_context);
+ * asio::posix::stream_descriptor descriptor(my_context);
* ...
* asio::posix::stream_descriptor::bytes_readable command;
* descriptor.io_control(command);
@@ -302,7 +376,7 @@ public:
void io_control(IoControlCommand& command)
{
asio::error_code ec;
- this->get_service().io_control(this->get_implementation(), command, ec);
+ impl_.get_service().io_control(impl_.get_implementation(), command, ec);
asio::detail::throw_error(ec, "io_control");
}
@@ -321,7 +395,7 @@ public:
* @par Example
* Getting the number of bytes ready to read:
* @code
- * asio::posix::stream_descriptor descriptor(io_context);
+ * asio::posix::stream_descriptor descriptor(my_context);
* ...
* asio::posix::stream_descriptor::bytes_readable command;
* asio::error_code ec;
@@ -337,7 +411,7 @@ public:
ASIO_SYNC_OP_VOID io_control(IoControlCommand& command,
asio::error_code& ec)
{
- this->get_service().io_control(this->get_implementation(), command, ec);
+ impl_.get_service().io_control(impl_.get_implementation(), command, ec);
ASIO_SYNC_OP_VOID_RETURN(ec);
}
@@ -354,7 +428,7 @@ public:
*/
bool non_blocking() const
{
- return this->get_service().non_blocking(this->get_implementation());
+ return impl_.get_service().non_blocking(impl_.get_implementation());
}
/// Sets the non-blocking mode of the descriptor.
@@ -373,7 +447,7 @@ public:
void non_blocking(bool mode)
{
asio::error_code ec;
- this->get_service().non_blocking(this->get_implementation(), mode, ec);
+ impl_.get_service().non_blocking(impl_.get_implementation(), mode, ec);
asio::detail::throw_error(ec, "non_blocking");
}
@@ -393,7 +467,7 @@ public:
ASIO_SYNC_OP_VOID non_blocking(
bool mode, asio::error_code& ec)
{
- this->get_service().non_blocking(this->get_implementation(), mode, ec);
+ impl_.get_service().non_blocking(impl_.get_implementation(), mode, ec);
ASIO_SYNC_OP_VOID_RETURN(ec);
}
@@ -413,8 +487,8 @@ public:
*/
bool native_non_blocking() const
{
- return this->get_service().native_non_blocking(
- this->get_implementation());
+ return impl_.get_service().native_non_blocking(
+ impl_.get_implementation());
}
/// Sets the non-blocking mode of the native descriptor implementation.
@@ -435,8 +509,8 @@ public:
void native_non_blocking(bool mode)
{
asio::error_code ec;
- this->get_service().native_non_blocking(
- this->get_implementation(), mode, ec);
+ impl_.get_service().native_non_blocking(
+ impl_.get_implementation(), mode, ec);
asio::detail::throw_error(ec, "native_non_blocking");
}
@@ -458,8 +532,8 @@ public:
ASIO_SYNC_OP_VOID native_non_blocking(
bool mode, asio::error_code& ec)
{
- this->get_service().native_non_blocking(
- this->get_implementation(), mode, ec);
+ impl_.get_service().native_non_blocking(
+ impl_.get_implementation(), mode, ec);
ASIO_SYNC_OP_VOID_RETURN(ec);
}
@@ -474,7 +548,7 @@ public:
* @par Example
* Waiting for a descriptor to become readable.
* @code
- * asio::posix::stream_descriptor descriptor(io_context);
+ * asio::posix::stream_descriptor descriptor(my_context);
* ...
* descriptor.wait(asio::posix::stream_descriptor::wait_read);
* @endcode
@@ -482,7 +556,7 @@ public:
void wait(wait_type w)
{
asio::error_code ec;
- this->get_service().wait(this->get_implementation(), w, ec);
+ impl_.get_service().wait(impl_.get_implementation(), w, ec);
asio::detail::throw_error(ec, "wait");
}
@@ -499,7 +573,7 @@ public:
* @par Example
* Waiting for a descriptor to become readable.
* @code
- * asio::posix::stream_descriptor descriptor(io_context);
+ * asio::posix::stream_descriptor descriptor(my_context);
* ...
* asio::error_code ec;
* descriptor.wait(asio::posix::stream_descriptor::wait_read, ec);
@@ -507,7 +581,7 @@ public:
*/
ASIO_SYNC_OP_VOID wait(wait_type w, asio::error_code& ec)
{
- this->get_service().wait(this->get_implementation(), w, ec);
+ impl_.get_service().wait(impl_.get_implementation(), w, ec);
ASIO_SYNC_OP_VOID_RETURN(ec);
}
@@ -526,9 +600,9 @@ public:
* const asio::error_code& error // Result of operation
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
- * not, the handler will not be invoked from within this function. Invocation
- * of the handler will be performed in a manner equivalent to using
- * asio::io_context::post().
+ * not, the handler will not be invoked from within this function. On
+ * immediate completion, invocation of the handler will be performed in a
+ * manner equivalent to using asio::post().
*
* @par Example
* @code
@@ -542,31 +616,85 @@ public:
*
* ...
*
- * asio::posix::stream_descriptor descriptor(io_context);
+ * asio::posix::stream_descriptor descriptor(my_context);
* ...
* descriptor.async_wait(
* asio::posix::stream_descriptor::wait_read,
* wait_handler);
* @endcode
+ *
+ * @par Per-Operation Cancellation
+ * This asynchronous operation supports cancellation for the following
+ * asio::cancellation_type values:
+ *
+ * @li @c cancellation_type::terminal
+ *
+ * @li @c cancellation_type::partial
+ *
+ * @li @c cancellation_type::total
*/
- template <typename WaitHandler>
- ASIO_INITFN_RESULT_TYPE(WaitHandler,
+ template <
+ ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code))
+ WaitHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
+ ASIO_INITFN_AUTO_RESULT_TYPE(WaitHandler,
void (asio::error_code))
- async_wait(wait_type w, ASIO_MOVE_ARG(WaitHandler) handler)
+ async_wait(wait_type w,
+ ASIO_MOVE_ARG(WaitHandler) handler
+ ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
{
- // If you get an error on the following line it means that your handler does
- // not meet the documented type requirements for a WaitHandler.
- ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
-
- return this->get_service().async_wait(this->get_implementation(),
- w, ASIO_MOVE_CAST(WaitHandler)(handler));
+ return async_initiate<WaitHandler, void (asio::error_code)>(
+ initiate_async_wait(this), handler, w);
}
protected:
/// Protected destructor to prevent deletion through this type.
+ /**
+ * This function destroys the descriptor, cancelling any outstanding
+ * asynchronous wait operations associated with the descriptor as if by
+ * calling @c cancel.
+ */
~basic_descriptor()
{
}
+
+ detail::io_object_impl<detail::reactive_descriptor_service, Executor> impl_;
+
+private:
+ // Disallow copying and assignment.
+ basic_descriptor(const basic_descriptor&) ASIO_DELETED;
+ basic_descriptor& operator=(const basic_descriptor&) ASIO_DELETED;
+
+ class initiate_async_wait
+ {
+ public:
+ typedef Executor executor_type;
+
+ explicit initiate_async_wait(basic_descriptor* self)
+ : self_(self)
+ {
+ }
+
+ executor_type get_executor() const ASIO_NOEXCEPT
+ {
+ return self_->get_executor();
+ }
+
+ template <typename WaitHandler>
+ void operator()(ASIO_MOVE_ARG(WaitHandler) handler, wait_type w) const
+ {
+ // If you get an error on the following line it means that your handler
+ // does not meet the documented type requirements for a WaitHandler.
+ ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
+
+ detail::non_const_lvalue<WaitHandler> handler2(handler);
+ self_->impl_.get_service().async_wait(
+ self_->impl_.get_implementation(), w,
+ handler2.value, self_->impl_.get_executor());
+ }
+
+ private:
+ basic_descriptor* self_;
+ };
};
} // namespace posix
@@ -577,6 +705,4 @@ protected:
#endif // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
// || defined(GENERATING_DOCUMENTATION)
-#endif // defined(ASIO_ENABLE_OLD_SERVICES)
-
#endif // ASIO_POSIX_BASIC_DESCRIPTOR_HPP