repo_name
stringclasses 10
values | file_path
stringlengths 29
222
| content
stringlengths 24
926k
| extention
stringclasses 5
values |
---|---|---|---|
asio | data/projects/asio/include/boost/asio/signal_set_base.hpp | //
// signal_set_base.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SIGNAL_SET_BASE_HPP
#define BOOST_ASIO_SIGNAL_SET_BASE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
/// The signal_set_base class is used as a base for the basic_signal_set class
/// templates so that we have a common place to define the flags enum.
class signal_set_base
{
public:
# if defined(GENERATING_DOCUMENTATION)
/// Enumeration representing the different types of flags that may specified
/// when adding a signal to a set.
enum flags
{
/// Bitmask representing no flags.
none = 0,
/// Affects the behaviour of interruptible functions such that, if the
/// function would have failed with error::interrupted when interrupted by
/// the specified signal, the function shall instead be restarted and not
/// fail with error::interrupted.
restart = implementation_defined,
/// Do not generate SIGCHLD when child processes stop or stopped child
/// processes continue.
no_child_stop = implementation_defined,
/// Do not transform child processes into zombies when they terminate.
no_child_wait = implementation_defined,
/// Special value to indicate that the signal registration does not care
/// which flags are set, and so will not conflict with any prior
/// registrations of the same signal.
dont_care = -1
};
/// Portability typedef.
typedef flags flags_t;
#else // defined(GENERATING_DOCUMENTATION)
enum class flags : int
{
none = 0,
restart = BOOST_ASIO_OS_DEF(SA_RESTART),
no_child_stop = BOOST_ASIO_OS_DEF(SA_NOCLDSTOP),
no_child_wait = BOOST_ASIO_OS_DEF(SA_NOCLDWAIT),
dont_care = -1
};
typedef flags flags_t;
#endif // defined(GENERATING_DOCUMENTATION)
protected:
/// Protected destructor to prevent deletion through this type.
~signal_set_base()
{
}
};
/// Negation operator.
/**
* @relates signal_set_base::flags
*/
inline constexpr bool operator!(signal_set_base::flags_t x)
{
return static_cast<int>(x) == 0;
}
/// Bitwise and operator.
/**
* @relates signal_set_base::flags
*/
inline constexpr signal_set_base::flags_t operator&(
signal_set_base::flags_t x, signal_set_base::flags_t y)
{
return static_cast<signal_set_base::flags_t>(
static_cast<int>(x) & static_cast<int>(y));
}
/// Bitwise or operator.
/**
* @relates signal_set_base::flags
*/
inline constexpr signal_set_base::flags_t operator|(
signal_set_base::flags_t x, signal_set_base::flags_t y)
{
return static_cast<signal_set_base::flags_t>(
static_cast<int>(x) | static_cast<int>(y));
}
/// Bitwise xor operator.
/**
* @relates signal_set_base::flags
*/
inline constexpr signal_set_base::flags_t operator^(
signal_set_base::flags_t x, signal_set_base::flags_t y)
{
return static_cast<signal_set_base::flags_t>(
static_cast<int>(x) ^ static_cast<int>(y));
}
/// Bitwise negation operator.
/**
* @relates signal_set_base::flags
*/
inline constexpr signal_set_base::flags_t operator~(
signal_set_base::flags_t x)
{
return static_cast<signal_set_base::flags_t>(~static_cast<int>(x));
}
/// Bitwise and-assignment operator.
/**
* @relates signal_set_base::flags
*/
inline signal_set_base::flags_t& operator&=(
signal_set_base::flags_t& x, signal_set_base::flags_t y)
{
x = x & y;
return x;
}
/// Bitwise or-assignment operator.
/**
* @relates signal_set_base::flags
*/
inline signal_set_base::flags_t& operator|=(
signal_set_base::flags_t& x, signal_set_base::flags_t y)
{
x = x | y;
return x;
}
/// Bitwise xor-assignment operator.
/**
* @relates signal_set_base::flags
*/
inline signal_set_base::flags_t& operator^=(
signal_set_base::flags_t& x, signal_set_base::flags_t y)
{
x = x ^ y;
return x;
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SIGNAL_SET_BASE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/basic_raw_socket.hpp | //
// basic_raw_socket.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_BASIC_RAW_SOCKET_HPP
#define BOOST_ASIO_BASIC_RAW_SOCKET_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <boost/asio/basic_socket.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if !defined(BOOST_ASIO_BASIC_RAW_SOCKET_FWD_DECL)
#define BOOST_ASIO_BASIC_RAW_SOCKET_FWD_DECL
// Forward declaration with defaulted arguments.
template <typename Protocol, typename Executor = any_io_executor>
class basic_raw_socket;
#endif // !defined(BOOST_ASIO_BASIC_RAW_SOCKET_FWD_DECL)
/// Provides raw-oriented socket functionality.
/**
* The basic_raw_socket class template provides asynchronous and blocking
* raw-oriented socket functionality.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*
* Synchronous @c send, @c send_to, @c receive, @c receive_from, @c connect,
* and @c shutdown operations are thread safe with respect to each other, if
* the underlying operating system calls are also thread safe. This means that
* it is permitted to perform concurrent calls to these synchronous operations
* on a single socket object. Other synchronous operations, such as @c open or
* @c close, are not thread safe.
*/
template <typename Protocol, typename Executor>
class basic_raw_socket
: public basic_socket<Protocol, Executor>
{
private:
class initiate_async_send;
class initiate_async_send_to;
class initiate_async_receive;
class initiate_async_receive_from;
public:
/// The type of the executor associated with the object.
typedef Executor executor_type;
/// Rebinds the socket type to another executor.
template <typename Executor1>
struct rebind_executor
{
/// The socket type when rebound to the specified executor.
typedef basic_raw_socket<Protocol, Executor1> other;
};
/// The native representation of a socket.
#if defined(GENERATING_DOCUMENTATION)
typedef implementation_defined native_handle_type;
#else
typedef typename basic_socket<Protocol,
Executor>::native_handle_type native_handle_type;
#endif
/// The protocol type.
typedef Protocol protocol_type;
/// The endpoint type.
typedef typename Protocol::endpoint endpoint_type;
/// Construct a basic_raw_socket without opening it.
/**
* This constructor creates a raw socket without opening it. The open()
* function must be called before data can be sent or received on the socket.
*
* @param ex The I/O executor that the socket will use, by default, to
* dispatch handlers for any asynchronous operations performed on the socket.
*/
explicit basic_raw_socket(const executor_type& ex)
: basic_socket<Protocol, Executor>(ex)
{
}
/// Construct a basic_raw_socket without opening it.
/**
* This constructor creates a raw socket without opening it. The open()
* function must be called before data can be sent or received on the socket.
*
* @param context An execution context which provides the I/O executor that
* the socket will use, by default, to dispatch handlers for any asynchronous
* operations performed on the socket.
*/
template <typename ExecutionContext>
explicit basic_raw_socket(ExecutionContext& context,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
> = 0)
: basic_socket<Protocol, Executor>(context)
{
}
/// Construct and open a basic_raw_socket.
/**
* This constructor creates and opens a raw socket.
*
* @param ex The I/O executor that the socket will use, by default, to
* dispatch handlers for any asynchronous operations performed on the socket.
*
* @param protocol An object specifying protocol parameters to be used.
*
* @throws boost::system::system_error Thrown on failure.
*/
basic_raw_socket(const executor_type& ex, const protocol_type& protocol)
: basic_socket<Protocol, Executor>(ex, protocol)
{
}
/// Construct and open a basic_raw_socket.
/**
* This constructor creates and opens a raw socket.
*
* @param context An execution context which provides the I/O executor that
* the socket will use, by default, to dispatch handlers for any asynchronous
* operations performed on the socket.
*
* @param protocol An object specifying protocol parameters to be used.
*
* @throws boost::system::system_error Thrown on failure.
*/
template <typename ExecutionContext>
basic_raw_socket(ExecutionContext& context, const protocol_type& protocol,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value,
defaulted_constraint
> = defaulted_constraint())
: basic_socket<Protocol, Executor>(context, protocol)
{
}
/// Construct a basic_raw_socket, opening it and binding it to the given
/// local endpoint.
/**
* This constructor creates a raw socket and automatically opens it bound
* to the specified endpoint on the local machine. The protocol used is the
* protocol associated with the given endpoint.
*
* @param ex The I/O executor that the socket will use, by default, to
* dispatch handlers for any asynchronous operations performed on the socket.
*
* @param endpoint An endpoint on the local machine to which the raw
* socket will be bound.
*
* @throws boost::system::system_error Thrown on failure.
*/
basic_raw_socket(const executor_type& ex, const endpoint_type& endpoint)
: basic_socket<Protocol, Executor>(ex, endpoint)
{
}
/// Construct a basic_raw_socket, opening it and binding it to the given
/// local endpoint.
/**
* This constructor creates a raw socket and automatically opens it bound
* to the specified endpoint on the local machine. The protocol used is the
* protocol associated with the given endpoint.
*
* @param context An execution context which provides the I/O executor that
* the socket will use, by default, to dispatch handlers for any asynchronous
* operations performed on the socket.
*
* @param endpoint An endpoint on the local machine to which the raw
* socket will be bound.
*
* @throws boost::system::system_error Thrown on failure.
*/
template <typename ExecutionContext>
basic_raw_socket(ExecutionContext& context, const endpoint_type& endpoint,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
> = 0)
: basic_socket<Protocol, Executor>(context, endpoint)
{
}
/// Construct a basic_raw_socket on an existing native socket.
/**
* This constructor creates a raw socket object to hold an existing
* native socket.
*
* @param ex The I/O executor that the socket will use, by default, to
* dispatch handlers for any asynchronous operations performed on the socket.
*
* @param protocol An object specifying protocol parameters to be used.
*
* @param native_socket The new underlying socket implementation.
*
* @throws boost::system::system_error Thrown on failure.
*/
basic_raw_socket(const executor_type& ex,
const protocol_type& protocol, const native_handle_type& native_socket)
: basic_socket<Protocol, Executor>(ex, protocol, native_socket)
{
}
/// Construct a basic_raw_socket on an existing native socket.
/**
* This constructor creates a raw socket object to hold an existing
* native socket.
*
* @param context An execution context which provides the I/O executor that
* the socket will use, by default, to dispatch handlers for any asynchronous
* operations performed on the socket.
*
* @param protocol An object specifying protocol parameters to be used.
*
* @param native_socket The new underlying socket implementation.
*
* @throws boost::system::system_error Thrown on failure.
*/
template <typename ExecutionContext>
basic_raw_socket(ExecutionContext& context,
const protocol_type& protocol, const native_handle_type& native_socket,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
> = 0)
: basic_socket<Protocol, Executor>(context, protocol, native_socket)
{
}
/// Move-construct a basic_raw_socket from another.
/**
* This constructor moves a raw socket from one object to another.
*
* @param other The other basic_raw_socket 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_raw_socket(const executor_type&)
* constructor.
*/
basic_raw_socket(basic_raw_socket&& other) noexcept
: basic_socket<Protocol, Executor>(std::move(other))
{
}
/// Move-assign a basic_raw_socket from another.
/**
* This assignment operator moves a raw socket from one object to another.
*
* @param other The other basic_raw_socket 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_raw_socket(const executor_type&)
* constructor.
*/
basic_raw_socket& operator=(basic_raw_socket&& other)
{
basic_socket<Protocol, Executor>::operator=(std::move(other));
return *this;
}
/// Move-construct a basic_raw_socket from a socket of another protocol
/// type.
/**
* This constructor moves a raw socket from one object to another.
*
* @param other The other basic_raw_socket 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_raw_socket(const executor_type&)
* constructor.
*/
template <typename Protocol1, typename Executor1>
basic_raw_socket(basic_raw_socket<Protocol1, Executor1>&& other,
constraint_t<
is_convertible<Protocol1, Protocol>::value
&& is_convertible<Executor1, Executor>::value
> = 0)
: basic_socket<Protocol, Executor>(std::move(other))
{
}
/// Move-assign a basic_raw_socket from a socket of another protocol type.
/**
* This assignment operator moves a raw socket from one object to another.
*
* @param other The other basic_raw_socket 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_raw_socket(const executor_type&)
* constructor.
*/
template <typename Protocol1, typename Executor1>
constraint_t<
is_convertible<Protocol1, Protocol>::value
&& is_convertible<Executor1, Executor>::value,
basic_raw_socket&
> operator=(basic_raw_socket<Protocol1, Executor1>&& other)
{
basic_socket<Protocol, Executor>::operator=(std::move(other));
return *this;
}
/// Destroys the socket.
/**
* This function destroys the socket, cancelling any outstanding asynchronous
* operations associated with the socket as if by calling @c cancel.
*/
~basic_raw_socket()
{
}
/// Send some data on a connected socket.
/**
* This function is used to send data on the raw socket. The function call
* will block until the data has been sent successfully or an error occurs.
*
* @param buffers One ore more data buffers to be sent on the socket.
*
* @returns The number of bytes sent.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note The send operation can only be used with a connected socket. Use
* the send_to function to send data on an unconnected raw socket.
*
* @par Example
* To send a single data buffer use the @ref buffer function as follows:
* @code socket.send(boost::asio::buffer(data, size)); @endcode
* See the @ref buffer documentation for information on sending multiple
* buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*/
template <typename ConstBufferSequence>
std::size_t send(const ConstBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t s = this->impl_.get_service().send(
this->impl_.get_implementation(), buffers, 0, ec);
boost::asio::detail::throw_error(ec, "send");
return s;
}
/// Send some data on a connected socket.
/**
* This function is used to send data on the raw socket. The function call
* will block until the data has been sent successfully or an error occurs.
*
* @param buffers One ore more data buffers to be sent on the socket.
*
* @param flags Flags specifying how the send call is to be made.
*
* @returns The number of bytes sent.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note The send operation can only be used with a connected socket. Use
* the send_to function to send data on an unconnected raw socket.
*/
template <typename ConstBufferSequence>
std::size_t send(const ConstBufferSequence& buffers,
socket_base::message_flags flags)
{
boost::system::error_code ec;
std::size_t s = this->impl_.get_service().send(
this->impl_.get_implementation(), buffers, flags, ec);
boost::asio::detail::throw_error(ec, "send");
return s;
}
/// Send some data on a connected socket.
/**
* This function is used to send data on the raw socket. The function call
* will block until the data has been sent successfully or an error occurs.
*
* @param buffers One or more data buffers to be sent on the socket.
*
* @param flags Flags specifying how the send call is to be made.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns The number of bytes sent.
*
* @note The send operation can only be used with a connected socket. Use
* the send_to function to send data on an unconnected raw socket.
*/
template <typename ConstBufferSequence>
std::size_t send(const ConstBufferSequence& buffers,
socket_base::message_flags flags, boost::system::error_code& ec)
{
return this->impl_.get_service().send(
this->impl_.get_implementation(), buffers, flags, ec);
}
/// Start an asynchronous send on a connected socket.
/**
* This function is used to asynchronously send data on the raw socket. It is
* an initiating function for an @ref asynchronous_operation, and always
* returns immediately.
*
* @param buffers One or more data buffers to be sent on the socket. Although
* the buffers object may be copied as necessary, ownership of the underlying
* memory blocks is retained by the caller, which must guarantee that they
* remain valid until the completion handler is called.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the send completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes sent.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @note The async_send operation can only be used with a connected socket.
* Use the async_send_to function to send data on an unconnected raw
* socket.
*
* @par Example
* To send a single data buffer use the @ref buffer function as follows:
* @code
* socket.async_send(boost::asio::buffer(data, size), handler);
* @endcode
* See the @ref buffer documentation for information on sending multiple
* buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*
* @par Per-Operation Cancellation
* On POSIX or Windows operating systems, this asynchronous operation supports
* cancellation for the following boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* @li @c cancellation_type::total
*/
template <typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken = default_completion_token_t<executor_type>>
auto async_send(const ConstBufferSequence& buffers,
WriteToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_send>(), token,
buffers, socket_base::message_flags(0)))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_send(this), token,
buffers, socket_base::message_flags(0));
}
/// Start an asynchronous send on a connected socket.
/**
* This function is used to asynchronously send data on the raw socket. It is
* an initiating function for an @ref asynchronous_operation, and always
* returns immediately.
*
* @param buffers One or more data buffers to be sent on the socket. Although
* the buffers object may be copied as necessary, ownership of the underlying
* memory blocks is retained by the caller, which must guarantee that they
* remain valid until the completion handler is called.
*
* @param flags Flags specifying how the send call is to be made.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the send completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes sent.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @note The async_send operation can only be used with a connected socket.
* Use the async_send_to function to send data on an unconnected raw
* socket.
*
* @par Per-Operation Cancellation
* On POSIX or Windows operating systems, this asynchronous operation supports
* cancellation for the following boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* @li @c cancellation_type::total
*/
template <typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken = default_completion_token_t<executor_type>>
auto async_send(const ConstBufferSequence& buffers,
socket_base::message_flags flags,
WriteToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_send>(), token, buffers, flags))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_send(this), token, buffers, flags);
}
/// Send raw data to the specified endpoint.
/**
* This function is used to send raw data to the specified remote endpoint.
* The function call will block until the data has been sent successfully or
* an error occurs.
*
* @param buffers One or more data buffers to be sent to the remote endpoint.
*
* @param destination The remote endpoint to which the data will be sent.
*
* @returns The number of bytes sent.
*
* @throws boost::system::system_error Thrown on failure.
*
* @par Example
* To send a single data buffer use the @ref buffer function as follows:
* @code
* boost::asio::ip::udp::endpoint destination(
* boost::asio::ip::address::from_string("1.2.3.4"), 12345);
* socket.send_to(boost::asio::buffer(data, size), destination);
* @endcode
* See the @ref buffer documentation for information on sending multiple
* buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*/
template <typename ConstBufferSequence>
std::size_t send_to(const ConstBufferSequence& buffers,
const endpoint_type& destination)
{
boost::system::error_code ec;
std::size_t s = this->impl_.get_service().send_to(
this->impl_.get_implementation(), buffers, destination, 0, ec);
boost::asio::detail::throw_error(ec, "send_to");
return s;
}
/// Send raw data to the specified endpoint.
/**
* This function is used to send raw data to the specified remote endpoint.
* The function call will block until the data has been sent successfully or
* an error occurs.
*
* @param buffers One or more data buffers to be sent to the remote endpoint.
*
* @param destination The remote endpoint to which the data will be sent.
*
* @param flags Flags specifying how the send call is to be made.
*
* @returns The number of bytes sent.
*
* @throws boost::system::system_error Thrown on failure.
*/
template <typename ConstBufferSequence>
std::size_t send_to(const ConstBufferSequence& buffers,
const endpoint_type& destination, socket_base::message_flags flags)
{
boost::system::error_code ec;
std::size_t s = this->impl_.get_service().send_to(
this->impl_.get_implementation(), buffers, destination, flags, ec);
boost::asio::detail::throw_error(ec, "send_to");
return s;
}
/// Send raw data to the specified endpoint.
/**
* This function is used to send raw data to the specified remote endpoint.
* The function call will block until the data has been sent successfully or
* an error occurs.
*
* @param buffers One or more data buffers to be sent to the remote endpoint.
*
* @param destination The remote endpoint to which the data will be sent.
*
* @param flags Flags specifying how the send call is to be made.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns The number of bytes sent.
*/
template <typename ConstBufferSequence>
std::size_t send_to(const ConstBufferSequence& buffers,
const endpoint_type& destination, socket_base::message_flags flags,
boost::system::error_code& ec)
{
return this->impl_.get_service().send_to(this->impl_.get_implementation(),
buffers, destination, flags, ec);
}
/// Start an asynchronous send.
/**
* This function is used to asynchronously send raw data to the specified
* remote endpoint. It is an initiating function for an @ref
* asynchronous_operation, and always returns immediately.
*
* @param buffers One or more data buffers to be sent to the remote endpoint.
* Although the buffers object may be copied as necessary, ownership of the
* underlying memory blocks is retained by the caller, which must guarantee
* that they remain valid until the completion handler is called.
*
* @param destination The remote endpoint to which the data will be sent.
* Copies will be made of the endpoint as required.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the send completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes sent.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @par Example
* To send a single data buffer use the @ref buffer function as follows:
* @code
* boost::asio::ip::udp::endpoint destination(
* boost::asio::ip::address::from_string("1.2.3.4"), 12345);
* socket.async_send_to(
* boost::asio::buffer(data, size), destination, handler);
* @endcode
* See the @ref buffer documentation for information on sending multiple
* buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*
* @par Per-Operation Cancellation
* On POSIX or Windows operating systems, this asynchronous operation supports
* cancellation for the following boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* @li @c cancellation_type::total
*/
template <typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken = default_completion_token_t<executor_type>>
auto async_send_to(const ConstBufferSequence& buffers,
const endpoint_type& destination,
WriteToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_send_to>(), token, buffers,
destination, socket_base::message_flags(0)))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_send_to(this), token, buffers,
destination, socket_base::message_flags(0));
}
/// Start an asynchronous send.
/**
* This function is used to asynchronously send raw data to the specified
* remote endpoint. It is an initiating function for an @ref
* asynchronous_operation, and always returns immediately.
*
* @param buffers One or more data buffers to be sent to the remote endpoint.
* Although the buffers object may be copied as necessary, ownership of the
* underlying memory blocks is retained by the caller, which must guarantee
* that they remain valid until the completion handler is called.
*
* @param flags Flags specifying how the send call is to be made.
*
* @param destination The remote endpoint to which the data will be sent.
* Copies will be made of the endpoint as required.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the send completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes sent.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @par Per-Operation Cancellation
* On POSIX or Windows operating systems, this asynchronous operation supports
* cancellation for the following boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* @li @c cancellation_type::total
*/
template <typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken = default_completion_token_t<executor_type>>
auto async_send_to(const ConstBufferSequence& buffers,
const endpoint_type& destination, socket_base::message_flags flags,
WriteToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_send_to>(), token,
buffers, destination, flags))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_send_to(this), token,
buffers, destination, flags);
}
/// Receive some data on a connected socket.
/**
* This function is used to receive data on the raw socket. The function
* call will block until data has been received successfully or an error
* occurs.
*
* @param buffers One or more buffers into which the data will be received.
*
* @returns The number of bytes received.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note The receive operation can only be used with a connected socket. Use
* the receive_from function to receive data on an unconnected raw
* socket.
*
* @par Example
* To receive into a single data buffer use the @ref buffer function as
* follows:
* @code socket.receive(boost::asio::buffer(data, size)); @endcode
* See the @ref buffer documentation for information on receiving into
* multiple buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*/
template <typename MutableBufferSequence>
std::size_t receive(const MutableBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t s = this->impl_.get_service().receive(
this->impl_.get_implementation(), buffers, 0, ec);
boost::asio::detail::throw_error(ec, "receive");
return s;
}
/// Receive some data on a connected socket.
/**
* This function is used to receive data on the raw socket. The function
* call will block until data has been received successfully or an error
* occurs.
*
* @param buffers One or more buffers into which the data will be received.
*
* @param flags Flags specifying how the receive call is to be made.
*
* @returns The number of bytes received.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note The receive operation can only be used with a connected socket. Use
* the receive_from function to receive data on an unconnected raw
* socket.
*/
template <typename MutableBufferSequence>
std::size_t receive(const MutableBufferSequence& buffers,
socket_base::message_flags flags)
{
boost::system::error_code ec;
std::size_t s = this->impl_.get_service().receive(
this->impl_.get_implementation(), buffers, flags, ec);
boost::asio::detail::throw_error(ec, "receive");
return s;
}
/// Receive some data on a connected socket.
/**
* This function is used to receive data on the raw socket. The function
* call will block until data has been received successfully or an error
* occurs.
*
* @param buffers One or more buffers into which the data will be received.
*
* @param flags Flags specifying how the receive call is to be made.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns The number of bytes received.
*
* @note The receive operation can only be used with a connected socket. Use
* the receive_from function to receive data on an unconnected raw
* socket.
*/
template <typename MutableBufferSequence>
std::size_t receive(const MutableBufferSequence& buffers,
socket_base::message_flags flags, boost::system::error_code& ec)
{
return this->impl_.get_service().receive(
this->impl_.get_implementation(), buffers, flags, ec);
}
/// Start an asynchronous receive on a connected socket.
/**
* This function is used to asynchronously receive data from the raw
* socket. It is an initiating function for an @ref asynchronous_operation,
* and always returns immediately.
*
* @param buffers One or more buffers into which the data will be received.
* Although the buffers object may be copied as necessary, ownership of the
* underlying memory blocks is retained by the caller, which must guarantee
* that they remain valid until the completion handler is called.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the receive completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes received.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @note The async_receive operation can only be used with a connected socket.
* Use the async_receive_from function to receive data on an unconnected
* raw socket.
*
* @par Example
* To receive into a single data buffer use the @ref buffer function as
* follows:
* @code
* socket.async_receive(boost::asio::buffer(data, size), handler);
* @endcode
* See the @ref buffer documentation for information on receiving into
* multiple buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*
* @par Per-Operation Cancellation
* On POSIX or Windows operating systems, this asynchronous operation supports
* cancellation for the following boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* @li @c cancellation_type::total
*/
template <typename MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken = default_completion_token_t<executor_type>>
auto async_receive(const MutableBufferSequence& buffers,
ReadToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_receive>(), token,
buffers, socket_base::message_flags(0)))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_receive(this), token,
buffers, socket_base::message_flags(0));
}
/// Start an asynchronous receive on a connected socket.
/**
* This function is used to asynchronously receive data from the raw
* socket. It is an initiating function for an @ref asynchronous_operation,
* and always returns immediately.
*
* @param buffers One or more buffers into which the data will be received.
* Although the buffers object may be copied as necessary, ownership of the
* underlying memory blocks is retained by the caller, which must guarantee
* that they remain valid until the completion handler is called.
*
* @param flags Flags specifying how the receive call is to be made.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the receive completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes received.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @note The async_receive operation can only be used with a connected socket.
* Use the async_receive_from function to receive data on an unconnected
* raw socket.
*
* @par Per-Operation Cancellation
* On POSIX or Windows operating systems, this asynchronous operation supports
* cancellation for the following boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* @li @c cancellation_type::total
*/
template <typename MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken
= default_completion_token_t<executor_type>>
auto async_receive(const MutableBufferSequence& buffers,
socket_base::message_flags flags,
ReadToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_receive>(), token, buffers, flags))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_receive(this), token, buffers, flags);
}
/// Receive raw data with the endpoint of the sender.
/**
* This function is used to receive raw data. The function call will block
* until data has been received successfully or an error occurs.
*
* @param buffers One or more buffers into which the data will be received.
*
* @param sender_endpoint An endpoint object that receives the endpoint of
* the remote sender of the data.
*
* @returns The number of bytes received.
*
* @throws boost::system::system_error Thrown on failure.
*
* @par Example
* To receive into a single data buffer use the @ref buffer function as
* follows:
* @code
* boost::asio::ip::udp::endpoint sender_endpoint;
* socket.receive_from(
* boost::asio::buffer(data, size), sender_endpoint);
* @endcode
* See the @ref buffer documentation for information on receiving into
* multiple buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*/
template <typename MutableBufferSequence>
std::size_t receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender_endpoint)
{
boost::system::error_code ec;
std::size_t s = this->impl_.get_service().receive_from(
this->impl_.get_implementation(), buffers, sender_endpoint, 0, ec);
boost::asio::detail::throw_error(ec, "receive_from");
return s;
}
/// Receive raw data with the endpoint of the sender.
/**
* This function is used to receive raw data. The function call will block
* until data has been received successfully or an error occurs.
*
* @param buffers One or more buffers into which the data will be received.
*
* @param sender_endpoint An endpoint object that receives the endpoint of
* the remote sender of the data.
*
* @param flags Flags specifying how the receive call is to be made.
*
* @returns The number of bytes received.
*
* @throws boost::system::system_error Thrown on failure.
*/
template <typename MutableBufferSequence>
std::size_t receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender_endpoint, socket_base::message_flags flags)
{
boost::system::error_code ec;
std::size_t s = this->impl_.get_service().receive_from(
this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec);
boost::asio::detail::throw_error(ec, "receive_from");
return s;
}
/// Receive raw data with the endpoint of the sender.
/**
* This function is used to receive raw data. The function call will block
* until data has been received successfully or an error occurs.
*
* @param buffers One or more buffers into which the data will be received.
*
* @param sender_endpoint An endpoint object that receives the endpoint of
* the remote sender of the data.
*
* @param flags Flags specifying how the receive call is to be made.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns The number of bytes received.
*/
template <typename MutableBufferSequence>
std::size_t receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender_endpoint, socket_base::message_flags flags,
boost::system::error_code& ec)
{
return this->impl_.get_service().receive_from(
this->impl_.get_implementation(), buffers, sender_endpoint, flags, ec);
}
/// Start an asynchronous receive.
/**
* This function is used to asynchronously receive raw data. It is an
* initiating function for an @ref asynchronous_operation, and always returns
* immediately.
*
* @param buffers One or more buffers into which the data will be received.
* Although the buffers object may be copied as necessary, ownership of the
* underlying memory blocks is retained by the caller, which must guarantee
* that they remain valid until the completion handler is called.
*
* @param sender_endpoint An endpoint object that receives the endpoint of
* the remote sender of the data. Ownership of the sender_endpoint object
* is retained by the caller, which must guarantee that it is valid until the
* completion handler is called.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the receive completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes received.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @par Example
* To receive into a single data buffer use the @ref buffer function as
* follows:
* @code socket.async_receive_from(
* boost::asio::buffer(data, size), 0, sender_endpoint, handler); @endcode
* See the @ref buffer documentation for information on receiving into
* multiple buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*
* @par Per-Operation Cancellation
* On POSIX or Windows operating systems, this asynchronous operation supports
* cancellation for the following boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* @li @c cancellation_type::total
*/
template <typename MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken = default_completion_token_t<executor_type>>
auto async_receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender_endpoint,
ReadToken&& token
= default_completion_token_t<executor_type>())
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_receive_from>(), token, buffers,
&sender_endpoint, socket_base::message_flags(0)))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_receive_from(this), token, buffers,
&sender_endpoint, socket_base::message_flags(0));
}
/// Start an asynchronous receive.
/**
* This function is used to asynchronously receive raw data. It is an
* initiating function for an @ref asynchronous_operation, and always returns
* immediately.
*
* @param buffers One or more buffers into which the data will be received.
* Although the buffers object may be copied as necessary, ownership of the
* underlying memory blocks is retained by the caller, which must guarantee
* that they remain valid until the completion handler is called.
*
* @param sender_endpoint An endpoint object that receives the endpoint of
* the remote sender of the data. Ownership of the sender_endpoint object
* is retained by the caller, which must guarantee that it is valid until the
* completion handler is called.
*
* @param flags Flags specifying how the receive call is to be made.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the receive completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes received.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @par Per-Operation Cancellation
* On POSIX or Windows operating systems, this asynchronous operation supports
* cancellation for the following boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* @li @c cancellation_type::total
*/
template <typename MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken
= default_completion_token_t<executor_type>>
auto async_receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender_endpoint, socket_base::message_flags flags,
ReadToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_receive_from>(), token,
buffers, &sender_endpoint, flags))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_receive_from(this), token,
buffers, &sender_endpoint, flags);
}
private:
// Disallow copying and assignment.
basic_raw_socket(const basic_raw_socket&) = delete;
basic_raw_socket& operator=(const basic_raw_socket&) = delete;
class initiate_async_send
{
public:
typedef Executor executor_type;
explicit initiate_async_send(basic_raw_socket* self)
: self_(self)
{
}
const executor_type& get_executor() const noexcept
{
return self_->get_executor();
}
template <typename WriteHandler, typename ConstBufferSequence>
void operator()(WriteHandler&& handler,
const ConstBufferSequence& buffers,
socket_base::message_flags flags) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::non_const_lvalue<WriteHandler> handler2(handler);
self_->impl_.get_service().async_send(
self_->impl_.get_implementation(), buffers, flags,
handler2.value, self_->impl_.get_executor());
}
private:
basic_raw_socket* self_;
};
class initiate_async_send_to
{
public:
typedef Executor executor_type;
explicit initiate_async_send_to(basic_raw_socket* self)
: self_(self)
{
}
const executor_type& get_executor() const noexcept
{
return self_->get_executor();
}
template <typename WriteHandler, typename ConstBufferSequence>
void operator()(WriteHandler&& handler,
const ConstBufferSequence& buffers, const endpoint_type& destination,
socket_base::message_flags flags) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::non_const_lvalue<WriteHandler> handler2(handler);
self_->impl_.get_service().async_send_to(
self_->impl_.get_implementation(), buffers, destination,
flags, handler2.value, self_->impl_.get_executor());
}
private:
basic_raw_socket* self_;
};
class initiate_async_receive
{
public:
typedef Executor executor_type;
explicit initiate_async_receive(basic_raw_socket* self)
: self_(self)
{
}
const executor_type& get_executor() const noexcept
{
return self_->get_executor();
}
template <typename ReadHandler, typename MutableBufferSequence>
void operator()(ReadHandler&& handler,
const MutableBufferSequence& buffers,
socket_base::message_flags flags) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::non_const_lvalue<ReadHandler> handler2(handler);
self_->impl_.get_service().async_receive(
self_->impl_.get_implementation(), buffers, flags,
handler2.value, self_->impl_.get_executor());
}
private:
basic_raw_socket* self_;
};
class initiate_async_receive_from
{
public:
typedef Executor executor_type;
explicit initiate_async_receive_from(basic_raw_socket* self)
: self_(self)
{
}
const executor_type& get_executor() const noexcept
{
return self_->get_executor();
}
template <typename ReadHandler, typename MutableBufferSequence>
void operator()(ReadHandler&& handler,
const MutableBufferSequence& buffers, endpoint_type* sender_endpoint,
socket_base::message_flags flags) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
detail::non_const_lvalue<ReadHandler> handler2(handler);
self_->impl_.get_service().async_receive_from(
self_->impl_.get_implementation(), buffers, *sender_endpoint,
flags, handler2.value, self_->impl_.get_executor());
}
private:
basic_raw_socket* self_;
};
};
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_BASIC_RAW_SOCKET_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/basic_writable_pipe.hpp | //
// basic_writable_pipe.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_BASIC_WRITABLE_PIPE_HPP
#define BOOST_ASIO_BASIC_WRITABLE_PIPE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HAS_PIPE) \
|| defined(GENERATING_DOCUMENTATION)
#include <string>
#include <utility>
#include <boost/asio/any_io_executor.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/io_object_impl.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/execution_context.hpp>
#if defined(BOOST_ASIO_HAS_IOCP)
# include <boost/asio/detail/win_iocp_handle_service.hpp>
#elif defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT)
# include <boost/asio/detail/io_uring_descriptor_service.hpp>
#else
# include <boost/asio/detail/reactive_descriptor_service.hpp>
#endif
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
/// Provides pipe functionality.
/**
* The basic_writable_pipe class provides a wrapper over pipe
* functionality.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*/
template <typename Executor = any_io_executor>
class basic_writable_pipe
{
private:
class initiate_async_write_some;
public:
/// The type of the executor associated with the object.
typedef Executor executor_type;
/// Rebinds the pipe type to another executor.
template <typename Executor1>
struct rebind_executor
{
/// The pipe type when rebound to the specified executor.
typedef basic_writable_pipe<Executor1> other;
};
/// The native representation of a pipe.
#if defined(GENERATING_DOCUMENTATION)
typedef implementation_defined native_handle_type;
#elif defined(BOOST_ASIO_HAS_IOCP)
typedef detail::win_iocp_handle_service::native_handle_type
native_handle_type;
#elif defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT)
typedef detail::io_uring_descriptor_service::native_handle_type
native_handle_type;
#else
typedef detail::reactive_descriptor_service::native_handle_type
native_handle_type;
#endif
/// A basic_writable_pipe is always the lowest layer.
typedef basic_writable_pipe lowest_layer_type;
/// Construct a basic_writable_pipe without opening it.
/**
* This constructor creates a pipe without opening it.
*
* @param ex The I/O executor that the pipe will use, by default, to dispatch
* handlers for any asynchronous operations performed on the pipe.
*/
explicit basic_writable_pipe(const executor_type& ex)
: impl_(0, ex)
{
}
/// Construct a basic_writable_pipe without opening it.
/**
* This constructor creates a pipe without opening it.
*
* @param context An execution context which provides the I/O executor that
* the pipe will use, by default, to dispatch handlers for any asynchronous
* operations performed on the pipe.
*/
template <typename ExecutionContext>
explicit basic_writable_pipe(ExecutionContext& context,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value,
defaulted_constraint
> = defaulted_constraint())
: impl_(0, 0, context)
{
}
/// Construct a basic_writable_pipe on an existing native pipe.
/**
* This constructor creates a pipe object to hold an existing native
* pipe.
*
* @param ex The I/O executor that the pipe will use, by default, to
* dispatch handlers for any asynchronous operations performed on the
* pipe.
*
* @param native_pipe A native pipe.
*
* @throws boost::system::system_error Thrown on failure.
*/
basic_writable_pipe(const executor_type& ex,
const native_handle_type& native_pipe)
: impl_(0, ex)
{
boost::system::error_code ec;
impl_.get_service().assign(impl_.get_implementation(),
native_pipe, ec);
boost::asio::detail::throw_error(ec, "assign");
}
/// Construct a basic_writable_pipe on an existing native pipe.
/**
* This constructor creates a pipe object to hold an existing native
* pipe.
*
* @param context An execution context which provides the I/O executor that
* the pipe will use, by default, to dispatch handlers for any
* asynchronous operations performed on the pipe.
*
* @param native_pipe A native pipe.
*
* @throws boost::system::system_error Thrown on failure.
*/
template <typename ExecutionContext>
basic_writable_pipe(ExecutionContext& context,
const native_handle_type& native_pipe,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
> = 0)
: impl_(0, 0, context)
{
boost::system::error_code ec;
impl_.get_service().assign(impl_.get_implementation(),
native_pipe, ec);
boost::asio::detail::throw_error(ec, "assign");
}
/// Move-construct a basic_writable_pipe from another.
/**
* This constructor moves a pipe from one object to another.
*
* @param other The other basic_writable_pipe 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_writable_pipe(const executor_type&)
* constructor.
*/
basic_writable_pipe(basic_writable_pipe&& other)
: impl_(std::move(other.impl_))
{
}
/// Move-assign a basic_writable_pipe from another.
/**
* This assignment operator moves a pipe from one object to another.
*
* @param other The other basic_writable_pipe 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_writable_pipe(const executor_type&)
* constructor.
*/
basic_writable_pipe& operator=(basic_writable_pipe&& other)
{
impl_ = std::move(other.impl_);
return *this;
}
// All pipes have access to each other's implementations.
template <typename Executor1>
friend class basic_writable_pipe;
/// Move-construct a basic_writable_pipe from a pipe of another executor type.
/**
* This constructor moves a pipe from one object to another.
*
* @param other The other basic_writable_pipe 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_writable_pipe(const executor_type&)
* constructor.
*/
template <typename Executor1>
basic_writable_pipe(basic_writable_pipe<Executor1>&& other,
constraint_t<
is_convertible<Executor1, Executor>::value,
defaulted_constraint
> = defaulted_constraint())
: impl_(std::move(other.impl_))
{
}
/// Move-assign a basic_writable_pipe from a pipe of another executor type.
/**
* This assignment operator moves a pipe from one object to another.
*
* @param other The other basic_writable_pipe 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_writable_pipe(const executor_type&)
* constructor.
*/
template <typename Executor1>
constraint_t<
is_convertible<Executor1, Executor>::value,
basic_writable_pipe&
> operator=(basic_writable_pipe<Executor1>&& other)
{
basic_writable_pipe tmp(std::move(other));
impl_ = std::move(tmp.impl_);
return *this;
}
/// Destroys the pipe.
/**
* This function destroys the pipe, cancelling any outstanding
* asynchronous wait operations associated with the pipe as if by
* calling @c cancel.
*/
~basic_writable_pipe()
{
}
/// Get the executor associated with the object.
const executor_type& get_executor() 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_writable_pipe 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
* is not transferred to the caller.
*/
lowest_layer_type& lowest_layer()
{
return *this;
}
/// 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_writable_pipe 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.
* Ownership is not transferred to the caller.
*/
const lowest_layer_type& lowest_layer() const
{
return *this;
}
/// Assign an existing native pipe to the pipe.
/*
* This function opens the pipe to hold an existing native pipe.
*
* @param native_pipe A native pipe.
*
* @throws boost::system::system_error Thrown on failure.
*/
void assign(const native_handle_type& native_pipe)
{
boost::system::error_code ec;
impl_.get_service().assign(impl_.get_implementation(), native_pipe, ec);
boost::asio::detail::throw_error(ec, "assign");
}
/// Assign an existing native pipe to the pipe.
/*
* This function opens the pipe to hold an existing native pipe.
*
* @param native_pipe A native pipe.
*
* @param ec Set to indicate what error occurred, if any.
*/
BOOST_ASIO_SYNC_OP_VOID assign(const native_handle_type& native_pipe,
boost::system::error_code& ec)
{
impl_.get_service().assign(impl_.get_implementation(), native_pipe, ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Determine whether the pipe is open.
bool is_open() const
{
return impl_.get_service().is_open(impl_.get_implementation());
}
/// Close the pipe.
/**
* This function is used to close the pipe. Any asynchronous write operations
* will be cancelled immediately, and will complete with the
* boost::asio::error::operation_aborted error.
*
* @throws boost::system::system_error Thrown on failure.
*/
void close()
{
boost::system::error_code ec;
impl_.get_service().close(impl_.get_implementation(), ec);
boost::asio::detail::throw_error(ec, "close");
}
/// Close the pipe.
/**
* This function is used to close the pipe. Any asynchronous write operations
* will be cancelled immediately, and will complete with the
* boost::asio::error::operation_aborted error.
*
* @param ec Set to indicate what error occurred, if any.
*/
BOOST_ASIO_SYNC_OP_VOID close(boost::system::error_code& ec)
{
impl_.get_service().close(impl_.get_implementation(), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Release ownership of the underlying native pipe.
/**
* This function causes all outstanding asynchronous write operations to
* finish immediately, and the handlers for cancelled operations will be
* passed the boost::asio::error::operation_aborted error. Ownership of the
* native pipe is then transferred to the caller.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note This function is unsupported on Windows versions prior to Windows
* 8.1, and will fail with boost::asio::error::operation_not_supported on
* these platforms.
*/
#if defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC >= 1400) \
&& (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0603)
__declspec(deprecated("This function always fails with "
"operation_not_supported when used on Windows versions "
"prior to Windows 8.1."))
#endif
native_handle_type release()
{
boost::system::error_code ec;
native_handle_type s = impl_.get_service().release(
impl_.get_implementation(), ec);
boost::asio::detail::throw_error(ec, "release");
return s;
}
/// Release ownership of the underlying native pipe.
/**
* This function causes all outstanding asynchronous write operations to
* finish immediately, and the handlers for cancelled operations will be
* passed the boost::asio::error::operation_aborted error. Ownership of the
* native pipe is then transferred to the caller.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note This function is unsupported on Windows versions prior to Windows
* 8.1, and will fail with boost::asio::error::operation_not_supported on
* these platforms.
*/
#if defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC >= 1400) \
&& (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0603)
__declspec(deprecated("This function always fails with "
"operation_not_supported when used on Windows versions "
"prior to Windows 8.1."))
#endif
native_handle_type release(boost::system::error_code& ec)
{
return impl_.get_service().release(impl_.get_implementation(), ec);
}
/// Get the native pipe representation.
/**
* This function may be used to obtain the underlying representation of the
* pipe. This is intended to allow access to native pipe
* functionality that is not otherwise provided.
*/
native_handle_type native_handle()
{
return impl_.get_service().native_handle(impl_.get_implementation());
}
/// Cancel all asynchronous operations associated with the pipe.
/**
* This function causes all outstanding asynchronous write operations to
* finish immediately, and the handlers for cancelled operations will be
* passed the boost::asio::error::operation_aborted error.
*
* @throws boost::system::system_error Thrown on failure.
*/
void cancel()
{
boost::system::error_code ec;
impl_.get_service().cancel(impl_.get_implementation(), ec);
boost::asio::detail::throw_error(ec, "cancel");
}
/// Cancel all asynchronous operations associated with the pipe.
/**
* This function causes all outstanding asynchronous write operations to
* finish immediately, and the handlers for cancelled operations will be
* passed the boost::asio::error::operation_aborted error.
*
* @param ec Set to indicate what error occurred, if any.
*/
BOOST_ASIO_SYNC_OP_VOID cancel(boost::system::error_code& ec)
{
impl_.get_service().cancel(impl_.get_implementation(), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Write some data to the pipe.
/**
* This function is used to write data to the pipe. The function call will
* block until one or more bytes of the data has been written successfully,
* or until an error occurs.
*
* @param buffers One or more data buffers to be written to the pipe.
*
* @returns The number of bytes written.
*
* @throws boost::system::system_error Thrown on failure. An error code of
* boost::asio::error::eof indicates that the connection was closed by the
* peer.
*
* @note The write_some operation may not transmit all of the data to the
* peer. Consider using the @ref write function if you need to ensure that
* all data is written before the blocking operation completes.
*
* @par Example
* To write a single data buffer use the @ref buffer function as follows:
* @code
* pipe.write_some(boost::asio::buffer(data, size));
* @endcode
* See the @ref buffer documentation for information on writing multiple
* buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*/
template <typename ConstBufferSequence>
std::size_t write_some(const ConstBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t s = impl_.get_service().write_some(
impl_.get_implementation(), buffers, ec);
boost::asio::detail::throw_error(ec, "write_some");
return s;
}
/// Write some data to the pipe.
/**
* This function is used to write data to the pipe. The function call will
* block until one or more bytes of the data has been written successfully,
* or until an error occurs.
*
* @param buffers One or more data buffers to be written to the pipe.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns The number of bytes written. Returns 0 if an error occurred.
*
* @note The write_some operation may not transmit all of the data to the
* peer. Consider using the @ref write function if you need to ensure that
* all data is written before the blocking operation completes.
*/
template <typename ConstBufferSequence>
std::size_t write_some(const ConstBufferSequence& buffers,
boost::system::error_code& ec)
{
return impl_.get_service().write_some(
impl_.get_implementation(), buffers, ec);
}
/// Start an asynchronous write.
/**
* This function is used to asynchronously write data to the pipe. It is an
* initiating function for an @ref asynchronous_operation, and always returns
* immediately.
*
* @param buffers One or more data buffers to be written to the pipe.
* Although the buffers object may be copied as necessary, ownership of the
* underlying memory blocks is retained by the caller, which must guarantee
* that they remain valid until the completion handler is called.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the write completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes written.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @note The write operation may not transmit all of the data to the peer.
* Consider using the @ref async_write function if you need to ensure that all
* data is written before the asynchronous operation completes.
*
* @par Example
* To write a single data buffer use the @ref buffer function as follows:
* @code
* pipe.async_write_some(boost::asio::buffer(data, size), handler);
* @endcode
* See the @ref buffer documentation for information on writing multiple
* buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*/
template <typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken = default_completion_token_t<executor_type>>
auto async_write_some(const ConstBufferSequence& buffers,
WriteToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_write_some>(), token, buffers))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_write_some(this), token, buffers);
}
private:
// Disallow copying and assignment.
basic_writable_pipe(const basic_writable_pipe&) = delete;
basic_writable_pipe& operator=(const basic_writable_pipe&) = delete;
class initiate_async_write_some
{
public:
typedef Executor executor_type;
explicit initiate_async_write_some(basic_writable_pipe* self)
: self_(self)
{
}
const executor_type& get_executor() const noexcept
{
return self_->get_executor();
}
template <typename WriteHandler, typename ConstBufferSequence>
void operator()(WriteHandler&& handler,
const ConstBufferSequence& buffers) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
detail::non_const_lvalue<WriteHandler> handler2(handler);
self_->impl_.get_service().async_write_some(
self_->impl_.get_implementation(), buffers,
handler2.value, self_->impl_.get_executor());
}
private:
basic_writable_pipe* self_;
};
#if defined(BOOST_ASIO_HAS_IOCP)
detail::io_object_impl<detail::win_iocp_handle_service, Executor> impl_;
#elif defined(BOOST_ASIO_HAS_IO_URING_AS_DEFAULT)
detail::io_object_impl<detail::io_uring_descriptor_service, Executor> impl_;
#else
detail::io_object_impl<detail::reactive_descriptor_service, Executor> impl_;
#endif
};
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // defined(BOOST_ASIO_HAS_PIPE)
// || defined(GENERATING_DOCUMENTATION)
#endif // BOOST_ASIO_BASIC_WRITABLE_PIPE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/static_thread_pool.hpp | //
// static_thread_pool.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_STATIC_THREAD_POOL_HPP
#define BOOST_ASIO_STATIC_THREAD_POOL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/thread_pool.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
typedef thread_pool static_thread_pool;
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_STATIC_THREAD_POOL_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/stream_file.hpp | //
// stream_file.hpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_STREAM_FILE_HPP
#define BOOST_ASIO_STREAM_FILE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HAS_FILE) \
|| defined(GENERATING_DOCUMENTATION)
#include <boost/asio/basic_stream_file.hpp>
namespace boost {
namespace asio {
/// Typedef for the typical usage of a stream-oriented file.
typedef basic_stream_file<> stream_file;
} // namespace asio
} // namespace boost
#endif // defined(BOOST_ASIO_HAS_FILE)
// || defined(GENERATING_DOCUMENTATION)
#endif // BOOST_ASIO_STREAM_FILE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/completion_condition.hpp | //
// completion_condition.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_COMPLETION_CONDITION_HPP
#define BOOST_ASIO_COMPLETION_CONDITION_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
// The default maximum number of bytes to transfer in a single operation.
enum default_max_transfer_size_t { default_max_transfer_size = 65536 };
// Adapt result of old-style completion conditions (which had a bool result
// where true indicated that the operation was complete).
inline std::size_t adapt_completion_condition_result(bool result)
{
return result ? 0 : default_max_transfer_size;
}
// Adapt result of current completion conditions (which have a size_t result
// where 0 means the operation is complete, and otherwise the result is the
// maximum number of bytes to transfer on the next underlying operation).
inline std::size_t adapt_completion_condition_result(std::size_t result)
{
return result;
}
class transfer_all_t
{
public:
typedef std::size_t result_type;
template <typename Error>
std::size_t operator()(const Error& err, std::size_t)
{
return !!err ? 0 : default_max_transfer_size;
}
};
class transfer_at_least_t
{
public:
typedef std::size_t result_type;
explicit transfer_at_least_t(std::size_t minimum)
: minimum_(minimum)
{
}
template <typename Error>
std::size_t operator()(const Error& err, std::size_t bytes_transferred)
{
return (!!err || bytes_transferred >= minimum_)
? 0 : default_max_transfer_size;
}
private:
std::size_t minimum_;
};
class transfer_exactly_t
{
public:
typedef std::size_t result_type;
explicit transfer_exactly_t(std::size_t size)
: size_(size)
{
}
template <typename Error>
std::size_t operator()(const Error& err, std::size_t bytes_transferred)
{
return (!!err || bytes_transferred >= size_) ? 0 :
(size_ - bytes_transferred < default_max_transfer_size
? size_ - bytes_transferred : std::size_t(default_max_transfer_size));
}
private:
std::size_t size_;
};
} // namespace detail
/**
* @defgroup completion_condition Completion Condition Function Objects
*
* Function objects used for determining when a read or write operation should
* complete.
*/
/*@{*/
/// Return a completion condition function object that indicates that a read or
/// write operation should continue until all of the data has been transferred,
/// or until an error occurs.
/**
* This function is used to create an object, of unspecified type, that meets
* CompletionCondition requirements.
*
* @par Example
* Reading until a buffer is full:
* @code
* boost::array<char, 128> buf;
* boost::system::error_code ec;
* std::size_t n = boost::asio::read(
* sock, boost::asio::buffer(buf),
* boost::asio::transfer_all(), ec);
* if (ec)
* {
* // An error occurred.
* }
* else
* {
* // n == 128
* }
* @endcode
*/
#if defined(GENERATING_DOCUMENTATION)
unspecified transfer_all();
#else
inline detail::transfer_all_t transfer_all()
{
return detail::transfer_all_t();
}
#endif
/// Return a completion condition function object that indicates that a read or
/// write operation should continue until a minimum number of bytes has been
/// transferred, or until an error occurs.
/**
* This function is used to create an object, of unspecified type, that meets
* CompletionCondition requirements.
*
* @par Example
* Reading until a buffer is full or contains at least 64 bytes:
* @code
* boost::array<char, 128> buf;
* boost::system::error_code ec;
* std::size_t n = boost::asio::read(
* sock, boost::asio::buffer(buf),
* boost::asio::transfer_at_least(64), ec);
* if (ec)
* {
* // An error occurred.
* }
* else
* {
* // n >= 64 && n <= 128
* }
* @endcode
*/
#if defined(GENERATING_DOCUMENTATION)
unspecified transfer_at_least(std::size_t minimum);
#else
inline detail::transfer_at_least_t transfer_at_least(std::size_t minimum)
{
return detail::transfer_at_least_t(minimum);
}
#endif
/// Return a completion condition function object that indicates that a read or
/// write operation should continue until an exact number of bytes has been
/// transferred, or until an error occurs.
/**
* This function is used to create an object, of unspecified type, that meets
* CompletionCondition requirements.
*
* @par Example
* Reading until a buffer is full or contains exactly 64 bytes:
* @code
* boost::array<char, 128> buf;
* boost::system::error_code ec;
* std::size_t n = boost::asio::read(
* sock, boost::asio::buffer(buf),
* boost::asio::transfer_exactly(64), ec);
* if (ec)
* {
* // An error occurred.
* }
* else
* {
* // n == 64
* }
* @endcode
*/
#if defined(GENERATING_DOCUMENTATION)
unspecified transfer_exactly(std::size_t size);
#else
inline detail::transfer_exactly_t transfer_exactly(std::size_t size)
{
return detail::transfer_exactly_t(size);
}
#endif
/*@}*/
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_COMPLETION_CONDITION_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/io_context.hpp | //
// io_context.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IO_CONTEXT_HPP
#define BOOST_ASIO_IO_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <stdexcept>
#include <typeinfo>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/chrono.hpp>
#include <boost/asio/detail/concurrency_hint.hpp>
#include <boost/asio/detail/cstdint.hpp>
#include <boost/asio/detail/wrapped_handler.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/execution.hpp>
#include <boost/asio/execution_context.hpp>
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
# include <boost/asio/detail/winsock_init.hpp>
#elif defined(__sun) || defined(__QNX__) || defined(__hpux) || defined(_AIX) \
|| defined(__osf__)
# include <boost/asio/detail/signal_init.hpp>
#endif
#if defined(BOOST_ASIO_HAS_IOCP)
# include <boost/asio/detail/win_iocp_io_context.hpp>
#else
# include <boost/asio/detail/scheduler.hpp>
#endif
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
#if defined(BOOST_ASIO_HAS_IOCP)
typedef win_iocp_io_context io_context_impl;
class win_iocp_overlapped_ptr;
#else
typedef scheduler io_context_impl;
#endif
struct io_context_bits
{
static constexpr uintptr_t blocking_never = 1;
static constexpr uintptr_t relationship_continuation = 2;
static constexpr uintptr_t outstanding_work_tracked = 4;
static constexpr uintptr_t runtime_bits = 3;
};
} // namespace detail
/// Provides core I/O functionality.
/**
* The io_context class provides the core I/O functionality for users of the
* asynchronous I/O objects, including:
*
* @li boost::asio::ip::tcp::socket
* @li boost::asio::ip::tcp::acceptor
* @li boost::asio::ip::udp::socket
* @li boost::asio::deadline_timer.
*
* The io_context class also includes facilities intended for developers of
* custom asynchronous services.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Safe, with the specific exceptions of the restart()
* and notify_fork() functions. Calling restart() while there are unfinished
* run(), run_one(), run_for(), run_until(), poll() or poll_one() calls results
* in undefined behaviour. The notify_fork() function should not be called
* while any io_context function, or any function on an I/O object that is
* associated with the io_context, is being called in another thread.
*
* @par Concepts:
* Dispatcher.
*
* @par Synchronous and asynchronous operations
*
* Synchronous operations on I/O objects implicitly run the io_context object
* for an individual operation. The io_context functions run(), run_one(),
* run_for(), run_until(), poll() or poll_one() must be called for the
* io_context to perform asynchronous operations on behalf of a C++ program.
* Notification that an asynchronous operation has completed is delivered by
* invocation of the associated handler. Handlers are invoked only by a thread
* that is currently calling any overload of run(), run_one(), run_for(),
* run_until(), poll() or poll_one() for the io_context.
*
* @par Effect of exceptions thrown from handlers
*
* If an exception is thrown from a handler, the exception is allowed to
* propagate through the throwing thread's invocation of run(), run_one(),
* run_for(), run_until(), poll() or poll_one(). No other threads that are
* calling any of these functions are affected. It is then the responsibility
* of the application to catch the exception.
*
* After the exception has been caught, the run(), run_one(), run_for(),
* run_until(), poll() or poll_one() call may be restarted @em without the need
* for an intervening call to restart(). This allows the thread to rejoin the
* io_context object's thread pool without impacting any other threads in the
* pool.
*
* For example:
*
* @code
* boost::asio::io_context io_context;
* ...
* for (;;)
* {
* try
* {
* io_context.run();
* break; // run() exited normally
* }
* catch (my_exception& e)
* {
* // Deal with exception as appropriate.
* }
* }
* @endcode
*
* @par Submitting arbitrary tasks to the io_context
*
* To submit functions to the io_context, use the @ref boost::asio::dispatch,
* @ref boost::asio::post or @ref boost::asio::defer free functions.
*
* For example:
*
* @code void my_task()
* {
* ...
* }
*
* ...
*
* boost::asio::io_context io_context;
*
* // Submit a function to the io_context.
* boost::asio::post(io_context, my_task);
*
* // Submit a lambda object to the io_context.
* boost::asio::post(io_context,
* []()
* {
* ...
* });
*
* // Run the io_context until it runs out of work.
* io_context.run(); @endcode
*
* @par Stopping the io_context from running out of work
*
* Some applications may need to prevent an io_context object's run() call from
* returning when there is no more work to do. For example, the io_context may
* be being run in a background thread that is launched prior to the
* application's asynchronous operations. The run() call may be kept running by
* using the @ref make_work_guard function to create an object of type
* boost::asio::executor_work_guard<io_context::executor_type>:
*
* @code boost::asio::io_context io_context;
* boost::asio::executor_work_guard<boost::asio::io_context::executor_type>
* = boost::asio::make_work_guard(io_context);
* ... @endcode
*
* To effect a shutdown, the application will then need to call the io_context
* object's stop() member function. This will cause the io_context run() call
* to return as soon as possible, abandoning unfinished operations and without
* permitting ready handlers to be dispatched.
*
* Alternatively, if the application requires that all operations and handlers
* be allowed to finish normally, the work object may be explicitly reset.
*
* @code boost::asio::io_context io_context;
* boost::asio::executor_work_guard<boost::asio::io_context::executor_type>
* = boost::asio::make_work_guard(io_context);
* ...
* work.reset(); // Allow run() to exit. @endcode
*/
class io_context
: public execution_context
{
private:
typedef detail::io_context_impl impl_type;
#if defined(BOOST_ASIO_HAS_IOCP)
friend class detail::win_iocp_overlapped_ptr;
#endif
#if !defined(BOOST_ASIO_NO_DEPRECATED)
struct initiate_dispatch;
struct initiate_post;
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
public:
template <typename Allocator, uintptr_t Bits>
class basic_executor_type;
template <typename Allocator, uintptr_t Bits>
friend class basic_executor_type;
/// Executor used to submit functions to an io_context.
typedef basic_executor_type<std::allocator<void>, 0> executor_type;
#if !defined(BOOST_ASIO_NO_DEPRECATED)
class work;
friend class work;
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
class service;
#if !defined(BOOST_ASIO_NO_EXTENSIONS) \
&& !defined(BOOST_ASIO_NO_TS_EXECUTORS)
class strand;
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
// && !defined(BOOST_ASIO_NO_TS_EXECUTORS)
/// The type used to count the number of handlers executed by the context.
typedef std::size_t count_type;
/// Constructor.
BOOST_ASIO_DECL io_context();
/// Constructor.
/**
* Construct with a hint about the required level of concurrency.
*
* @param concurrency_hint A suggestion to the implementation on how many
* threads it should allow to run simultaneously.
*/
BOOST_ASIO_DECL explicit io_context(int concurrency_hint);
/// Destructor.
/**
* On destruction, the io_context performs the following sequence of
* operations:
*
* @li For each service object @c svc in the io_context set, in reverse order
* of the beginning of service object lifetime, performs
* @c svc->shutdown().
*
* @li Uninvoked handler objects that were scheduled for deferred invocation
* on the io_context, or any associated strand, are destroyed.
*
* @li For each service object @c svc in the io_context set, in reverse order
* of the beginning of service object lifetime, performs
* <tt>delete static_cast<io_context::service*>(svc)</tt>.
*
* @note The destruction sequence described above permits programs to
* simplify their resource management by using @c shared_ptr<>. Where an
* object's lifetime is tied to the lifetime of a connection (or some other
* sequence of asynchronous operations), a @c shared_ptr to the object would
* be bound into the handlers for all asynchronous operations associated with
* it. This works as follows:
*
* @li When a single connection ends, all associated asynchronous operations
* complete. The corresponding handler objects are destroyed, and all
* @c shared_ptr references to the objects are destroyed.
*
* @li To shut down the whole program, the io_context function stop() is
* called to terminate any run() calls as soon as possible. The io_context
* destructor defined above destroys all handlers, causing all @c shared_ptr
* references to all connection objects to be destroyed.
*/
BOOST_ASIO_DECL ~io_context();
/// Obtains the executor associated with the io_context.
executor_type get_executor() noexcept;
/// Run the io_context object's event processing loop.
/**
* The run() function blocks until all work has finished and there are no
* more handlers to be dispatched, or until the io_context has been stopped.
*
* Multiple threads may call the run() function to set up a pool of threads
* from which the io_context may execute handlers. All threads that are
* waiting in the pool are equivalent and the io_context may choose any one
* of them to invoke a handler.
*
* A normal exit from the run() function implies that the io_context object
* is stopped (the stopped() function returns @c true). Subsequent calls to
* run(), run_one(), poll() or poll_one() will return immediately unless there
* is a prior call to restart().
*
* @return The number of handlers that were executed.
*
* @note Calling the run() function from a thread that is currently calling
* one of run(), run_one(), run_for(), run_until(), poll() or poll_one() on
* the same io_context object may introduce the potential for deadlock. It is
* the caller's reponsibility to avoid this.
*
* The poll() function may also be used to dispatch ready handlers, but
* without blocking.
*/
BOOST_ASIO_DECL count_type run();
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use non-error_code overload.) Run the io_context object's
/// event processing loop.
/**
* The run() function blocks until all work has finished and there are no
* more handlers to be dispatched, or until the io_context has been stopped.
*
* Multiple threads may call the run() function to set up a pool of threads
* from which the io_context may execute handlers. All threads that are
* waiting in the pool are equivalent and the io_context may choose any one
* of them to invoke a handler.
*
* A normal exit from the run() function implies that the io_context object
* is stopped (the stopped() function returns @c true). Subsequent calls to
* run(), run_one(), poll() or poll_one() will return immediately unless there
* is a prior call to restart().
*
* @param ec Set to indicate what error occurred, if any.
*
* @return The number of handlers that were executed.
*
* @note Calling the run() function from a thread that is currently calling
* one of run(), run_one(), run_for(), run_until(), poll() or poll_one() on
* the same io_context object may introduce the potential for deadlock. It is
* the caller's reponsibility to avoid this.
*
* The poll() function may also be used to dispatch ready handlers, but
* without blocking.
*/
BOOST_ASIO_DECL count_type run(boost::system::error_code& ec);
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Run the io_context object's event processing loop for a specified
/// duration.
/**
* The run_for() function blocks until all work has finished and there are no
* more handlers to be dispatched, until the io_context has been stopped, or
* until the specified duration has elapsed.
*
* @param rel_time The duration for which the call may block.
*
* @return The number of handlers that were executed.
*/
template <typename Rep, typename Period>
std::size_t run_for(const chrono::duration<Rep, Period>& rel_time);
/// Run the io_context object's event processing loop until a specified time.
/**
* The run_until() function blocks until all work has finished and there are
* no more handlers to be dispatched, until the io_context has been stopped,
* or until the specified time has been reached.
*
* @param abs_time The time point until which the call may block.
*
* @return The number of handlers that were executed.
*/
template <typename Clock, typename Duration>
std::size_t run_until(const chrono::time_point<Clock, Duration>& abs_time);
/// Run the io_context object's event processing loop to execute at most one
/// handler.
/**
* The run_one() function blocks until one handler has been dispatched, or
* until the io_context has been stopped.
*
* @return The number of handlers that were executed. A zero return value
* implies that the io_context object is stopped (the stopped() function
* returns @c true). Subsequent calls to run(), run_one(), poll() or
* poll_one() will return immediately unless there is a prior call to
* restart().
*
* @note Calling the run_one() function from a thread that is currently
* calling one of run(), run_one(), run_for(), run_until(), poll() or
* poll_one() on the same io_context object may introduce the potential for
* deadlock. It is the caller's reponsibility to avoid this.
*/
BOOST_ASIO_DECL count_type run_one();
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use non-error_code overload.) Run the io_context object's
/// event processing loop to execute at most one handler.
/**
* The run_one() function blocks until one handler has been dispatched, or
* until the io_context has been stopped.
*
* @return The number of handlers that were executed. A zero return value
* implies that the io_context object is stopped (the stopped() function
* returns @c true). Subsequent calls to run(), run_one(), poll() or
* poll_one() will return immediately unless there is a prior call to
* restart().
*
* @return The number of handlers that were executed.
*
* @note Calling the run_one() function from a thread that is currently
* calling one of run(), run_one(), run_for(), run_until(), poll() or
* poll_one() on the same io_context object may introduce the potential for
* deadlock. It is the caller's reponsibility to avoid this.
*/
BOOST_ASIO_DECL count_type run_one(boost::system::error_code& ec);
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Run the io_context object's event processing loop for a specified duration
/// to execute at most one handler.
/**
* The run_one_for() function blocks until one handler has been dispatched,
* until the io_context has been stopped, or until the specified duration has
* elapsed.
*
* @param rel_time The duration for which the call may block.
*
* @return The number of handlers that were executed.
*/
template <typename Rep, typename Period>
std::size_t run_one_for(const chrono::duration<Rep, Period>& rel_time);
/// Run the io_context object's event processing loop until a specified time
/// to execute at most one handler.
/**
* The run_one_until() function blocks until one handler has been dispatched,
* until the io_context has been stopped, or until the specified time has
* been reached.
*
* @param abs_time The time point until which the call may block.
*
* @return The number of handlers that were executed.
*/
template <typename Clock, typename Duration>
std::size_t run_one_until(
const chrono::time_point<Clock, Duration>& abs_time);
/// Run the io_context object's event processing loop to execute ready
/// handlers.
/**
* The poll() function runs handlers that are ready to run, without blocking,
* until the io_context has been stopped or there are no more ready handlers.
*
* @return The number of handlers that were executed.
*/
BOOST_ASIO_DECL count_type poll();
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use non-error_code overload.) Run the io_context object's
/// event processing loop to execute ready handlers.
/**
* The poll() function runs handlers that are ready to run, without blocking,
* until the io_context has been stopped or there are no more ready handlers.
*
* @param ec Set to indicate what error occurred, if any.
*
* @return The number of handlers that were executed.
*/
BOOST_ASIO_DECL count_type poll(boost::system::error_code& ec);
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Run the io_context object's event processing loop to execute one ready
/// handler.
/**
* The poll_one() function runs at most one handler that is ready to run,
* without blocking.
*
* @return The number of handlers that were executed.
*/
BOOST_ASIO_DECL count_type poll_one();
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use non-error_code overload.) Run the io_context object's
/// event processing loop to execute one ready handler.
/**
* The poll_one() function runs at most one handler that is ready to run,
* without blocking.
*
* @param ec Set to indicate what error occurred, if any.
*
* @return The number of handlers that were executed.
*/
BOOST_ASIO_DECL count_type poll_one(boost::system::error_code& ec);
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Stop the io_context object's event processing loop.
/**
* This function does not block, but instead simply signals the io_context to
* stop. All invocations of its run() or run_one() member functions should
* return as soon as possible. Subsequent calls to run(), run_one(), poll()
* or poll_one() will return immediately until restart() is called.
*/
BOOST_ASIO_DECL void stop();
/// Determine whether the io_context object has been stopped.
/**
* This function is used to determine whether an io_context object has been
* stopped, either through an explicit call to stop(), or due to running out
* of work. When an io_context object is stopped, calls to run(), run_one(),
* poll() or poll_one() will return immediately without invoking any
* handlers.
*
* @return @c true if the io_context object is stopped, otherwise @c false.
*/
BOOST_ASIO_DECL bool stopped() const;
/// Restart the io_context in preparation for a subsequent run() invocation.
/**
* This function must be called prior to any second or later set of
* invocations of the run(), run_one(), poll() or poll_one() functions when a
* previous invocation of these functions returned due to the io_context
* being stopped or running out of work. After a call to restart(), the
* io_context object's stopped() function will return @c false.
*
* This function must not be called while there are any unfinished calls to
* the run(), run_one(), poll() or poll_one() functions.
*/
BOOST_ASIO_DECL void restart();
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use restart().) Reset the io_context in preparation for a
/// subsequent run() invocation.
/**
* This function must be called prior to any second or later set of
* invocations of the run(), run_one(), poll() or poll_one() functions when a
* previous invocation of these functions returned due to the io_context
* being stopped or running out of work. After a call to restart(), the
* io_context object's stopped() function will return @c false.
*
* This function must not be called while there are any unfinished calls to
* the run(), run_one(), poll() or poll_one() functions.
*/
void reset();
/// (Deprecated: Use boost::asio::dispatch().) Request the io_context to
/// invoke the given handler.
/**
* This function is used to ask the io_context to execute the given handler.
*
* The io_context guarantees that the handler will only be called in a thread
* in which the run(), run_one(), poll() or poll_one() member functions is
* currently being invoked. The handler may be executed inside this function
* if the guarantee can be met.
*
* @param handler The handler to be called. The io_context will make
* a copy of the handler object as required. The function signature of the
* handler must be: @code void handler(); @endcode
*
* @note This function throws an exception only if:
*
* @li the handler's associated allocator; or
*
* @li the handler's copy constructor
*
* throws an exception.
*/
template <typename LegacyCompletionHandler>
auto dispatch(LegacyCompletionHandler&& handler)
-> decltype(
async_initiate<LegacyCompletionHandler, void ()>(
declval<initiate_dispatch>(), handler, this));
/// (Deprecated: Use boost::asio::post().) Request the io_context to invoke
/// the given handler and return immediately.
/**
* This function is used to ask the io_context to execute the given handler,
* but without allowing the io_context to call the handler from inside this
* function.
*
* The io_context guarantees that the handler will only be called in a thread
* in which the run(), run_one(), poll() or poll_one() member functions is
* currently being invoked.
*
* @param handler The handler to be called. The io_context will make
* a copy of the handler object as required. The function signature of the
* handler must be: @code void handler(); @endcode
*
* @note This function throws an exception only if:
*
* @li the handler's associated allocator; or
*
* @li the handler's copy constructor
*
* throws an exception.
*/
template <typename LegacyCompletionHandler>
auto post(LegacyCompletionHandler&& handler)
-> decltype(
async_initiate<LegacyCompletionHandler, void ()>(
declval<initiate_post>(), handler, this));
/// (Deprecated: Use boost::asio::bind_executor().) Create a new handler that
/// automatically dispatches the wrapped handler on the io_context.
/**
* This function is used to create a new handler function object that, when
* invoked, will automatically pass the wrapped handler to the io_context
* object's dispatch function.
*
* @param handler The handler to be wrapped. The io_context will make a copy
* of the handler object as required. The function signature of the handler
* must be: @code void handler(A1 a1, ... An an); @endcode
*
* @return A function object that, when invoked, passes the wrapped handler to
* the io_context object's dispatch function. Given a function object with the
* signature:
* @code R f(A1 a1, ... An an); @endcode
* If this function object is passed to the wrap function like so:
* @code io_context.wrap(f); @endcode
* then the return value is a function object with the signature
* @code void g(A1 a1, ... An an); @endcode
* that, when invoked, executes code equivalent to:
* @code io_context.dispatch(boost::bind(f, a1, ... an)); @endcode
*/
template <typename Handler>
#if defined(GENERATING_DOCUMENTATION)
unspecified
#else
detail::wrapped_handler<io_context&, Handler>
#endif
wrap(Handler handler);
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
private:
io_context(const io_context&) = delete;
io_context& operator=(const io_context&) = delete;
// Helper function to add the implementation.
BOOST_ASIO_DECL impl_type& add_impl(impl_type* impl);
// Backwards compatible overload for use with services derived from
// io_context::service.
template <typename Service>
friend Service& use_service(io_context& ioc);
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
detail::winsock_init<> init_;
#elif defined(__sun) || defined(__QNX__) || defined(__hpux) || defined(_AIX) \
|| defined(__osf__)
detail::signal_init<> init_;
#endif
// The implementation.
impl_type& impl_;
};
namespace detail {
} // namespace detail
/// Executor implementation type used to submit functions to an io_context.
template <typename Allocator, uintptr_t Bits>
class io_context::basic_executor_type :
detail::io_context_bits, Allocator
{
public:
/// Copy constructor.
basic_executor_type(const basic_executor_type& other) noexcept
: Allocator(static_cast<const Allocator&>(other)),
target_(other.target_)
{
if (Bits & outstanding_work_tracked)
if (context_ptr())
context_ptr()->impl_.work_started();
}
/// Move constructor.
basic_executor_type(basic_executor_type&& other) noexcept
: Allocator(static_cast<Allocator&&>(other)),
target_(other.target_)
{
if (Bits & outstanding_work_tracked)
other.target_ = 0;
}
/// Destructor.
~basic_executor_type() noexcept
{
if (Bits & outstanding_work_tracked)
if (context_ptr())
context_ptr()->impl_.work_finished();
}
/// Assignment operator.
basic_executor_type& operator=(const basic_executor_type& other) noexcept;
/// Move assignment operator.
basic_executor_type& operator=(basic_executor_type&& other) noexcept;
#if !defined(GENERATING_DOCUMENTATION)
private:
friend struct boost_asio_require_fn::impl;
friend struct boost_asio_prefer_fn::impl;
#endif // !defined(GENERATING_DOCUMENTATION)
/// Obtain an executor with the @c blocking.possibly property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::require customisation point.
*
* For example:
* @code auto ex1 = my_io_context.get_executor();
* auto ex2 = boost::asio::require(ex1,
* boost::asio::execution::blocking.possibly); @endcode
*/
constexpr basic_executor_type require(execution::blocking_t::possibly_t) const
{
return basic_executor_type(context_ptr(),
*this, bits() & ~blocking_never);
}
/// Obtain an executor with the @c blocking.never property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::require customisation point.
*
* For example:
* @code auto ex1 = my_io_context.get_executor();
* auto ex2 = boost::asio::require(ex1,
* boost::asio::execution::blocking.never); @endcode
*/
constexpr basic_executor_type require(execution::blocking_t::never_t) const
{
return basic_executor_type(context_ptr(),
*this, bits() | blocking_never);
}
/// Obtain an executor with the @c relationship.fork property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::require customisation point.
*
* For example:
* @code auto ex1 = my_io_context.get_executor();
* auto ex2 = boost::asio::require(ex1,
* boost::asio::execution::relationship.fork); @endcode
*/
constexpr basic_executor_type require(execution::relationship_t::fork_t) const
{
return basic_executor_type(context_ptr(),
*this, bits() & ~relationship_continuation);
}
/// Obtain an executor with the @c relationship.continuation property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::require customisation point.
*
* For example:
* @code auto ex1 = my_io_context.get_executor();
* auto ex2 = boost::asio::require(ex1,
* boost::asio::execution::relationship.continuation); @endcode
*/
constexpr basic_executor_type require(
execution::relationship_t::continuation_t) const
{
return basic_executor_type(context_ptr(),
*this, bits() | relationship_continuation);
}
/// Obtain an executor with the @c outstanding_work.tracked property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::require customisation point.
*
* For example:
* @code auto ex1 = my_io_context.get_executor();
* auto ex2 = boost::asio::require(ex1,
* boost::asio::execution::outstanding_work.tracked); @endcode
*/
constexpr basic_executor_type<Allocator,
BOOST_ASIO_UNSPECIFIED(Bits | outstanding_work_tracked)>
require(execution::outstanding_work_t::tracked_t) const
{
return basic_executor_type<Allocator, Bits | outstanding_work_tracked>(
context_ptr(), *this, bits());
}
/// Obtain an executor with the @c outstanding_work.untracked property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::require customisation point.
*
* For example:
* @code auto ex1 = my_io_context.get_executor();
* auto ex2 = boost::asio::require(ex1,
* boost::asio::execution::outstanding_work.untracked); @endcode
*/
constexpr basic_executor_type<Allocator,
BOOST_ASIO_UNSPECIFIED(Bits & ~outstanding_work_tracked)>
require(execution::outstanding_work_t::untracked_t) const
{
return basic_executor_type<Allocator, Bits & ~outstanding_work_tracked>(
context_ptr(), *this, bits());
}
/// Obtain an executor with the specified @c allocator property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::require customisation point.
*
* For example:
* @code auto ex1 = my_io_context.get_executor();
* auto ex2 = boost::asio::require(ex1,
* boost::asio::execution::allocator(my_allocator)); @endcode
*/
template <typename OtherAllocator>
constexpr basic_executor_type<OtherAllocator, Bits>
require(execution::allocator_t<OtherAllocator> a) const
{
return basic_executor_type<OtherAllocator, Bits>(
context_ptr(), a.value(), bits());
}
/// Obtain an executor with the default @c allocator property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::require customisation point.
*
* For example:
* @code auto ex1 = my_io_context.get_executor();
* auto ex2 = boost::asio::require(ex1,
* boost::asio::execution::allocator); @endcode
*/
constexpr basic_executor_type<std::allocator<void>, Bits>
require(execution::allocator_t<void>) const
{
return basic_executor_type<std::allocator<void>, Bits>(
context_ptr(), std::allocator<void>(), bits());
}
#if !defined(GENERATING_DOCUMENTATION)
private:
friend struct boost_asio_query_fn::impl;
friend struct boost::asio::execution::detail::mapping_t<0>;
friend struct boost::asio::execution::detail::outstanding_work_t<0>;
#endif // !defined(GENERATING_DOCUMENTATION)
/// Query the current value of the @c mapping property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::query customisation point.
*
* For example:
* @code auto ex = my_io_context.get_executor();
* if (boost::asio::query(ex, boost::asio::execution::mapping)
* == boost::asio::execution::mapping.thread)
* ... @endcode
*/
static constexpr execution::mapping_t query(execution::mapping_t) noexcept
{
return execution::mapping.thread;
}
/// Query the current value of the @c context property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::query customisation point.
*
* For example:
* @code auto ex = my_io_context.get_executor();
* boost::asio::io_context& ctx = boost::asio::query(
* ex, boost::asio::execution::context); @endcode
*/
io_context& query(execution::context_t) const noexcept
{
return *context_ptr();
}
/// Query the current value of the @c blocking property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::query customisation point.
*
* For example:
* @code auto ex = my_io_context.get_executor();
* if (boost::asio::query(ex, boost::asio::execution::blocking)
* == boost::asio::execution::blocking.always)
* ... @endcode
*/
constexpr execution::blocking_t query(execution::blocking_t) const noexcept
{
return (bits() & blocking_never)
? execution::blocking_t(execution::blocking.never)
: execution::blocking_t(execution::blocking.possibly);
}
/// Query the current value of the @c relationship property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::query customisation point.
*
* For example:
* @code auto ex = my_io_context.get_executor();
* if (boost::asio::query(ex, boost::asio::execution::relationship)
* == boost::asio::execution::relationship.continuation)
* ... @endcode
*/
constexpr execution::relationship_t query(
execution::relationship_t) const noexcept
{
return (bits() & relationship_continuation)
? execution::relationship_t(execution::relationship.continuation)
: execution::relationship_t(execution::relationship.fork);
}
/// Query the current value of the @c outstanding_work property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::query customisation point.
*
* For example:
* @code auto ex = my_io_context.get_executor();
* if (boost::asio::query(ex, boost::asio::execution::outstanding_work)
* == boost::asio::execution::outstanding_work.tracked)
* ... @endcode
*/
static constexpr execution::outstanding_work_t query(
execution::outstanding_work_t) noexcept
{
return (Bits & outstanding_work_tracked)
? execution::outstanding_work_t(execution::outstanding_work.tracked)
: execution::outstanding_work_t(execution::outstanding_work.untracked);
}
/// Query the current value of the @c allocator property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::query customisation point.
*
* For example:
* @code auto ex = my_io_context.get_executor();
* auto alloc = boost::asio::query(ex,
* boost::asio::execution::allocator); @endcode
*/
template <typename OtherAllocator>
constexpr Allocator query(
execution::allocator_t<OtherAllocator>) const noexcept
{
return static_cast<const Allocator&>(*this);
}
/// Query the current value of the @c allocator property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::query customisation point.
*
* For example:
* @code auto ex = my_io_context.get_executor();
* auto alloc = boost::asio::query(ex,
* boost::asio::execution::allocator); @endcode
*/
constexpr Allocator query(execution::allocator_t<void>) const noexcept
{
return static_cast<const Allocator&>(*this);
}
public:
/// Determine whether the io_context is running in the current thread.
/**
* @return @c true if the current thread is running the io_context. Otherwise
* returns @c false.
*/
bool running_in_this_thread() const noexcept;
/// Compare two executors for equality.
/**
* Two executors are equal if they refer to the same underlying io_context.
*/
friend bool operator==(const basic_executor_type& a,
const basic_executor_type& b) noexcept
{
return a.target_ == b.target_
&& static_cast<const Allocator&>(a) == static_cast<const Allocator&>(b);
}
/// Compare two executors for inequality.
/**
* Two executors are equal if they refer to the same underlying io_context.
*/
friend bool operator!=(const basic_executor_type& a,
const basic_executor_type& b) noexcept
{
return a.target_ != b.target_
|| static_cast<const Allocator&>(a) != static_cast<const Allocator&>(b);
}
/// Execution function.
template <typename Function>
void execute(Function&& f) const;
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
public:
/// Obtain the underlying execution context.
io_context& context() const noexcept;
/// Inform the io_context that it has some outstanding work to do.
/**
* This function is used to inform the io_context that some work has begun.
* This ensures that the io_context's run() and run_one() functions do not
* exit while the work is underway.
*/
void on_work_started() const noexcept;
/// Inform the io_context that some work is no longer outstanding.
/**
* This function is used to inform the io_context that some work has
* finished. Once the count of unfinished work reaches zero, the io_context
* is stopped and the run() and run_one() functions may exit.
*/
void on_work_finished() const noexcept;
/// Request the io_context to invoke the given function object.
/**
* This function is used to ask the io_context to execute the given function
* object. If the current thread is running the io_context, @c dispatch()
* executes the function before returning. Otherwise, the function will be
* scheduled to run on the io_context.
*
* @param f The function object to be called. The executor will make a copy
* of the handler object as required. The function signature of the function
* object must be: @code void function(); @endcode
*
* @param a An allocator that may be used by the executor to allocate the
* internal storage needed for function invocation.
*/
template <typename Function, typename OtherAllocator>
void dispatch(Function&& f, const OtherAllocator& a) const;
/// Request the io_context to invoke the given function object.
/**
* This function is used to ask the io_context to execute the given function
* object. The function object will never be executed inside @c post().
* Instead, it will be scheduled to run on the io_context.
*
* @param f The function object to be called. The executor will make a copy
* of the handler object as required. The function signature of the function
* object must be: @code void function(); @endcode
*
* @param a An allocator that may be used by the executor to allocate the
* internal storage needed for function invocation.
*/
template <typename Function, typename OtherAllocator>
void post(Function&& f, const OtherAllocator& a) const;
/// Request the io_context to invoke the given function object.
/**
* This function is used to ask the io_context to execute the given function
* object. The function object will never be executed inside @c defer().
* Instead, it will be scheduled to run on the io_context.
*
* If the current thread belongs to the io_context, @c defer() will delay
* scheduling the function object until the current thread returns control to
* the pool.
*
* @param f The function object to be called. The executor will make a copy
* of the handler object as required. The function signature of the function
* object must be: @code void function(); @endcode
*
* @param a An allocator that may be used by the executor to allocate the
* internal storage needed for function invocation.
*/
template <typename Function, typename OtherAllocator>
void defer(Function&& f, const OtherAllocator& a) const;
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
private:
friend class io_context;
template <typename, uintptr_t> friend class basic_executor_type;
// Constructor used by io_context::get_executor().
explicit basic_executor_type(io_context& i) noexcept
: Allocator(),
target_(reinterpret_cast<uintptr_t>(&i))
{
if (Bits & outstanding_work_tracked)
context_ptr()->impl_.work_started();
}
// Constructor used by require().
basic_executor_type(io_context* i,
const Allocator& a, uintptr_t bits) noexcept
: Allocator(a),
target_(reinterpret_cast<uintptr_t>(i) | bits)
{
if (Bits & outstanding_work_tracked)
if (context_ptr())
context_ptr()->impl_.work_started();
}
io_context* context_ptr() const noexcept
{
return reinterpret_cast<io_context*>(target_ & ~runtime_bits);
}
uintptr_t bits() const noexcept
{
return target_ & runtime_bits;
}
// The underlying io_context and runtime bits.
uintptr_t target_;
};
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use executor_work_guard.) Class to inform the io_context when
/// it has work to do.
/**
* The work class is used to inform the io_context when work starts and
* finishes. This ensures that the io_context object's run() function will not
* exit while work is underway, and that it does exit when there is no
* unfinished work remaining.
*
* The work class is copy-constructible so that it may be used as a data member
* in a handler class. It is not assignable.
*/
class io_context::work
{
public:
/// Constructor notifies the io_context that work is starting.
/**
* The constructor is used to inform the io_context that some work has begun.
* This ensures that the io_context object's run() function will not exit
* while the work is underway.
*/
explicit work(boost::asio::io_context& io_context);
/// Copy constructor notifies the io_context that work is starting.
/**
* The constructor is used to inform the io_context that some work has begun.
* This ensures that the io_context object's run() function will not exit
* while the work is underway.
*/
work(const work& other);
/// Destructor notifies the io_context that the work is complete.
/**
* The destructor is used to inform the io_context that some work has
* finished. Once the count of unfinished work reaches zero, the io_context
* object's run() function is permitted to exit.
*/
~work();
/// Get the io_context associated with the work.
boost::asio::io_context& get_io_context();
private:
// Prevent assignment.
void operator=(const work& other);
// The io_context implementation.
detail::io_context_impl& io_context_impl_;
};
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Base class for all io_context services.
class io_context::service
: public execution_context::service
{
public:
/// Get the io_context object that owns the service.
boost::asio::io_context& get_io_context();
private:
/// Destroy all user-defined handler objects owned by the service.
BOOST_ASIO_DECL virtual void shutdown();
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use shutdown().) Destroy all user-defined handler objects
/// owned by the service.
BOOST_ASIO_DECL virtual void shutdown_service();
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
/// Handle notification of a fork-related event to perform any necessary
/// housekeeping.
/**
* This function is not a pure virtual so that services only have to
* implement it if necessary. The default implementation does nothing.
*/
BOOST_ASIO_DECL virtual void notify_fork(
execution_context::fork_event event);
#if !defined(BOOST_ASIO_NO_DEPRECATED)
/// (Deprecated: Use notify_fork().) Handle notification of a fork-related
/// event to perform any necessary housekeeping.
/**
* This function is not a pure virtual so that services only have to
* implement it if necessary. The default implementation does nothing.
*/
BOOST_ASIO_DECL virtual void fork_service(
execution_context::fork_event event);
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
protected:
/// Constructor.
/**
* @param owner The io_context object that owns the service.
*/
BOOST_ASIO_DECL service(boost::asio::io_context& owner);
/// Destructor.
BOOST_ASIO_DECL virtual ~service();
};
namespace detail {
// Special service base class to keep classes header-file only.
template <typename Type>
class service_base
: public boost::asio::io_context::service
{
public:
static boost::asio::detail::service_id<Type> id;
// Constructor.
service_base(boost::asio::io_context& io_context)
: boost::asio::io_context::service(io_context)
{
}
};
template <typename Type>
boost::asio::detail::service_id<Type> service_base<Type>::id;
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <typename Allocator, uintptr_t Bits>
struct equality_comparable<
boost::asio::io_context::basic_executor_type<Allocator, Bits>
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename Allocator, uintptr_t Bits, typename Function>
struct execute_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
Function
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
template <typename Allocator, uintptr_t Bits>
struct require_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
boost::asio::execution::blocking_t::possibly_t
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef boost::asio::io_context::basic_executor_type<
Allocator, Bits> result_type;
};
template <typename Allocator, uintptr_t Bits>
struct require_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
boost::asio::execution::blocking_t::never_t
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef boost::asio::io_context::basic_executor_type<
Allocator, Bits> result_type;
};
template <typename Allocator, uintptr_t Bits>
struct require_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
boost::asio::execution::relationship_t::fork_t
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef boost::asio::io_context::basic_executor_type<
Allocator, Bits> result_type;
};
template <typename Allocator, uintptr_t Bits>
struct require_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
boost::asio::execution::relationship_t::continuation_t
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef boost::asio::io_context::basic_executor_type<
Allocator, Bits> result_type;
};
template <typename Allocator, uintptr_t Bits>
struct require_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
boost::asio::execution::outstanding_work_t::tracked_t
> : boost::asio::detail::io_context_bits
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef boost::asio::io_context::basic_executor_type<
Allocator, Bits | outstanding_work_tracked> result_type;
};
template <typename Allocator, uintptr_t Bits>
struct require_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
boost::asio::execution::outstanding_work_t::untracked_t
> : boost::asio::detail::io_context_bits
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef boost::asio::io_context::basic_executor_type<
Allocator, Bits & ~outstanding_work_tracked> result_type;
};
template <typename Allocator, uintptr_t Bits>
struct require_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
boost::asio::execution::allocator_t<void>
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef boost::asio::io_context::basic_executor_type<
std::allocator<void>, Bits> result_type;
};
template <uintptr_t Bits,
typename Allocator, typename OtherAllocator>
struct require_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
boost::asio::execution::allocator_t<OtherAllocator>
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef boost::asio::io_context::basic_executor_type<
OtherAllocator, Bits> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
template <typename Allocator, uintptr_t Bits, typename Property>
struct query_static_constexpr_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
Property,
typename boost::asio::enable_if<
boost::asio::is_convertible<
Property,
boost::asio::execution::outstanding_work_t
>::value
>::type
> : boost::asio::detail::io_context_bits
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef boost::asio::execution::outstanding_work_t result_type;
static constexpr result_type value() noexcept
{
return (Bits & outstanding_work_tracked)
? execution::outstanding_work_t(execution::outstanding_work.tracked)
: execution::outstanding_work_t(execution::outstanding_work.untracked);
}
};
template <typename Allocator, uintptr_t Bits, typename Property>
struct query_static_constexpr_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
Property,
typename boost::asio::enable_if<
boost::asio::is_convertible<
Property,
boost::asio::execution::mapping_t
>::value
>::type
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef boost::asio::execution::mapping_t::thread_t result_type;
static constexpr result_type value() noexcept
{
return result_type();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
template <typename Allocator, uintptr_t Bits, typename Property>
struct query_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
Property,
typename boost::asio::enable_if<
boost::asio::is_convertible<
Property,
boost::asio::execution::blocking_t
>::value
>::type
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef boost::asio::execution::blocking_t result_type;
};
template <typename Allocator, uintptr_t Bits, typename Property>
struct query_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
Property,
typename boost::asio::enable_if<
boost::asio::is_convertible<
Property,
boost::asio::execution::relationship_t
>::value
>::type
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef boost::asio::execution::relationship_t result_type;
};
template <typename Allocator, uintptr_t Bits>
struct query_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
boost::asio::execution::context_t
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef boost::asio::io_context& result_type;
};
template <typename Allocator, uintptr_t Bits>
struct query_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
boost::asio::execution::allocator_t<void>
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef Allocator result_type;
};
template <typename Allocator, uintptr_t Bits, typename OtherAllocator>
struct query_member<
boost::asio::io_context::basic_executor_type<Allocator, Bits>,
boost::asio::execution::allocator_t<OtherAllocator>
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef Allocator result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
} // namespace traits
namespace execution {
template <>
struct is_executor<io_context> : false_type
{
};
} // namespace execution
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/impl/io_context.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/impl/io_context.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
// If both io_context.hpp and strand.hpp have been included, automatically
// include the header file needed for the io_context::strand class.
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
# if defined(BOOST_ASIO_STRAND_HPP)
# include <boost/asio/io_context_strand.hpp>
# endif // defined(BOOST_ASIO_STRAND_HPP)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
#endif // BOOST_ASIO_IO_CONTEXT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/wait_traits.hpp | //
// wait_traits.hpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_WAIT_TRAITS_HPP
#define BOOST_ASIO_WAIT_TRAITS_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
/// Wait traits suitable for use with the basic_waitable_timer class template.
template <typename Clock>
struct wait_traits
{
/// Convert a clock duration into a duration used for waiting.
/**
* @returns @c d.
*/
static typename Clock::duration to_wait_duration(
const typename Clock::duration& d)
{
return d;
}
/// Convert a clock duration into a duration used for waiting.
/**
* @returns @c d.
*/
static typename Clock::duration to_wait_duration(
const typename Clock::time_point& t)
{
typename Clock::time_point now = Clock::now();
if (now + (Clock::duration::max)() < t)
return (Clock::duration::max)();
if (now + (Clock::duration::min)() > t)
return (Clock::duration::min)();
return t - now;
}
};
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_WAIT_TRAITS_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/streambuf.hpp | //
// streambuf.hpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_STREAMBUF_HPP
#define BOOST_ASIO_STREAMBUF_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_NO_IOSTREAM)
#include <boost/asio/basic_streambuf.hpp>
namespace boost {
namespace asio {
/// Typedef for the typical usage of basic_streambuf.
typedef basic_streambuf<> streambuf;
} // namespace asio
} // namespace boost
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // BOOST_ASIO_STREAMBUF_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/awaitable.hpp | //
// awaitable.hpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_AWAITABLE_HPP
#define BOOST_ASIO_AWAITABLE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
#if defined(BOOST_ASIO_HAS_STD_COROUTINE)
# include <coroutine>
#else // defined(BOOST_ASIO_HAS_STD_COROUTINE)
# include <experimental/coroutine>
#endif // defined(BOOST_ASIO_HAS_STD_COROUTINE)
#include <utility>
#include <boost/asio/any_io_executor.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
#if defined(BOOST_ASIO_HAS_STD_COROUTINE)
using std::coroutine_handle;
using std::suspend_always;
#else // defined(BOOST_ASIO_HAS_STD_COROUTINE)
using std::experimental::coroutine_handle;
using std::experimental::suspend_always;
#endif // defined(BOOST_ASIO_HAS_STD_COROUTINE)
template <typename> class awaitable_thread;
template <typename, typename> class awaitable_frame;
} // namespace detail
/// The return type of a coroutine or asynchronous operation.
template <typename T, typename Executor = any_io_executor>
class BOOST_ASIO_NODISCARD awaitable
{
public:
/// The type of the awaited value.
typedef T value_type;
/// The executor type that will be used for the coroutine.
typedef Executor executor_type;
/// Default constructor.
constexpr awaitable() noexcept
: frame_(nullptr)
{
}
/// Move constructor.
awaitable(awaitable&& other) noexcept
: frame_(std::exchange(other.frame_, nullptr))
{
}
/// Destructor
~awaitable()
{
if (frame_)
frame_->destroy();
}
/// Move assignment.
awaitable& operator=(awaitable&& other) noexcept
{
if (this != &other)
frame_ = std::exchange(other.frame_, nullptr);
return *this;
}
/// Checks if the awaitable refers to a future result.
bool valid() const noexcept
{
return !!frame_;
}
#if !defined(GENERATING_DOCUMENTATION)
// Support for co_await keyword.
bool await_ready() const noexcept
{
return false;
}
// Support for co_await keyword.
template <class U>
void await_suspend(
detail::coroutine_handle<detail::awaitable_frame<U, Executor>> h)
{
frame_->push_frame(&h.promise());
}
// Support for co_await keyword.
T await_resume()
{
return awaitable(static_cast<awaitable&&>(*this)).frame_->get();
}
#endif // !defined(GENERATING_DOCUMENTATION)
private:
template <typename> friend class detail::awaitable_thread;
template <typename, typename> friend class detail::awaitable_frame;
// Not copy constructible or copy assignable.
awaitable(const awaitable&) = delete;
awaitable& operator=(const awaitable&) = delete;
// Construct the awaitable from a coroutine's frame object.
explicit awaitable(detail::awaitable_frame<T, Executor>* a)
: frame_(a)
{
}
detail::awaitable_frame<T, Executor>* frame_;
};
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/impl/awaitable.hpp>
#endif // defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
#endif // BOOST_ASIO_AWAITABLE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/spawn.hpp | //
// spawn.hpp
// ~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SPAWN_HPP
#define BOOST_ASIO_SPAWN_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/any_io_executor.hpp>
#include <boost/asio/cancellation_signal.hpp>
#include <boost/asio/cancellation_state.hpp>
#include <boost/asio/detail/exception.hpp>
#include <boost/asio/detail/memory.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/is_executor.hpp>
#include <boost/asio/strand.hpp>
#if defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
# include <boost/coroutine/all.hpp>
#endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
// Base class for all spawn()-ed thread implementations.
class spawned_thread_base
{
public:
spawned_thread_base()
: owner_(0),
has_context_switched_(false),
throw_if_cancelled_(false),
terminal_(false)
{
}
virtual ~spawned_thread_base() {}
virtual void resume() = 0;
virtual void suspend_with(void (*fn)(void*), void* arg) = 0;
virtual void destroy() = 0;
void attach(spawned_thread_base** owner)
{
owner_ = owner;
*owner_ = this;
}
void detach()
{
if (owner_)
*owner_ = 0;
owner_ = 0;
}
void suspend()
{
suspend_with(0, 0);
}
template <typename F>
void suspend_with(F f)
{
suspend_with(&spawned_thread_base::call<F>, &f);
}
cancellation_slot get_cancellation_slot() const noexcept
{
return cancellation_state_.slot();
}
cancellation_state get_cancellation_state() const noexcept
{
return cancellation_state_;
}
void reset_cancellation_state()
{
cancellation_state_ = cancellation_state(parent_cancellation_slot_);
}
template <typename Filter>
void reset_cancellation_state(Filter filter)
{
cancellation_state_ = cancellation_state(
parent_cancellation_slot_, filter, filter);
}
template <typename InFilter, typename OutFilter>
void reset_cancellation_state(InFilter in_filter, OutFilter out_filter)
{
cancellation_state_ = cancellation_state(
parent_cancellation_slot_, in_filter, out_filter);
}
cancellation_type_t cancelled() const noexcept
{
return cancellation_state_.cancelled();
}
bool has_context_switched() const noexcept
{
return has_context_switched_;
}
bool throw_if_cancelled() const noexcept
{
return throw_if_cancelled_;
}
void throw_if_cancelled(bool value) noexcept
{
throw_if_cancelled_ = value;
}
protected:
spawned_thread_base** owner_; // Points to data member in active handler.
boost::asio::cancellation_slot parent_cancellation_slot_;
boost::asio::cancellation_state cancellation_state_;
bool has_context_switched_;
bool throw_if_cancelled_;
bool terminal_;
private:
// Disallow copying and assignment.
spawned_thread_base(const spawned_thread_base&) = delete;
spawned_thread_base& operator=(const spawned_thread_base&) = delete;
template <typename F>
static void call(void* f)
{
(*static_cast<F*>(f))();
}
};
template <typename T>
struct spawn_signature
{
typedef void type(exception_ptr, T);
};
template <>
struct spawn_signature<void>
{
typedef void type(exception_ptr);
};
template <typename Executor>
class initiate_spawn;
} // namespace detail
/// A @ref completion_token that represents the currently executing coroutine.
/**
* The basic_yield_context class is a completion token type that is used to
* represent the currently executing stackful coroutine. A basic_yield_context
* object may be passed as a completion token to an asynchronous operation. For
* example:
*
* @code template <typename Executor>
* void my_coroutine(basic_yield_context<Executor> yield)
* {
* ...
* std::size_t n = my_socket.async_read_some(buffer, yield);
* ...
* } @endcode
*
* The initiating function (async_read_some in the above example) suspends the
* current coroutine. The coroutine is resumed when the asynchronous operation
* completes, and the result of the operation is returned.
*/
template <typename Executor>
class basic_yield_context
{
public:
/// The executor type associated with the yield context.
typedef Executor executor_type;
/// The cancellation slot type associated with the yield context.
typedef cancellation_slot cancellation_slot_type;
/// Construct a yield context from another yield context type.
/**
* Requires that OtherExecutor be convertible to Executor.
*/
template <typename OtherExecutor>
basic_yield_context(const basic_yield_context<OtherExecutor>& other,
constraint_t<
is_convertible<OtherExecutor, Executor>::value
> = 0)
: spawned_thread_(other.spawned_thread_),
executor_(other.executor_),
ec_(other.ec_)
{
}
/// Get the executor associated with the yield context.
executor_type get_executor() const noexcept
{
return executor_;
}
/// Get the cancellation slot associated with the coroutine.
cancellation_slot_type get_cancellation_slot() const noexcept
{
return spawned_thread_->get_cancellation_slot();
}
/// Get the cancellation state associated with the coroutine.
cancellation_state get_cancellation_state() const noexcept
{
return spawned_thread_->get_cancellation_state();
}
/// Reset the cancellation state associated with the coroutine.
/**
* Let <tt>P</tt> be the cancellation slot associated with the current
* coroutine's @ref spawn completion handler. Assigns a new
* boost::asio::cancellation_state object <tt>S</tt>, constructed as
* <tt>S(P)</tt>, into the current coroutine's cancellation state object.
*/
void reset_cancellation_state() const
{
spawned_thread_->reset_cancellation_state();
}
/// Reset the cancellation state associated with the coroutine.
/**
* Let <tt>P</tt> be the cancellation slot associated with the current
* coroutine's @ref spawn completion handler. Assigns a new
* boost::asio::cancellation_state object <tt>S</tt>, constructed as <tt>S(P,
* std::forward<Filter>(filter))</tt>, into the current coroutine's
* cancellation state object.
*/
template <typename Filter>
void reset_cancellation_state(Filter&& filter) const
{
spawned_thread_->reset_cancellation_state(
static_cast<Filter&&>(filter));
}
/// Reset the cancellation state associated with the coroutine.
/**
* Let <tt>P</tt> be the cancellation slot associated with the current
* coroutine's @ref spawn completion handler. Assigns a new
* boost::asio::cancellation_state object <tt>S</tt>, constructed as <tt>S(P,
* std::forward<InFilter>(in_filter),
* std::forward<OutFilter>(out_filter))</tt>, into the current coroutine's
* cancellation state object.
*/
template <typename InFilter, typename OutFilter>
void reset_cancellation_state(InFilter&& in_filter,
OutFilter&& out_filter) const
{
spawned_thread_->reset_cancellation_state(
static_cast<InFilter&&>(in_filter),
static_cast<OutFilter&&>(out_filter));
}
/// Determine whether the current coroutine has been cancelled.
cancellation_type_t cancelled() const noexcept
{
return spawned_thread_->cancelled();
}
/// Determine whether the coroutine throws if trying to suspend when it has
/// been cancelled.
bool throw_if_cancelled() const noexcept
{
return spawned_thread_->throw_if_cancelled();
}
/// Set whether the coroutine throws if trying to suspend when it has been
/// cancelled.
void throw_if_cancelled(bool value) const noexcept
{
spawned_thread_->throw_if_cancelled(value);
}
/// Return a yield context that sets the specified error_code.
/**
* By default, when a yield context is used with an asynchronous operation, a
* non-success error_code is converted to system_error and thrown. This
* operator may be used to specify an error_code object that should instead be
* set with the asynchronous operation's result. For example:
*
* @code template <typename Executor>
* void my_coroutine(basic_yield_context<Executor> yield)
* {
* ...
* std::size_t n = my_socket.async_read_some(buffer, yield[ec]);
* if (ec)
* {
* // An error occurred.
* }
* ...
* } @endcode
*/
basic_yield_context operator[](boost::system::error_code& ec) const
{
basic_yield_context tmp(*this);
tmp.ec_ = &ec;
return tmp;
}
#if !defined(GENERATING_DOCUMENTATION)
//private:
basic_yield_context(detail::spawned_thread_base* spawned_thread,
const Executor& ex)
: spawned_thread_(spawned_thread),
executor_(ex),
ec_(0)
{
}
detail::spawned_thread_base* spawned_thread_;
Executor executor_;
boost::system::error_code* ec_;
#endif // !defined(GENERATING_DOCUMENTATION)
};
/// A @ref completion_token object that represents the currently executing
/// coroutine.
typedef basic_yield_context<any_io_executor> yield_context;
/**
* @defgroup spawn boost::asio::spawn
*
* @brief Start a new stackful coroutine.
*
* The spawn() function is a high-level wrapper over the Boost.Coroutine
* library. This function enables programs to implement asynchronous logic in a
* synchronous manner, as illustrated by the following example:
*
* @code boost::asio::spawn(my_strand, do_echo, boost::asio::detached);
*
* // ...
*
* void do_echo(boost::asio::yield_context yield)
* {
* try
* {
* char data[128];
* for (;;)
* {
* std::size_t length =
* my_socket.async_read_some(
* boost::asio::buffer(data), yield);
*
* boost::asio::async_write(my_socket,
* boost::asio::buffer(data, length), yield);
* }
* }
* catch (std::exception& e)
* {
* // ...
* }
* } @endcode
*/
/*@{*/
/// Start a new stackful coroutine that executes on a given executor.
/**
* This function is used to launch a new stackful coroutine.
*
* @param ex Identifies the executor that will run the stackful coroutine.
*
* @param function The coroutine function. The function must be callable the
* signature:
* @code void function(basic_yield_context<Executor> yield); @endcode
*
* @param token The @ref completion_token that will handle the notification
* that the coroutine has completed. If the return type @c R of @c function is
* @c void, the function signature of the completion handler must be:
*
* @code void handler(std::exception_ptr); @endcode
* Otherwise, the function signature of the completion handler must be:
* @code void handler(std::exception_ptr, R); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr, R) @endcode
* where @c R is the return type of the function object.
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call the basic_yield_context member function
* @c reset_cancellation_state.
*/
template <typename Executor, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type)
CompletionToken = default_completion_token_t<Executor>>
auto spawn(const Executor& ex, F&& function,
CompletionToken&& token = default_completion_token_t<Executor>(),
#if defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
!is_same<
decay_t<CompletionToken>,
boost::coroutines::attributes
>::value
> = 0,
#endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
> = 0)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type>(
declval<detail::initiate_spawn<Executor>>(),
token, static_cast<F&&>(function)));
/// Start a new stackful coroutine that executes on a given execution context.
/**
* This function is used to launch a new stackful coroutine.
*
* @param ctx Identifies the execution context that will run the stackful
* coroutine.
*
* @param function The coroutine function. The function must be callable the
* signature:
* @code void function(basic_yield_context<Executor> yield); @endcode
*
* @param token The @ref completion_token that will handle the notification
* that the coroutine has completed. If the return type @c R of @c function is
* @c void, the function signature of the completion handler must be:
*
* @code void handler(std::exception_ptr); @endcode
* Otherwise, the function signature of the completion handler must be:
* @code void handler(std::exception_ptr, R); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr, R) @endcode
* where @c R is the return type of the function object.
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call the basic_yield_context member function
* @c reset_cancellation_state.
*/
template <typename ExecutionContext, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<
typename ExecutionContext::executor_type>)>>::type)
CompletionToken = default_completion_token_t<
typename ExecutionContext::executor_type>>
auto spawn(ExecutionContext& ctx, F&& function,
CompletionToken&& token
= default_completion_token_t<typename ExecutionContext::executor_type>(),
#if defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
!is_same<
decay_t<CompletionToken>,
boost::coroutines::attributes
>::value
> = 0,
#endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
> = 0)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<
typename ExecutionContext::executor_type>)>>::type>(
declval<detail::initiate_spawn<
typename ExecutionContext::executor_type>>(),
token, static_cast<F&&>(function)));
/// Start a new stackful coroutine, inheriting the executor of another.
/**
* This function is used to launch a new stackful coroutine.
*
* @param ctx Identifies the current coroutine as a parent of the new
* coroutine. This specifies that the new coroutine should inherit the executor
* of the parent. For example, if the parent coroutine is executing in a
* particular strand, then the new coroutine will execute in the same strand.
*
* @param function The coroutine function. The function must be callable the
* signature:
* @code void function(basic_yield_context<Executor> yield); @endcode
*
* @param token The @ref completion_token that will handle the notification
* that the coroutine has completed. If the return type @c R of @c function is
* @c void, the function signature of the completion handler must be:
*
* @code void handler(std::exception_ptr); @endcode
* Otherwise, the function signature of the completion handler must be:
* @code void handler(std::exception_ptr, R); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr, R) @endcode
* where @c R is the return type of the function object.
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call the basic_yield_context member function
* @c reset_cancellation_state.
*/
template <typename Executor, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type)
CompletionToken = default_completion_token_t<Executor>>
auto spawn(const basic_yield_context<Executor>& ctx, F&& function,
CompletionToken&& token = default_completion_token_t<Executor>(),
#if defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
!is_same<
decay_t<CompletionToken>,
boost::coroutines::attributes
>::value
> = 0,
#endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
> = 0)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type>(
declval<detail::initiate_spawn<Executor>>(),
token, static_cast<F&&>(function)));
#if defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER) \
|| defined(GENERATING_DOCUMENTATION)
/// Start a new stackful coroutine that executes on a given executor.
/**
* This function is used to launch a new stackful coroutine using the
* specified stack allocator.
*
* @param ex Identifies the executor that will run the stackful coroutine.
*
* @param stack_allocator Denotes the allocator to be used to allocate the
* underlying coroutine's stack. The type must satisfy the stack-allocator
* concept defined by the Boost.Context library.
*
* @param function The coroutine function. The function must be callable the
* signature:
* @code void function(basic_yield_context<Executor> yield); @endcode
*
* @param token The @ref completion_token that will handle the notification
* that the coroutine has completed. If the return type @c R of @c function is
* @c void, the function signature of the completion handler must be:
*
* @code void handler(std::exception_ptr); @endcode
* Otherwise, the function signature of the completion handler must be:
* @code void handler(std::exception_ptr, R); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr, R) @endcode
* where @c R is the return type of the function object.
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call the basic_yield_context member function
* @c reset_cancellation_state.
*/
template <typename Executor, typename StackAllocator, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type)
CompletionToken = default_completion_token_t<Executor>>
auto spawn(const Executor& ex, allocator_arg_t,
StackAllocator&& stack_allocator, F&& function,
CompletionToken&& token = default_completion_token_t<Executor>(),
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
> = 0)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type>(
declval<detail::initiate_spawn<Executor>>(),
token, allocator_arg_t(),
static_cast<StackAllocator&&>(stack_allocator),
static_cast<F&&>(function)));
/// Start a new stackful coroutine that executes on a given execution context.
/**
* This function is used to launch a new stackful coroutine.
*
* @param ctx Identifies the execution context that will run the stackful
* coroutine.
*
* @param stack_allocator Denotes the allocator to be used to allocate the
* underlying coroutine's stack. The type must satisfy the stack-allocator
* concept defined by the Boost.Context library.
*
* @param function The coroutine function. The function must be callable the
* signature:
* @code void function(basic_yield_context<Executor> yield); @endcode
*
* @param token The @ref completion_token that will handle the notification
* that the coroutine has completed. If the return type @c R of @c function is
* @c void, the function signature of the completion handler must be:
*
* @code void handler(std::exception_ptr); @endcode
* Otherwise, the function signature of the completion handler must be:
* @code void handler(std::exception_ptr, R); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr, R) @endcode
* where @c R is the return type of the function object.
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call the basic_yield_context member function
* @c reset_cancellation_state.
*/
template <typename ExecutionContext, typename StackAllocator, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<
typename ExecutionContext::executor_type>)>>::type)
CompletionToken = default_completion_token_t<
typename ExecutionContext::executor_type>>
auto spawn(ExecutionContext& ctx, allocator_arg_t,
StackAllocator&& stack_allocator, F&& function,
CompletionToken&& token
= default_completion_token_t<typename ExecutionContext::executor_type>(),
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
> = 0)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<
typename ExecutionContext::executor_type>)>>::type>(
declval<detail::initiate_spawn<
typename ExecutionContext::executor_type>>(),
token, allocator_arg_t(),
static_cast<StackAllocator&&>(stack_allocator),
static_cast<F&&>(function)));
/// Start a new stackful coroutine, inheriting the executor of another.
/**
* This function is used to launch a new stackful coroutine using the
* specified stack allocator.
*
* @param ctx Identifies the current coroutine as a parent of the new
* coroutine. This specifies that the new coroutine should inherit the
* executor of the parent. For example, if the parent coroutine is executing
* in a particular strand, then the new coroutine will execute in the same
* strand.
*
* @param stack_allocator Denotes the allocator to be used to allocate the
* underlying coroutine's stack. The type must satisfy the stack-allocator
* concept defined by the Boost.Context library.
*
* @param function The coroutine function. The function must be callable the
* signature:
* @code void function(basic_yield_context<Executor> yield); @endcode
*
* @param token The @ref completion_token that will handle the notification
* that the coroutine has completed. If the return type @c R of @c function is
* @c void, the function signature of the completion handler must be:
*
* @code void handler(std::exception_ptr); @endcode
* Otherwise, the function signature of the completion handler must be:
* @code void handler(std::exception_ptr, R); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr, R) @endcode
* where @c R is the return type of the function object.
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call the basic_yield_context member function
* @c reset_cancellation_state.
*/
template <typename Executor, typename StackAllocator, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type)
CompletionToken = default_completion_token_t<Executor>>
auto spawn(const basic_yield_context<Executor>& ctx, allocator_arg_t,
StackAllocator&& stack_allocator, F&& function,
CompletionToken&& token = default_completion_token_t<Executor>(),
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
> = 0)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type>(
declval<detail::initiate_spawn<Executor>>(),
token, allocator_arg_t(),
static_cast<StackAllocator&&>(stack_allocator),
static_cast<F&&>(function)));
#endif // defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
// || defined(GENERATING_DOCUMENTATION)
#if defined(BOOST_ASIO_HAS_BOOST_COROUTINE) \
|| defined(GENERATING_DOCUMENTATION)
/// (Deprecated: Use overloads with a completion token.) Start a new stackful
/// coroutine, calling the specified handler when it completes.
/**
* This function is used to launch a new coroutine.
*
* @param function The coroutine function. The function must have the signature:
* @code void function(basic_yield_context<Executor> yield); @endcode
* where Executor is the associated executor type of @c Function.
*
* @param attributes Boost.Coroutine attributes used to customise the coroutine.
*/
template <typename Function>
void spawn(Function&& function,
const boost::coroutines::attributes& attributes
= boost::coroutines::attributes());
/// (Deprecated: Use overloads with a completion token.) Start a new stackful
/// coroutine, calling the specified handler when it completes.
/**
* This function is used to launch a new coroutine.
*
* @param handler A handler to be called when the coroutine exits. More
* importantly, the handler provides an execution context (via the the handler
* invocation hook) for the coroutine. The handler must have the signature:
* @code void handler(); @endcode
*
* @param function The coroutine function. The function must have the signature:
* @code void function(basic_yield_context<Executor> yield); @endcode
* where Executor is the associated executor type of @c Handler.
*
* @param attributes Boost.Coroutine attributes used to customise the coroutine.
*/
template <typename Handler, typename Function>
void spawn(Handler&& handler, Function&& function,
const boost::coroutines::attributes& attributes
= boost::coroutines::attributes(),
constraint_t<
!is_executor<decay_t<Handler>>::value &&
!execution::is_executor<decay_t<Handler>>::value &&
!is_convertible<Handler&, execution_context&>::value
> = 0);
/// (Deprecated: Use overloads with a completion token.) Start a new stackful
/// coroutine, inheriting the execution context of another.
/**
* This function is used to launch a new coroutine.
*
* @param ctx Identifies the current coroutine as a parent of the new
* coroutine. This specifies that the new coroutine should inherit the
* execution context of the parent. For example, if the parent coroutine is
* executing in a particular strand, then the new coroutine will execute in the
* same strand.
*
* @param function The coroutine function. The function must have the signature:
* @code void function(basic_yield_context<Executor> yield); @endcode
*
* @param attributes Boost.Coroutine attributes used to customise the coroutine.
*/
template <typename Executor, typename Function>
void spawn(basic_yield_context<Executor> ctx, Function&& function,
const boost::coroutines::attributes& attributes
= boost::coroutines::attributes());
/// (Deprecated: Use overloads with a completion token.) Start a new stackful
/// coroutine that executes on a given executor.
/**
* This function is used to launch a new coroutine.
*
* @param ex Identifies the executor that will run the coroutine. The new
* coroutine is automatically given its own explicit strand within this
* executor.
*
* @param function The coroutine function. The function must have the signature:
* @code void function(yield_context yield); @endcode
*
* @param attributes Boost.Coroutine attributes used to customise the coroutine.
*/
template <typename Function, typename Executor>
void spawn(const Executor& ex, Function&& function,
const boost::coroutines::attributes& attributes
= boost::coroutines::attributes(),
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
> = 0);
/// (Deprecated: Use overloads with a completion token.) Start a new stackful
/// coroutine that executes on a given strand.
/**
* This function is used to launch a new coroutine.
*
* @param ex Identifies the strand that will run the coroutine.
*
* @param function The coroutine function. The function must have the signature:
* @code void function(yield_context yield); @endcode
*
* @param attributes Boost.Coroutine attributes used to customise the coroutine.
*/
template <typename Function, typename Executor>
void spawn(const strand<Executor>& ex, Function&& function,
const boost::coroutines::attributes& attributes
= boost::coroutines::attributes());
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
/// (Deprecated: Use overloads with a completion token.) Start a new stackful
/// coroutine that executes in the context of a strand.
/**
* This function is used to launch a new coroutine.
*
* @param s Identifies a strand. By starting multiple coroutines on the same
* strand, the implementation ensures that none of those coroutines can execute
* simultaneously.
*
* @param function The coroutine function. The function must have the signature:
* @code void function(yield_context yield); @endcode
*
* @param attributes Boost.Coroutine attributes used to customise the coroutine.
*/
template <typename Function>
void spawn(const boost::asio::io_context::strand& s, Function&& function,
const boost::coroutines::attributes& attributes
= boost::coroutines::attributes());
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
/// (Deprecated: Use overloads with a completion token.) Start a new stackful
/// coroutine that executes on a given execution context.
/**
* This function is used to launch a new coroutine.
*
* @param ctx Identifies the execution context that will run the coroutine. The
* new coroutine is implicitly given its own strand within this execution
* context.
*
* @param function The coroutine function. The function must have the signature:
* @code void function(yield_context yield); @endcode
*
* @param attributes Boost.Coroutine attributes used to customise the coroutine.
*/
template <typename Function, typename ExecutionContext>
void spawn(ExecutionContext& ctx, Function&& function,
const boost::coroutines::attributes& attributes
= boost::coroutines::attributes(),
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
> = 0);
#endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
// || defined(GENERATING_DOCUMENTATION)
/*@}*/
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/impl/spawn.hpp>
#endif // BOOST_ASIO_SPAWN_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/co_spawn.hpp | //
// co_spawn.hpp
// ~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_CO_SPAWN_HPP
#define BOOST_ASIO_CO_SPAWN_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
#include <boost/asio/awaitable.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/execution_context.hpp>
#include <boost/asio/is_executor.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
template <typename T>
struct awaitable_signature;
template <typename T, typename Executor>
struct awaitable_signature<awaitable<T, Executor>>
{
typedef void type(std::exception_ptr, T);
};
template <typename Executor>
struct awaitable_signature<awaitable<void, Executor>>
{
typedef void type(std::exception_ptr);
};
} // namespace detail
/// Spawn a new coroutined-based thread of execution.
/**
* @param ex The executor that will be used to schedule the new thread of
* execution.
*
* @param a The boost::asio::awaitable object that is the result of calling the
* coroutine's entry point function.
*
* @param token The @ref completion_token that will handle the notification that
* the thread of execution has completed. The function signature of the
* completion handler must be:
* @code void handler(std::exception_ptr, T); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr, T) @endcode
*
* @par Example
* @code
* boost::asio::awaitable<std::size_t> echo(tcp::socket socket)
* {
* std::size_t bytes_transferred = 0;
*
* try
* {
* char data[1024];
* for (;;)
* {
* std::size_t n = co_await socket.async_read_some(
* boost::asio::buffer(data), boost::asio::use_awaitable);
*
* co_await boost::asio::async_write(socket,
* boost::asio::buffer(data, n), boost::asio::use_awaitable);
*
* bytes_transferred += n;
* }
* }
* catch (const std::exception&)
* {
* }
*
* co_return bytes_transferred;
* }
*
* // ...
*
* boost::asio::co_spawn(my_executor,
* echo(std::move(my_tcp_socket)),
* [](std::exception_ptr e, std::size_t n)
* {
* std::cout << "transferred " << n << "\n";
* });
* @endcode
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call boost::asio::this_coro::reset_cancellation_state.
*/
template <typename Executor, typename T, typename AwaitableExecutor,
BOOST_ASIO_COMPLETION_TOKEN_FOR(
void(std::exception_ptr, T)) CompletionToken
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
CompletionToken, void(std::exception_ptr, T))
co_spawn(const Executor& ex, awaitable<T, AwaitableExecutor> a,
CompletionToken&& token
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor),
constraint_t<
(is_executor<Executor>::value || execution::is_executor<Executor>::value)
&& is_convertible<Executor, AwaitableExecutor>::value
> = 0);
/// Spawn a new coroutined-based thread of execution.
/**
* @param ex The executor that will be used to schedule the new thread of
* execution.
*
* @param a The boost::asio::awaitable object that is the result of calling the
* coroutine's entry point function.
*
* @param token The @ref completion_token that will handle the notification that
* the thread of execution has completed. The function signature of the
* completion handler must be:
* @code void handler(std::exception_ptr); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr) @endcode
*
* @par Example
* @code
* boost::asio::awaitable<void> echo(tcp::socket socket)
* {
* try
* {
* char data[1024];
* for (;;)
* {
* std::size_t n = co_await socket.async_read_some(
* boost::asio::buffer(data), boost::asio::use_awaitable);
*
* co_await boost::asio::async_write(socket,
* boost::asio::buffer(data, n), boost::asio::use_awaitable);
* }
* }
* catch (const std::exception& e)
* {
* std::cerr << "Exception: " << e.what() << "\n";
* }
* }
*
* // ...
*
* boost::asio::co_spawn(my_executor,
* echo(std::move(my_tcp_socket)),
* boost::asio::detached);
* @endcode
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call boost::asio::this_coro::reset_cancellation_state.
*/
template <typename Executor, typename AwaitableExecutor,
BOOST_ASIO_COMPLETION_TOKEN_FOR(
void(std::exception_ptr)) CompletionToken
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
CompletionToken, void(std::exception_ptr))
co_spawn(const Executor& ex, awaitable<void, AwaitableExecutor> a,
CompletionToken&& token
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor),
constraint_t<
(is_executor<Executor>::value || execution::is_executor<Executor>::value)
&& is_convertible<Executor, AwaitableExecutor>::value
> = 0);
/// Spawn a new coroutined-based thread of execution.
/**
* @param ctx An execution context that will provide the executor to be used to
* schedule the new thread of execution.
*
* @param a The boost::asio::awaitable object that is the result of calling the
* coroutine's entry point function.
*
* @param token The @ref completion_token that will handle the notification that
* the thread of execution has completed. The function signature of the
* completion handler must be:
* @code void handler(std::exception_ptr); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr, T) @endcode
*
* @par Example
* @code
* boost::asio::awaitable<std::size_t> echo(tcp::socket socket)
* {
* std::size_t bytes_transferred = 0;
*
* try
* {
* char data[1024];
* for (;;)
* {
* std::size_t n = co_await socket.async_read_some(
* boost::asio::buffer(data), boost::asio::use_awaitable);
*
* co_await boost::asio::async_write(socket,
* boost::asio::buffer(data, n), boost::asio::use_awaitable);
*
* bytes_transferred += n;
* }
* }
* catch (const std::exception&)
* {
* }
*
* co_return bytes_transferred;
* }
*
* // ...
*
* boost::asio::co_spawn(my_io_context,
* echo(std::move(my_tcp_socket)),
* [](std::exception_ptr e, std::size_t n)
* {
* std::cout << "transferred " << n << "\n";
* });
* @endcode
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call boost::asio::this_coro::reset_cancellation_state.
*/
template <typename ExecutionContext, typename T, typename AwaitableExecutor,
BOOST_ASIO_COMPLETION_TOKEN_FOR(
void(std::exception_ptr, T)) CompletionToken
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
typename ExecutionContext::executor_type)>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
CompletionToken, void(std::exception_ptr, T))
co_spawn(ExecutionContext& ctx, awaitable<T, AwaitableExecutor> a,
CompletionToken&& token
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
typename ExecutionContext::executor_type),
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
&& is_convertible<typename ExecutionContext::executor_type,
AwaitableExecutor>::value
> = 0);
/// Spawn a new coroutined-based thread of execution.
/**
* @param ctx An execution context that will provide the executor to be used to
* schedule the new thread of execution.
*
* @param a The boost::asio::awaitable object that is the result of calling the
* coroutine's entry point function.
*
* @param token The @ref completion_token that will handle the notification that
* the thread of execution has completed. The function signature of the
* completion handler must be:
* @code void handler(std::exception_ptr); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr) @endcode
*
* @par Example
* @code
* boost::asio::awaitable<void> echo(tcp::socket socket)
* {
* try
* {
* char data[1024];
* for (;;)
* {
* std::size_t n = co_await socket.async_read_some(
* boost::asio::buffer(data), boost::asio::use_awaitable);
*
* co_await boost::asio::async_write(socket,
* boost::asio::buffer(data, n), boost::asio::use_awaitable);
* }
* }
* catch (const std::exception& e)
* {
* std::cerr << "Exception: " << e.what() << "\n";
* }
* }
*
* // ...
*
* boost::asio::co_spawn(my_io_context,
* echo(std::move(my_tcp_socket)),
* boost::asio::detached);
* @endcode
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call boost::asio::this_coro::reset_cancellation_state.
*/
template <typename ExecutionContext, typename AwaitableExecutor,
BOOST_ASIO_COMPLETION_TOKEN_FOR(
void(std::exception_ptr)) CompletionToken
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
typename ExecutionContext::executor_type)>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
CompletionToken, void(std::exception_ptr))
co_spawn(ExecutionContext& ctx, awaitable<void, AwaitableExecutor> a,
CompletionToken&& token
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
typename ExecutionContext::executor_type),
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
&& is_convertible<typename ExecutionContext::executor_type,
AwaitableExecutor>::value
> = 0);
/// Spawn a new coroutined-based thread of execution.
/**
* @param ex The executor that will be used to schedule the new thread of
* execution.
*
* @param f A nullary function object with a return type of the form
* @c boost::asio::awaitable<R,E> that will be used as the coroutine's entry
* point.
*
* @param token The @ref completion_token that will handle the notification
* that the thread of execution has completed. If @c R is @c void, the function
* signature of the completion handler must be:
*
* @code void handler(std::exception_ptr); @endcode
* Otherwise, the function signature of the completion handler must be:
* @code void handler(std::exception_ptr, R); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr, R) @endcode
* where @c R is the first template argument to the @c awaitable returned by the
* supplied function object @c F:
* @code boost::asio::awaitable<R, AwaitableExecutor> F() @endcode
*
* @par Example
* @code
* boost::asio::awaitable<std::size_t> echo(tcp::socket socket)
* {
* std::size_t bytes_transferred = 0;
*
* try
* {
* char data[1024];
* for (;;)
* {
* std::size_t n = co_await socket.async_read_some(
* boost::asio::buffer(data), boost::asio::use_awaitable);
*
* co_await boost::asio::async_write(socket,
* boost::asio::buffer(data, n), boost::asio::use_awaitable);
*
* bytes_transferred += n;
* }
* }
* catch (const std::exception&)
* {
* }
*
* co_return bytes_transferred;
* }
*
* // ...
*
* boost::asio::co_spawn(my_executor,
* [socket = std::move(my_tcp_socket)]() mutable
* -> boost::asio::awaitable<void>
* {
* try
* {
* char data[1024];
* for (;;)
* {
* std::size_t n = co_await socket.async_read_some(
* boost::asio::buffer(data), boost::asio::use_awaitable);
*
* co_await boost::asio::async_write(socket,
* boost::asio::buffer(data, n), boost::asio::use_awaitable);
* }
* }
* catch (const std::exception& e)
* {
* std::cerr << "Exception: " << e.what() << "\n";
* }
* }, boost::asio::detached);
* @endcode
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call boost::asio::this_coro::reset_cancellation_state.
*/
template <typename Executor, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
result_of_t<F()>>::type) CompletionToken
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
typename detail::awaitable_signature<result_of_t<F()>>::type)
co_spawn(const Executor& ex, F&& f,
CompletionToken&& token
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor),
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
> = 0);
/// Spawn a new coroutined-based thread of execution.
/**
* @param ctx An execution context that will provide the executor to be used to
* schedule the new thread of execution.
*
* @param f A nullary function object with a return type of the form
* @c boost::asio::awaitable<R,E> that will be used as the coroutine's entry
* point.
*
* @param token The @ref completion_token that will handle the notification
* that the thread of execution has completed. If @c R is @c void, the function
* signature of the completion handler must be:
*
* @code void handler(std::exception_ptr); @endcode
* Otherwise, the function signature of the completion handler must be:
* @code void handler(std::exception_ptr, R); @endcode
*
* @par Completion Signature
* @code void(std::exception_ptr, R) @endcode
* where @c R is the first template argument to the @c awaitable returned by the
* supplied function object @c F:
* @code boost::asio::awaitable<R, AwaitableExecutor> F() @endcode
*
* @par Example
* @code
* boost::asio::awaitable<std::size_t> echo(tcp::socket socket)
* {
* std::size_t bytes_transferred = 0;
*
* try
* {
* char data[1024];
* for (;;)
* {
* std::size_t n = co_await socket.async_read_some(
* boost::asio::buffer(data), boost::asio::use_awaitable);
*
* co_await boost::asio::async_write(socket,
* boost::asio::buffer(data, n), boost::asio::use_awaitable);
*
* bytes_transferred += n;
* }
* }
* catch (const std::exception&)
* {
* }
*
* co_return bytes_transferred;
* }
*
* // ...
*
* boost::asio::co_spawn(my_io_context,
* [socket = std::move(my_tcp_socket)]() mutable
* -> boost::asio::awaitable<void>
* {
* try
* {
* char data[1024];
* for (;;)
* {
* std::size_t n = co_await socket.async_read_some(
* boost::asio::buffer(data), boost::asio::use_awaitable);
*
* co_await boost::asio::async_write(socket,
* boost::asio::buffer(data, n), boost::asio::use_awaitable);
* }
* }
* catch (const std::exception& e)
* {
* std::cerr << "Exception: " << e.what() << "\n";
* }
* }, boost::asio::detached);
* @endcode
*
* @par Per-Operation Cancellation
* The new thread of execution is created with a cancellation state that
* supports @c cancellation_type::terminal values only. To change the
* cancellation state, call boost::asio::this_coro::reset_cancellation_state.
*/
template <typename ExecutionContext, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
result_of_t<F()>>::type) CompletionToken
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
typename ExecutionContext::executor_type)>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
typename detail::awaitable_signature<result_of_t<F()>>::type)
co_spawn(ExecutionContext& ctx, F&& f,
CompletionToken&& token
BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
typename ExecutionContext::executor_type),
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
> = 0);
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/impl/co_spawn.hpp>
#endif // defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(GENERATING_DOCUMENTATION)
#endif // BOOST_ASIO_CO_SPAWN_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/bind_immediate_executor.hpp | //
// bind_immediate_executor.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_BIND_IMMEDIATE_EXECUTOR_HPP
#define BOOST_ASIO_BIND_IMMEDIATE_EXECUTOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/associated_immediate_executor.hpp>
#include <boost/asio/associator.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
// Helper to automatically define nested typedef result_type.
template <typename T, typename = void>
struct immediate_executor_binder_result_type
{
protected:
typedef void result_type_or_void;
};
template <typename T>
struct immediate_executor_binder_result_type<T, void_t<typename T::result_type>>
{
typedef typename T::result_type result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R>
struct immediate_executor_binder_result_type<R(*)()>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R>
struct immediate_executor_binder_result_type<R(&)()>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R, typename A1>
struct immediate_executor_binder_result_type<R(*)(A1)>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R, typename A1>
struct immediate_executor_binder_result_type<R(&)(A1)>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R, typename A1, typename A2>
struct immediate_executor_binder_result_type<R(*)(A1, A2)>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R, typename A1, typename A2>
struct immediate_executor_binder_result_type<R(&)(A1, A2)>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
// Helper to automatically define nested typedef argument_type.
template <typename T, typename = void>
struct immediate_executor_binder_argument_type {};
template <typename T>
struct immediate_executor_binder_argument_type<T,
void_t<typename T::argument_type>>
{
typedef typename T::argument_type argument_type;
};
template <typename R, typename A1>
struct immediate_executor_binder_argument_type<R(*)(A1)>
{
typedef A1 argument_type;
};
template <typename R, typename A1>
struct immediate_executor_binder_argument_type<R(&)(A1)>
{
typedef A1 argument_type;
};
// Helper to automatically define nested typedefs first_argument_type and
// second_argument_type.
template <typename T, typename = void>
struct immediate_executor_binder_argument_types {};
template <typename T>
struct immediate_executor_binder_argument_types<T,
void_t<typename T::first_argument_type>>
{
typedef typename T::first_argument_type first_argument_type;
typedef typename T::second_argument_type second_argument_type;
};
template <typename R, typename A1, typename A2>
struct immediate_executor_binder_argument_type<R(*)(A1, A2)>
{
typedef A1 first_argument_type;
typedef A2 second_argument_type;
};
template <typename R, typename A1, typename A2>
struct immediate_executor_binder_argument_type<R(&)(A1, A2)>
{
typedef A1 first_argument_type;
typedef A2 second_argument_type;
};
} // namespace detail
/// A call wrapper type to bind a immediate executor of type @c Executor
/// to an object of type @c T.
template <typename T, typename Executor>
class immediate_executor_binder
#if !defined(GENERATING_DOCUMENTATION)
: public detail::immediate_executor_binder_result_type<T>,
public detail::immediate_executor_binder_argument_type<T>,
public detail::immediate_executor_binder_argument_types<T>
#endif // !defined(GENERATING_DOCUMENTATION)
{
public:
/// The type of the target object.
typedef T target_type;
/// The type of the associated immediate executor.
typedef Executor immediate_executor_type;
#if defined(GENERATING_DOCUMENTATION)
/// The return type if a function.
/**
* The type of @c result_type is based on the type @c T of the wrapper's
* target object:
*
* @li if @c T is a pointer to function type, @c result_type is a synonym for
* the return type of @c T;
*
* @li if @c T is a class type with a member type @c result_type, then @c
* result_type is a synonym for @c T::result_type;
*
* @li otherwise @c result_type is not defined.
*/
typedef see_below result_type;
/// The type of the function's argument.
/**
* The type of @c argument_type is based on the type @c T of the wrapper's
* target object:
*
* @li if @c T is a pointer to a function type accepting a single argument,
* @c argument_type is a synonym for the return type of @c T;
*
* @li if @c T is a class type with a member type @c argument_type, then @c
* argument_type is a synonym for @c T::argument_type;
*
* @li otherwise @c argument_type is not defined.
*/
typedef see_below argument_type;
/// The type of the function's first argument.
/**
* The type of @c first_argument_type is based on the type @c T of the
* wrapper's target object:
*
* @li if @c T is a pointer to a function type accepting two arguments, @c
* first_argument_type is a synonym for the return type of @c T;
*
* @li if @c T is a class type with a member type @c first_argument_type,
* then @c first_argument_type is a synonym for @c T::first_argument_type;
*
* @li otherwise @c first_argument_type is not defined.
*/
typedef see_below first_argument_type;
/// The type of the function's second argument.
/**
* The type of @c second_argument_type is based on the type @c T of the
* wrapper's target object:
*
* @li if @c T is a pointer to a function type accepting two arguments, @c
* second_argument_type is a synonym for the return type of @c T;
*
* @li if @c T is a class type with a member type @c first_argument_type,
* then @c second_argument_type is a synonym for @c T::second_argument_type;
*
* @li otherwise @c second_argument_type is not defined.
*/
typedef see_below second_argument_type;
#endif // defined(GENERATING_DOCUMENTATION)
/// Construct a immediate executor wrapper for the specified object.
/**
* This constructor is only valid if the type @c T is constructible from type
* @c U.
*/
template <typename U>
immediate_executor_binder(const immediate_executor_type& e,
U&& u)
: executor_(e),
target_(static_cast<U&&>(u))
{
}
/// Copy constructor.
immediate_executor_binder(const immediate_executor_binder& other)
: executor_(other.get_immediate_executor()),
target_(other.get())
{
}
/// Construct a copy, but specify a different immediate executor.
immediate_executor_binder(const immediate_executor_type& e,
const immediate_executor_binder& other)
: executor_(e),
target_(other.get())
{
}
/// Construct a copy of a different immediate executor wrapper type.
/**
* This constructor is only valid if the @c Executor type is
* constructible from type @c OtherExecutor, and the type @c T is
* constructible from type @c U.
*/
template <typename U, typename OtherExecutor>
immediate_executor_binder(
const immediate_executor_binder<U, OtherExecutor>& other,
constraint_t<is_constructible<Executor, OtherExecutor>::value> = 0,
constraint_t<is_constructible<T, U>::value> = 0)
: executor_(other.get_immediate_executor()),
target_(other.get())
{
}
/// Construct a copy of a different immediate executor wrapper type, but
/// specify a different immediate executor.
/**
* This constructor is only valid if the type @c T is constructible from type
* @c U.
*/
template <typename U, typename OtherExecutor>
immediate_executor_binder(const immediate_executor_type& e,
const immediate_executor_binder<U, OtherExecutor>& other,
constraint_t<is_constructible<T, U>::value> = 0)
: executor_(e),
target_(other.get())
{
}
/// Move constructor.
immediate_executor_binder(immediate_executor_binder&& other)
: executor_(static_cast<immediate_executor_type&&>(
other.get_immediate_executor())),
target_(static_cast<T&&>(other.get()))
{
}
/// Move construct the target object, but specify a different immediate
/// executor.
immediate_executor_binder(const immediate_executor_type& e,
immediate_executor_binder&& other)
: executor_(e),
target_(static_cast<T&&>(other.get()))
{
}
/// Move construct from a different immediate executor wrapper type.
template <typename U, typename OtherExecutor>
immediate_executor_binder(
immediate_executor_binder<U, OtherExecutor>&& other,
constraint_t<is_constructible<Executor, OtherExecutor>::value> = 0,
constraint_t<is_constructible<T, U>::value> = 0)
: executor_(static_cast<OtherExecutor&&>(
other.get_immediate_executor())),
target_(static_cast<U&&>(other.get()))
{
}
/// Move construct from a different immediate executor wrapper type, but
/// specify a different immediate executor.
template <typename U, typename OtherExecutor>
immediate_executor_binder(const immediate_executor_type& e,
immediate_executor_binder<U, OtherExecutor>&& other,
constraint_t<is_constructible<T, U>::value> = 0)
: executor_(e),
target_(static_cast<U&&>(other.get()))
{
}
/// Destructor.
~immediate_executor_binder()
{
}
/// Obtain a reference to the target object.
target_type& get() noexcept
{
return target_;
}
/// Obtain a reference to the target object.
const target_type& get() const noexcept
{
return target_;
}
/// Obtain the associated immediate executor.
immediate_executor_type get_immediate_executor() const noexcept
{
return executor_;
}
/// Forwarding function call operator.
template <typename... Args>
result_of_t<T(Args...)> operator()(Args&&... args)
{
return target_(static_cast<Args&&>(args)...);
}
/// Forwarding function call operator.
template <typename... Args>
result_of_t<T(Args...)> operator()(Args&&... args) const
{
return target_(static_cast<Args&&>(args)...);
}
private:
Executor executor_;
T target_;
};
/// Associate an object of type @c T with a immediate executor of type
/// @c Executor.
template <typename Executor, typename T>
BOOST_ASIO_NODISCARD inline immediate_executor_binder<decay_t<T>, Executor>
bind_immediate_executor(const Executor& e, T&& t)
{
return immediate_executor_binder<
decay_t<T>, Executor>(
e, static_cast<T&&>(t));
}
#if !defined(GENERATING_DOCUMENTATION)
namespace detail {
template <typename TargetAsyncResult, typename Executor, typename = void>
class immediate_executor_binder_completion_handler_async_result
{
public:
template <typename T>
explicit immediate_executor_binder_completion_handler_async_result(T&)
{
}
};
template <typename TargetAsyncResult, typename Executor>
class immediate_executor_binder_completion_handler_async_result<
TargetAsyncResult, Executor,
void_t<
typename TargetAsyncResult::completion_handler_type
>>
{
private:
TargetAsyncResult target_;
public:
typedef immediate_executor_binder<
typename TargetAsyncResult::completion_handler_type, Executor>
completion_handler_type;
explicit immediate_executor_binder_completion_handler_async_result(
typename TargetAsyncResult::completion_handler_type& handler)
: target_(handler)
{
}
auto get() -> decltype(target_.get())
{
return target_.get();
}
};
template <typename TargetAsyncResult, typename = void>
struct immediate_executor_binder_async_result_return_type
{
};
template <typename TargetAsyncResult>
struct immediate_executor_binder_async_result_return_type<
TargetAsyncResult,
void_t<
typename TargetAsyncResult::return_type
>>
{
typedef typename TargetAsyncResult::return_type return_type;
};
} // namespace detail
template <typename T, typename Executor, typename Signature>
class async_result<immediate_executor_binder<T, Executor>, Signature> :
public detail::immediate_executor_binder_completion_handler_async_result<
async_result<T, Signature>, Executor>,
public detail::immediate_executor_binder_async_result_return_type<
async_result<T, Signature>>
{
public:
explicit async_result(immediate_executor_binder<T, Executor>& b)
: detail::immediate_executor_binder_completion_handler_async_result<
async_result<T, Signature>, Executor>(b.get())
{
}
template <typename Initiation>
struct init_wrapper
{
template <typename Init>
init_wrapper(const Executor& e, Init&& init)
: executor_(e),
initiation_(static_cast<Init&&>(init))
{
}
template <typename Handler, typename... Args>
void operator()(Handler&& handler, Args&&... args)
{
static_cast<Initiation&&>(initiation_)(
immediate_executor_binder<
decay_t<Handler>, Executor>(
executor_, static_cast<Handler&&>(handler)),
static_cast<Args&&>(args)...);
}
template <typename Handler, typename... Args>
void operator()(Handler&& handler, Args&&... args) const
{
initiation_(
immediate_executor_binder<
decay_t<Handler>, Executor>(
executor_, static_cast<Handler&&>(handler)),
static_cast<Args&&>(args)...);
}
Executor executor_;
Initiation initiation_;
};
template <typename Initiation, typename RawCompletionToken, typename... Args>
static auto initiate(Initiation&& initiation,
RawCompletionToken&& token, Args&&... args)
-> decltype(
async_initiate<T, Signature>(
declval<init_wrapper<decay_t<Initiation>>>(),
token.get(), static_cast<Args&&>(args)...))
{
return async_initiate<T, Signature>(
init_wrapper<decay_t<Initiation>>(
token.get_immediate_executor(),
static_cast<Initiation&&>(initiation)),
token.get(), static_cast<Args&&>(args)...);
}
private:
async_result(const async_result&) = delete;
async_result& operator=(const async_result&) = delete;
async_result<T, Signature> target_;
};
template <template <typename, typename> class Associator,
typename T, typename Executor, typename DefaultCandidate>
struct associator<Associator,
immediate_executor_binder<T, Executor>,
DefaultCandidate>
: Associator<T, DefaultCandidate>
{
static typename Associator<T, DefaultCandidate>::type get(
const immediate_executor_binder<T, Executor>& b) noexcept
{
return Associator<T, DefaultCandidate>::get(b.get());
}
static auto get(const immediate_executor_binder<T, Executor>& b,
const DefaultCandidate& c) noexcept
-> decltype(Associator<T, DefaultCandidate>::get(b.get(), c))
{
return Associator<T, DefaultCandidate>::get(b.get(), c);
}
};
template <typename T, typename Executor, typename Executor1>
struct associated_immediate_executor<
immediate_executor_binder<T, Executor>,
Executor1>
{
typedef Executor type;
static auto get(const immediate_executor_binder<T, Executor>& b,
const Executor1& = Executor1()) noexcept
-> decltype(b.get_immediate_executor())
{
return b.get_immediate_executor();
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_BIND_IMMEDIATE_EXECUTOR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/associated_immediate_executor.hpp | //
// associated_immediate_executor.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_ASSOCIATED_IMMEDIATE_EXECUTOR_HPP
#define BOOST_ASIO_ASSOCIATED_IMMEDIATE_EXECUTOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/associator.hpp>
#include <boost/asio/detail/functional.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/blocking.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/execution_context.hpp>
#include <boost/asio/is_executor.hpp>
#include <boost/asio/require.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename T, typename Executor>
struct associated_immediate_executor;
namespace detail {
template <typename T, typename = void>
struct has_immediate_executor_type : false_type
{
};
template <typename T>
struct has_immediate_executor_type<T,
void_t<typename T::immediate_executor_type>>
: true_type
{
};
template <typename E, typename = void, typename = void>
struct default_immediate_executor
{
typedef require_result_t<E, execution::blocking_t::never_t> type;
static type get(const E& e) noexcept
{
return boost::asio::require(e, execution::blocking.never);
}
};
template <typename E>
struct default_immediate_executor<E,
enable_if_t<
!execution::is_executor<E>::value
>,
enable_if_t<
is_executor<E>::value
>>
{
class type : public E
{
public:
template <typename Executor1>
explicit type(const Executor1& e,
constraint_t<
conditional_t<
!is_same<Executor1, type>::value,
is_convertible<Executor1, E>,
false_type
>::value
> = 0) noexcept
: E(e)
{
}
type(const type& other) noexcept
: E(static_cast<const E&>(other))
{
}
type(type&& other) noexcept
: E(static_cast<E&&>(other))
{
}
template <typename Function, typename Allocator>
void dispatch(Function&& f, const Allocator& a) const
{
this->post(static_cast<Function&&>(f), a);
}
friend bool operator==(const type& a, const type& b) noexcept
{
return static_cast<const E&>(a) == static_cast<const E&>(b);
}
friend bool operator!=(const type& a, const type& b) noexcept
{
return static_cast<const E&>(a) != static_cast<const E&>(b);
}
};
static type get(const E& e) noexcept
{
return type(e);
}
};
template <typename T, typename E, typename = void, typename = void>
struct associated_immediate_executor_impl
{
typedef void asio_associated_immediate_executor_is_unspecialised;
typedef typename default_immediate_executor<E>::type type;
static auto get(const T&, const E& e) noexcept
-> decltype(default_immediate_executor<E>::get(e))
{
return default_immediate_executor<E>::get(e);
}
};
template <typename T, typename E>
struct associated_immediate_executor_impl<T, E,
void_t<typename T::immediate_executor_type>>
{
typedef typename T::immediate_executor_type type;
static auto get(const T& t, const E&) noexcept
-> decltype(t.get_immediate_executor())
{
return t.get_immediate_executor();
}
};
template <typename T, typename E>
struct associated_immediate_executor_impl<T, E,
enable_if_t<
!has_immediate_executor_type<T>::value
>,
void_t<
typename associator<associated_immediate_executor, T, E>::type
>> : associator<associated_immediate_executor, T, E>
{
};
} // namespace detail
/// Traits type used to obtain the immediate executor associated with an object.
/**
* A program may specialise this traits type if the @c T template parameter in
* the specialisation is a user-defined type. The template parameter @c
* Executor shall be a type meeting the Executor requirements.
*
* Specialisations shall meet the following requirements, where @c t is a const
* reference to an object of type @c T, and @c e is an object of type @c
* Executor.
*
* @li Provide a nested typedef @c type that identifies a type meeting the
* Executor requirements.
*
* @li Provide a noexcept static member function named @c get, callable as @c
* get(t) and with return type @c type or a (possibly const) reference to @c
* type.
*
* @li Provide a noexcept static member function named @c get, callable as @c
* get(t,e) and with return type @c type or a (possibly const) reference to @c
* type.
*/
template <typename T, typename Executor>
struct associated_immediate_executor
#if !defined(GENERATING_DOCUMENTATION)
: detail::associated_immediate_executor_impl<T, Executor>
#endif // !defined(GENERATING_DOCUMENTATION)
{
#if defined(GENERATING_DOCUMENTATION)
/// If @c T has a nested type @c immediate_executor_type,
// <tt>T::immediate_executor_type</tt>. Otherwise @c Executor.
typedef see_below type;
/// If @c T has a nested type @c immediate_executor_type, returns
/// <tt>t.get_immediate_executor()</tt>. Otherwise returns
/// <tt>boost::asio::require(ex, boost::asio::execution::blocking.never)</tt>.
static decltype(auto) get(const T& t, const Executor& ex) noexcept;
#endif // defined(GENERATING_DOCUMENTATION)
};
/// Helper function to obtain an object's associated executor.
/**
* @returns <tt>associated_immediate_executor<T, Executor>::get(t, ex)</tt>
*/
template <typename T, typename Executor>
BOOST_ASIO_NODISCARD inline auto get_associated_immediate_executor(
const T& t, const Executor& ex,
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
> = 0) noexcept
-> decltype(associated_immediate_executor<T, Executor>::get(t, ex))
{
return associated_immediate_executor<T, Executor>::get(t, ex);
}
/// Helper function to obtain an object's associated executor.
/**
* @returns <tt>associated_immediate_executor<T, typename
* ExecutionContext::executor_type>::get(t, ctx.get_executor())</tt>
*/
template <typename T, typename ExecutionContext>
BOOST_ASIO_NODISCARD inline typename associated_immediate_executor<T,
typename ExecutionContext::executor_type>::type
get_associated_immediate_executor(const T& t, ExecutionContext& ctx,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
> = 0) noexcept
{
return associated_immediate_executor<T,
typename ExecutionContext::executor_type>::get(t, ctx.get_executor());
}
template <typename T, typename Executor>
using associated_immediate_executor_t =
typename associated_immediate_executor<T, Executor>::type;
namespace detail {
template <typename T, typename E, typename = void>
struct associated_immediate_executor_forwarding_base
{
};
template <typename T, typename E>
struct associated_immediate_executor_forwarding_base<T, E,
enable_if_t<
is_same<
typename associated_immediate_executor<T,
E>::asio_associated_immediate_executor_is_unspecialised,
void
>::value
>>
{
typedef void asio_associated_immediate_executor_is_unspecialised;
};
} // namespace detail
/// Specialisation of associated_immediate_executor for
/// @c std::reference_wrapper.
template <typename T, typename Executor>
struct associated_immediate_executor<reference_wrapper<T>, Executor>
#if !defined(GENERATING_DOCUMENTATION)
: detail::associated_immediate_executor_forwarding_base<T, Executor>
#endif // !defined(GENERATING_DOCUMENTATION)
{
/// Forwards @c type to the associator specialisation for the unwrapped type
/// @c T.
typedef typename associated_immediate_executor<T, Executor>::type type;
/// Forwards the request to get the executor to the associator specialisation
/// for the unwrapped type @c T.
static auto get(reference_wrapper<T> t, const Executor& ex) noexcept
-> decltype(associated_immediate_executor<T, Executor>::get(t.get(), ex))
{
return associated_immediate_executor<T, Executor>::get(t.get(), ex);
}
};
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_ASSOCIATED_IMMEDIATE_EXECUTOR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution_context.hpp | //
// execution_context.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_CONTEXT_HPP
#define BOOST_ASIO_EXECUTION_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <stdexcept>
#include <typeinfo>
#include <boost/asio/detail/noncopyable.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
class execution_context;
class io_context;
#if !defined(GENERATING_DOCUMENTATION)
template <typename Service> Service& use_service(execution_context&);
template <typename Service> Service& use_service(io_context&);
template <typename Service> void add_service(execution_context&, Service*);
template <typename Service> bool has_service(execution_context&);
#endif // !defined(GENERATING_DOCUMENTATION)
namespace detail { class service_registry; }
/// A context for function object execution.
/**
* An execution context represents a place where function objects will be
* executed. An @c io_context is an example of an execution context.
*
* @par The execution_context class and services
*
* Class execution_context implements an extensible, type-safe, polymorphic set
* of services, indexed by service type.
*
* Services exist to manage the resources that are shared across an execution
* context. For example, timers may be implemented in terms of a single timer
* queue, and this queue would be stored in a service.
*
* Access to the services of an execution_context is via three function
* templates, use_service(), add_service() and has_service().
*
* In a call to @c use_service<Service>(), the type argument chooses a service,
* making available all members of the named type. If @c Service is not present
* in an execution_context, an object of type @c Service is created and added
* to the execution_context. A C++ program can check if an execution_context
* implements a particular service with the function template @c
* has_service<Service>().
*
* Service objects may be explicitly added to an execution_context using the
* function template @c add_service<Service>(). If the @c Service is already
* present, the service_already_exists exception is thrown. If the owner of the
* service is not the same object as the execution_context parameter, the
* invalid_service_owner exception is thrown.
*
* Once a service reference is obtained from an execution_context object by
* calling use_service(), that reference remains usable as long as the owning
* execution_context object exists.
*
* All service implementations have execution_context::service as a public base
* class. Custom services may be implemented by deriving from this class and
* then added to an execution_context using the facilities described above.
*
* @par The execution_context as a base class
*
* Class execution_context may be used only as a base class for concrete
* execution context types. The @c io_context is an example of such a derived
* type.
*
* On destruction, a class that is derived from execution_context must perform
* <tt>execution_context::shutdown()</tt> followed by
* <tt>execution_context::destroy()</tt>.
*
* This destruction sequence permits programs to simplify their resource
* management by using @c shared_ptr<>. Where an object's lifetime is tied to
* the lifetime of a connection (or some other sequence of asynchronous
* operations), a @c shared_ptr to the object would be bound into the handlers
* for all asynchronous operations associated with it. This works as follows:
*
* @li When a single connection ends, all associated asynchronous operations
* complete. The corresponding handler objects are destroyed, and all @c
* shared_ptr references to the objects are destroyed.
*
* @li To shut down the whole program, the io_context function stop() is called
* to terminate any run() calls as soon as possible. The io_context destructor
* calls @c shutdown() and @c destroy() to destroy all pending handlers,
* causing all @c shared_ptr references to all connection objects to be
* destroyed.
*/
class execution_context
: private noncopyable
{
public:
class id;
class service;
public:
/// Constructor.
BOOST_ASIO_DECL execution_context();
/// Destructor.
BOOST_ASIO_DECL ~execution_context();
protected:
/// Shuts down all services in the context.
/**
* This function is implemented as follows:
*
* @li For each service object @c svc in the execution_context set, in
* reverse order of the beginning of service object lifetime, performs @c
* svc->shutdown().
*/
BOOST_ASIO_DECL void shutdown();
/// Destroys all services in the context.
/**
* This function is implemented as follows:
*
* @li For each service object @c svc in the execution_context set, in
* reverse order * of the beginning of service object lifetime, performs
* <tt>delete static_cast<execution_context::service*>(svc)</tt>.
*/
BOOST_ASIO_DECL void destroy();
public:
/// Fork-related event notifications.
enum fork_event
{
/// Notify the context that the process is about to fork.
fork_prepare,
/// Notify the context that the process has forked and is the parent.
fork_parent,
/// Notify the context that the process has forked and is the child.
fork_child
};
/// Notify the execution_context of a fork-related event.
/**
* This function is used to inform the execution_context that the process is
* about to fork, or has just forked. This allows the execution_context, and
* the services it contains, to perform any necessary housekeeping to ensure
* correct operation following a fork.
*
* This function must not be called while any other execution_context
* function, or any function associated with the execution_context's derived
* class, is being called in another thread. It is, however, safe to call
* this function from within a completion handler, provided no other thread
* is accessing the execution_context or its derived class.
*
* @param event A fork-related event.
*
* @throws boost::system::system_error Thrown on failure. If the notification
* fails the execution_context object should no longer be used and should be
* destroyed.
*
* @par Example
* The following code illustrates how to incorporate the notify_fork()
* function:
* @code my_execution_context.notify_fork(execution_context::fork_prepare);
* if (fork() == 0)
* {
* // This is the child process.
* my_execution_context.notify_fork(execution_context::fork_child);
* }
* else
* {
* // This is the parent process.
* my_execution_context.notify_fork(execution_context::fork_parent);
* } @endcode
*
* @note For each service object @c svc in the execution_context set,
* performs <tt>svc->notify_fork();</tt>. When processing the fork_prepare
* event, services are visited in reverse order of the beginning of service
* object lifetime. Otherwise, services are visited in order of the beginning
* of service object lifetime.
*/
BOOST_ASIO_DECL void notify_fork(fork_event event);
/// Obtain the service object corresponding to the given type.
/**
* This function is used to locate a service object that corresponds to the
* given service type. If there is no existing implementation of the service,
* then the execution_context will create a new instance of the service.
*
* @param e The execution_context object that owns the service.
*
* @return The service interface implementing the specified service type.
* Ownership of the service interface is not transferred to the caller.
*/
template <typename Service>
friend Service& use_service(execution_context& e);
/// Obtain the service object corresponding to the given type.
/**
* This function is used to locate a service object that corresponds to the
* given service type. If there is no existing implementation of the service,
* then the io_context will create a new instance of the service.
*
* @param ioc The io_context object that owns the service.
*
* @return The service interface implementing the specified service type.
* Ownership of the service interface is not transferred to the caller.
*
* @note This overload is preserved for backwards compatibility with services
* that inherit from io_context::service.
*/
template <typename Service>
friend Service& use_service(io_context& ioc);
/// Creates a service object and adds it to the execution_context.
/**
* This function is used to add a service to the execution_context.
*
* @param e The execution_context object that owns the service.
*
* @param args Zero or more arguments to be passed to the service
* constructor.
*
* @throws boost::asio::service_already_exists Thrown if a service of the
* given type is already present in the execution_context.
*/
template <typename Service, typename... Args>
friend Service& make_service(execution_context& e, Args&&... args);
/// (Deprecated: Use make_service().) Add a service object to the
/// execution_context.
/**
* This function is used to add a service to the execution_context.
*
* @param e The execution_context object that owns the service.
*
* @param svc The service object. On success, ownership of the service object
* is transferred to the execution_context. When the execution_context object
* is destroyed, it will destroy the service object by performing: @code
* delete static_cast<execution_context::service*>(svc) @endcode
*
* @throws boost::asio::service_already_exists Thrown if a service of the
* given type is already present in the execution_context.
*
* @throws boost::asio::invalid_service_owner Thrown if the service's owning
* execution_context is not the execution_context object specified by the
* @c e parameter.
*/
template <typename Service>
friend void add_service(execution_context& e, Service* svc);
/// Determine if an execution_context contains a specified service type.
/**
* This function is used to determine whether the execution_context contains a
* service object corresponding to the given service type.
*
* @param e The execution_context object that owns the service.
*
* @return A boolean indicating whether the execution_context contains the
* service.
*/
template <typename Service>
friend bool has_service(execution_context& e);
private:
// The service registry.
boost::asio::detail::service_registry* service_registry_;
};
/// Class used to uniquely identify a service.
class execution_context::id
: private noncopyable
{
public:
/// Constructor.
id() {}
};
/// Base class for all io_context services.
class execution_context::service
: private noncopyable
{
public:
/// Get the context object that owns the service.
execution_context& context();
protected:
/// Constructor.
/**
* @param owner The execution_context object that owns the service.
*/
BOOST_ASIO_DECL service(execution_context& owner);
/// Destructor.
BOOST_ASIO_DECL virtual ~service();
private:
/// Destroy all user-defined handler objects owned by the service.
virtual void shutdown() = 0;
/// Handle notification of a fork-related event to perform any necessary
/// housekeeping.
/**
* This function is not a pure virtual so that services only have to
* implement it if necessary. The default implementation does nothing.
*/
BOOST_ASIO_DECL virtual void notify_fork(
execution_context::fork_event event);
friend class boost::asio::detail::service_registry;
struct key
{
key() : type_info_(0), id_(0) {}
const std::type_info* type_info_;
const execution_context::id* id_;
} key_;
execution_context& owner_;
service* next_;
};
/// Exception thrown when trying to add a duplicate service to an
/// execution_context.
class service_already_exists
: public std::logic_error
{
public:
BOOST_ASIO_DECL service_already_exists();
};
/// Exception thrown when trying to add a service object to an
/// execution_context where the service has a different owner.
class invalid_service_owner
: public std::logic_error
{
public:
BOOST_ASIO_DECL invalid_service_owner();
};
namespace detail {
// Special derived service id type to keep classes header-file only.
template <typename Type>
class service_id
: public execution_context::id
{
};
// Special service base class to keep classes header-file only.
template <typename Type>
class execution_context_service_base
: public execution_context::service
{
public:
static service_id<Type> id;
// Constructor.
execution_context_service_base(execution_context& e)
: execution_context::service(e)
{
}
};
template <typename Type>
service_id<Type> execution_context_service_base<Type>::id;
} // namespace detail
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/impl/execution_context.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/impl/execution_context.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // BOOST_ASIO_EXECUTION_CONTEXT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/associated_cancellation_slot.hpp | //
// associated_cancellation_slot.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_ASSOCIATED_CANCELLATION_SLOT_HPP
#define BOOST_ASIO_ASSOCIATED_CANCELLATION_SLOT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/associator.hpp>
#include <boost/asio/cancellation_signal.hpp>
#include <boost/asio/detail/functional.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename T, typename CancellationSlot>
struct associated_cancellation_slot;
namespace detail {
template <typename T, typename = void>
struct has_cancellation_slot_type : false_type
{
};
template <typename T>
struct has_cancellation_slot_type<T, void_t<typename T::cancellation_slot_type>>
: true_type
{
};
template <typename T, typename S, typename = void, typename = void>
struct associated_cancellation_slot_impl
{
typedef void asio_associated_cancellation_slot_is_unspecialised;
typedef S type;
static type get(const T&) noexcept
{
return type();
}
static const type& get(const T&, const S& s) noexcept
{
return s;
}
};
template <typename T, typename S>
struct associated_cancellation_slot_impl<T, S,
void_t<typename T::cancellation_slot_type>>
{
typedef typename T::cancellation_slot_type type;
static auto get(const T& t) noexcept
-> decltype(t.get_cancellation_slot())
{
return t.get_cancellation_slot();
}
static auto get(const T& t, const S&) noexcept
-> decltype(t.get_cancellation_slot())
{
return t.get_cancellation_slot();
}
};
template <typename T, typename S>
struct associated_cancellation_slot_impl<T, S,
enable_if_t<
!has_cancellation_slot_type<T>::value
>,
void_t<
typename associator<associated_cancellation_slot, T, S>::type
>> : associator<associated_cancellation_slot, T, S>
{
};
} // namespace detail
/// Traits type used to obtain the cancellation_slot associated with an object.
/**
* A program may specialise this traits type if the @c T template parameter in
* the specialisation is a user-defined type. The template parameter @c
* CancellationSlot shall be a type meeting the CancellationSlot requirements.
*
* Specialisations shall meet the following requirements, where @c t is a const
* reference to an object of type @c T, and @c s is an object of type @c
* CancellationSlot.
*
* @li Provide a nested typedef @c type that identifies a type meeting the
* CancellationSlot requirements.
*
* @li Provide a noexcept static member function named @c get, callable as @c
* get(t) and with return type @c type or a (possibly const) reference to @c
* type.
*
* @li Provide a noexcept static member function named @c get, callable as @c
* get(t,s) and with return type @c type or a (possibly const) reference to @c
* type.
*/
template <typename T, typename CancellationSlot = cancellation_slot>
struct associated_cancellation_slot
#if !defined(GENERATING_DOCUMENTATION)
: detail::associated_cancellation_slot_impl<T, CancellationSlot>
#endif // !defined(GENERATING_DOCUMENTATION)
{
#if defined(GENERATING_DOCUMENTATION)
/// If @c T has a nested type @c cancellation_slot_type,
/// <tt>T::cancellation_slot_type</tt>. Otherwise
/// @c CancellationSlot.
typedef see_below type;
/// If @c T has a nested type @c cancellation_slot_type, returns
/// <tt>t.get_cancellation_slot()</tt>. Otherwise returns @c type().
static decltype(auto) get(const T& t) noexcept;
/// If @c T has a nested type @c cancellation_slot_type, returns
/// <tt>t.get_cancellation_slot()</tt>. Otherwise returns @c s.
static decltype(auto) get(const T& t,
const CancellationSlot& s) noexcept;
#endif // defined(GENERATING_DOCUMENTATION)
};
/// Helper function to obtain an object's associated cancellation_slot.
/**
* @returns <tt>associated_cancellation_slot<T>::get(t)</tt>
*/
template <typename T>
BOOST_ASIO_NODISCARD inline typename associated_cancellation_slot<T>::type
get_associated_cancellation_slot(const T& t) noexcept
{
return associated_cancellation_slot<T>::get(t);
}
/// Helper function to obtain an object's associated cancellation_slot.
/**
* @returns <tt>associated_cancellation_slot<T,
* CancellationSlot>::get(t, st)</tt>
*/
template <typename T, typename CancellationSlot>
BOOST_ASIO_NODISCARD inline auto get_associated_cancellation_slot(
const T& t, const CancellationSlot& st) noexcept
-> decltype(associated_cancellation_slot<T, CancellationSlot>::get(t, st))
{
return associated_cancellation_slot<T, CancellationSlot>::get(t, st);
}
template <typename T, typename CancellationSlot = cancellation_slot>
using associated_cancellation_slot_t =
typename associated_cancellation_slot<T, CancellationSlot>::type;
namespace detail {
template <typename T, typename S, typename = void>
struct associated_cancellation_slot_forwarding_base
{
};
template <typename T, typename S>
struct associated_cancellation_slot_forwarding_base<T, S,
enable_if_t<
is_same<
typename associated_cancellation_slot<T,
S>::asio_associated_cancellation_slot_is_unspecialised,
void
>::value
>>
{
typedef void asio_associated_cancellation_slot_is_unspecialised;
};
} // namespace detail
/// Specialisation of associated_cancellation_slot for @c
/// std::reference_wrapper.
template <typename T, typename CancellationSlot>
struct associated_cancellation_slot<reference_wrapper<T>, CancellationSlot>
#if !defined(GENERATING_DOCUMENTATION)
: detail::associated_cancellation_slot_forwarding_base<T, CancellationSlot>
#endif // !defined(GENERATING_DOCUMENTATION)
{
/// Forwards @c type to the associator specialisation for the unwrapped type
/// @c T.
typedef typename associated_cancellation_slot<T, CancellationSlot>::type type;
/// Forwards the request to get the cancellation slot to the associator
/// specialisation for the unwrapped type @c T.
static type get(reference_wrapper<T> t) noexcept
{
return associated_cancellation_slot<T, CancellationSlot>::get(t.get());
}
/// Forwards the request to get the cancellation slot to the associator
/// specialisation for the unwrapped type @c T.
static auto get(reference_wrapper<T> t, const CancellationSlot& s) noexcept
-> decltype(
associated_cancellation_slot<T, CancellationSlot>::get(t.get(), s))
{
return associated_cancellation_slot<T, CancellationSlot>::get(t.get(), s);
}
};
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_ASSOCIATED_CANCELLATION_SLOT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/multiple_exceptions.hpp | //
// multiple_exceptions.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_MULTIPLE_EXCEPTIONS_HPP
#define BOOST_ASIO_MULTIPLE_EXCEPTIONS_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <exception>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
/// Exception thrown when there are multiple pending exceptions to rethrow.
class multiple_exceptions
: public std::exception
{
public:
/// Constructor.
BOOST_ASIO_DECL multiple_exceptions(
std::exception_ptr first) noexcept;
/// Obtain message associated with exception.
BOOST_ASIO_DECL virtual const char* what() const
noexcept;
/// Obtain a pointer to the first exception.
BOOST_ASIO_DECL std::exception_ptr first_exception() const;
private:
std::exception_ptr first_;
};
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/impl/multiple_exceptions.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // BOOST_ASIO_MULTIPLE_EXCEPTIONS_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/uses_executor.hpp | //
// uses_executor.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_USES_EXECUTOR_HPP
#define BOOST_ASIO_USES_EXECUTOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
/// A special type, similar to std::nothrow_t, used to disambiguate
/// constructors that accept executor arguments.
/**
* The executor_arg_t struct is an empty structure type used as a unique type
* to disambiguate constructor and function overloading. Specifically, some
* types have constructors with executor_arg_t as the first argument,
* immediately followed by an argument of a type that satisfies the Executor
* type requirements.
*/
struct executor_arg_t
{
/// Constructor.
constexpr executor_arg_t() noexcept
{
}
};
/// A special value, similar to std::nothrow, used to disambiguate constructors
/// that accept executor arguments.
/**
* See boost::asio::executor_arg_t and boost::asio::uses_executor
* for more information.
*/
constexpr executor_arg_t executor_arg;
/// The uses_executor trait detects whether a type T has an associated executor
/// that is convertible from type Executor.
/**
* Meets the BinaryTypeTrait requirements. The Asio library provides a
* definition that is derived from false_type. A program may specialize this
* template to derive from true_type for a user-defined type T that can be
* constructed with an executor, where the first argument of a constructor has
* type executor_arg_t and the second argument is convertible from type
* Executor.
*/
template <typename T, typename Executor>
struct uses_executor : false_type {};
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_USES_EXECUTOR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution.hpp | //
// execution.hpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_HPP
#define BOOST_ASIO_EXECUTION_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/execution/allocator.hpp>
#include <boost/asio/execution/any_executor.hpp>
#include <boost/asio/execution/bad_executor.hpp>
#include <boost/asio/execution/blocking.hpp>
#include <boost/asio/execution/blocking_adaptation.hpp>
#include <boost/asio/execution/context.hpp>
#include <boost/asio/execution/context_as.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/execution/invocable_archetype.hpp>
#include <boost/asio/execution/mapping.hpp>
#include <boost/asio/execution/occupancy.hpp>
#include <boost/asio/execution/outstanding_work.hpp>
#include <boost/asio/execution/prefer_only.hpp>
#include <boost/asio/execution/relationship.hpp>
#endif // BOOST_ASIO_EXECUTION_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/bind_executor.hpp | //
// bind_executor.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_BIND_EXECUTOR_HPP
#define BOOST_ASIO_BIND_EXECUTOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/associated_executor.hpp>
#include <boost/asio/associator.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/execution_context.hpp>
#include <boost/asio/is_executor.hpp>
#include <boost/asio/uses_executor.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
// Helper to automatically define nested typedef result_type.
template <typename T, typename = void>
struct executor_binder_result_type
{
protected:
typedef void result_type_or_void;
};
template <typename T>
struct executor_binder_result_type<T, void_t<typename T::result_type>>
{
typedef typename T::result_type result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R>
struct executor_binder_result_type<R(*)()>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R>
struct executor_binder_result_type<R(&)()>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R, typename A1>
struct executor_binder_result_type<R(*)(A1)>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R, typename A1>
struct executor_binder_result_type<R(&)(A1)>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R, typename A1, typename A2>
struct executor_binder_result_type<R(*)(A1, A2)>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
template <typename R, typename A1, typename A2>
struct executor_binder_result_type<R(&)(A1, A2)>
{
typedef R result_type;
protected:
typedef result_type result_type_or_void;
};
// Helper to automatically define nested typedef argument_type.
template <typename T, typename = void>
struct executor_binder_argument_type {};
template <typename T>
struct executor_binder_argument_type<T, void_t<typename T::argument_type>>
{
typedef typename T::argument_type argument_type;
};
template <typename R, typename A1>
struct executor_binder_argument_type<R(*)(A1)>
{
typedef A1 argument_type;
};
template <typename R, typename A1>
struct executor_binder_argument_type<R(&)(A1)>
{
typedef A1 argument_type;
};
// Helper to automatically define nested typedefs first_argument_type and
// second_argument_type.
template <typename T, typename = void>
struct executor_binder_argument_types {};
template <typename T>
struct executor_binder_argument_types<T,
void_t<typename T::first_argument_type>>
{
typedef typename T::first_argument_type first_argument_type;
typedef typename T::second_argument_type second_argument_type;
};
template <typename R, typename A1, typename A2>
struct executor_binder_argument_type<R(*)(A1, A2)>
{
typedef A1 first_argument_type;
typedef A2 second_argument_type;
};
template <typename R, typename A1, typename A2>
struct executor_binder_argument_type<R(&)(A1, A2)>
{
typedef A1 first_argument_type;
typedef A2 second_argument_type;
};
// Helper to perform uses_executor construction of the target type, if
// required.
template <typename T, typename Executor, bool UsesExecutor>
class executor_binder_base;
template <typename T, typename Executor>
class executor_binder_base<T, Executor, true>
{
protected:
template <typename E, typename U>
executor_binder_base(E&& e, U&& u)
: executor_(static_cast<E&&>(e)),
target_(executor_arg_t(), executor_, static_cast<U&&>(u))
{
}
Executor executor_;
T target_;
};
template <typename T, typename Executor>
class executor_binder_base<T, Executor, false>
{
protected:
template <typename E, typename U>
executor_binder_base(E&& e, U&& u)
: executor_(static_cast<E&&>(e)),
target_(static_cast<U&&>(u))
{
}
Executor executor_;
T target_;
};
} // namespace detail
/// A call wrapper type to bind an executor of type @c Executor to an object of
/// type @c T.
template <typename T, typename Executor>
class executor_binder
#if !defined(GENERATING_DOCUMENTATION)
: public detail::executor_binder_result_type<T>,
public detail::executor_binder_argument_type<T>,
public detail::executor_binder_argument_types<T>,
private detail::executor_binder_base<
T, Executor, uses_executor<T, Executor>::value>
#endif // !defined(GENERATING_DOCUMENTATION)
{
public:
/// The type of the target object.
typedef T target_type;
/// The type of the associated executor.
typedef Executor executor_type;
#if defined(GENERATING_DOCUMENTATION)
/// The return type if a function.
/**
* The type of @c result_type is based on the type @c T of the wrapper's
* target object:
*
* @li if @c T is a pointer to function type, @c result_type is a synonym for
* the return type of @c T;
*
* @li if @c T is a class type with a member type @c result_type, then @c
* result_type is a synonym for @c T::result_type;
*
* @li otherwise @c result_type is not defined.
*/
typedef see_below result_type;
/// The type of the function's argument.
/**
* The type of @c argument_type is based on the type @c T of the wrapper's
* target object:
*
* @li if @c T is a pointer to a function type accepting a single argument,
* @c argument_type is a synonym for the return type of @c T;
*
* @li if @c T is a class type with a member type @c argument_type, then @c
* argument_type is a synonym for @c T::argument_type;
*
* @li otherwise @c argument_type is not defined.
*/
typedef see_below argument_type;
/// The type of the function's first argument.
/**
* The type of @c first_argument_type is based on the type @c T of the
* wrapper's target object:
*
* @li if @c T is a pointer to a function type accepting two arguments, @c
* first_argument_type is a synonym for the return type of @c T;
*
* @li if @c T is a class type with a member type @c first_argument_type,
* then @c first_argument_type is a synonym for @c T::first_argument_type;
*
* @li otherwise @c first_argument_type is not defined.
*/
typedef see_below first_argument_type;
/// The type of the function's second argument.
/**
* The type of @c second_argument_type is based on the type @c T of the
* wrapper's target object:
*
* @li if @c T is a pointer to a function type accepting two arguments, @c
* second_argument_type is a synonym for the return type of @c T;
*
* @li if @c T is a class type with a member type @c first_argument_type,
* then @c second_argument_type is a synonym for @c T::second_argument_type;
*
* @li otherwise @c second_argument_type is not defined.
*/
typedef see_below second_argument_type;
#endif // defined(GENERATING_DOCUMENTATION)
/// Construct an executor wrapper for the specified object.
/**
* This constructor is only valid if the type @c T is constructible from type
* @c U.
*/
template <typename U>
executor_binder(executor_arg_t, const executor_type& e,
U&& u)
: base_type(e, static_cast<U&&>(u))
{
}
/// Copy constructor.
executor_binder(const executor_binder& other)
: base_type(other.get_executor(), other.get())
{
}
/// Construct a copy, but specify a different executor.
executor_binder(executor_arg_t, const executor_type& e,
const executor_binder& other)
: base_type(e, other.get())
{
}
/// Construct a copy of a different executor wrapper type.
/**
* This constructor is only valid if the @c Executor type is constructible
* from type @c OtherExecutor, and the type @c T is constructible from type
* @c U.
*/
template <typename U, typename OtherExecutor>
executor_binder(const executor_binder<U, OtherExecutor>& other,
constraint_t<is_constructible<Executor, OtherExecutor>::value> = 0,
constraint_t<is_constructible<T, U>::value> = 0)
: base_type(other.get_executor(), other.get())
{
}
/// Construct a copy of a different executor wrapper type, but specify a
/// different executor.
/**
* This constructor is only valid if the type @c T is constructible from type
* @c U.
*/
template <typename U, typename OtherExecutor>
executor_binder(executor_arg_t, const executor_type& e,
const executor_binder<U, OtherExecutor>& other,
constraint_t<is_constructible<T, U>::value> = 0)
: base_type(e, other.get())
{
}
/// Move constructor.
executor_binder(executor_binder&& other)
: base_type(static_cast<executor_type&&>(other.get_executor()),
static_cast<T&&>(other.get()))
{
}
/// Move construct the target object, but specify a different executor.
executor_binder(executor_arg_t, const executor_type& e,
executor_binder&& other)
: base_type(e, static_cast<T&&>(other.get()))
{
}
/// Move construct from a different executor wrapper type.
template <typename U, typename OtherExecutor>
executor_binder(executor_binder<U, OtherExecutor>&& other,
constraint_t<is_constructible<Executor, OtherExecutor>::value> = 0,
constraint_t<is_constructible<T, U>::value> = 0)
: base_type(static_cast<OtherExecutor&&>(other.get_executor()),
static_cast<U&&>(other.get()))
{
}
/// Move construct from a different executor wrapper type, but specify a
/// different executor.
template <typename U, typename OtherExecutor>
executor_binder(executor_arg_t, const executor_type& e,
executor_binder<U, OtherExecutor>&& other,
constraint_t<is_constructible<T, U>::value> = 0)
: base_type(e, static_cast<U&&>(other.get()))
{
}
/// Destructor.
~executor_binder()
{
}
/// Obtain a reference to the target object.
target_type& get() noexcept
{
return this->target_;
}
/// Obtain a reference to the target object.
const target_type& get() const noexcept
{
return this->target_;
}
/// Obtain the associated executor.
executor_type get_executor() const noexcept
{
return this->executor_;
}
/// Forwarding function call operator.
template <typename... Args>
result_of_t<T(Args...)> operator()(Args&&... args)
{
return this->target_(static_cast<Args&&>(args)...);
}
/// Forwarding function call operator.
template <typename... Args>
result_of_t<T(Args...)> operator()(Args&&... args) const
{
return this->target_(static_cast<Args&&>(args)...);
}
private:
typedef detail::executor_binder_base<T, Executor,
uses_executor<T, Executor>::value> base_type;
};
/// Associate an object of type @c T with an executor of type @c Executor.
template <typename Executor, typename T>
BOOST_ASIO_NODISCARD inline executor_binder<decay_t<T>, Executor>
bind_executor(const Executor& ex, T&& t,
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
> = 0)
{
return executor_binder<decay_t<T>, Executor>(
executor_arg_t(), ex, static_cast<T&&>(t));
}
/// Associate an object of type @c T with an execution context's executor.
template <typename ExecutionContext, typename T>
BOOST_ASIO_NODISCARD inline executor_binder<decay_t<T>,
typename ExecutionContext::executor_type>
bind_executor(ExecutionContext& ctx, T&& t,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
> = 0)
{
return executor_binder<decay_t<T>, typename ExecutionContext::executor_type>(
executor_arg_t(), ctx.get_executor(), static_cast<T&&>(t));
}
#if !defined(GENERATING_DOCUMENTATION)
template <typename T, typename Executor>
struct uses_executor<executor_binder<T, Executor>, Executor>
: true_type {};
namespace detail {
template <typename TargetAsyncResult, typename Executor, typename = void>
class executor_binder_completion_handler_async_result
{
public:
template <typename T>
explicit executor_binder_completion_handler_async_result(T&)
{
}
};
template <typename TargetAsyncResult, typename Executor>
class executor_binder_completion_handler_async_result<
TargetAsyncResult, Executor,
void_t<typename TargetAsyncResult::completion_handler_type >>
{
private:
TargetAsyncResult target_;
public:
typedef executor_binder<
typename TargetAsyncResult::completion_handler_type, Executor>
completion_handler_type;
explicit executor_binder_completion_handler_async_result(
typename TargetAsyncResult::completion_handler_type& handler)
: target_(handler)
{
}
auto get() -> decltype(target_.get())
{
return target_.get();
}
};
template <typename TargetAsyncResult, typename = void>
struct executor_binder_async_result_return_type
{
};
template <typename TargetAsyncResult>
struct executor_binder_async_result_return_type<TargetAsyncResult,
void_t<typename TargetAsyncResult::return_type>>
{
typedef typename TargetAsyncResult::return_type return_type;
};
} // namespace detail
template <typename T, typename Executor, typename Signature>
class async_result<executor_binder<T, Executor>, Signature> :
public detail::executor_binder_completion_handler_async_result<
async_result<T, Signature>, Executor>,
public detail::executor_binder_async_result_return_type<
async_result<T, Signature>>
{
public:
explicit async_result(executor_binder<T, Executor>& b)
: detail::executor_binder_completion_handler_async_result<
async_result<T, Signature>, Executor>(b.get())
{
}
template <typename Initiation>
struct init_wrapper
{
template <typename Init>
init_wrapper(const Executor& ex, Init&& init)
: ex_(ex),
initiation_(static_cast<Init&&>(init))
{
}
template <typename Handler, typename... Args>
void operator()(Handler&& handler, Args&&... args)
{
static_cast<Initiation&&>(initiation_)(
executor_binder<decay_t<Handler>, Executor>(
executor_arg_t(), ex_, static_cast<Handler&&>(handler)),
static_cast<Args&&>(args)...);
}
template <typename Handler, typename... Args>
void operator()(Handler&& handler, Args&&... args) const
{
initiation_(
executor_binder<decay_t<Handler>, Executor>(
executor_arg_t(), ex_, static_cast<Handler&&>(handler)),
static_cast<Args&&>(args)...);
}
Executor ex_;
Initiation initiation_;
};
template <typename Initiation, typename RawCompletionToken, typename... Args>
static auto initiate(Initiation&& initiation,
RawCompletionToken&& token, Args&&... args)
-> decltype(
async_initiate<T, Signature>(
declval<init_wrapper<decay_t<Initiation>>>(),
token.get(), static_cast<Args&&>(args)...))
{
return async_initiate<T, Signature>(
init_wrapper<decay_t<Initiation>>(
token.get_executor(), static_cast<Initiation&&>(initiation)),
token.get(), static_cast<Args&&>(args)...);
}
private:
async_result(const async_result&) = delete;
async_result& operator=(const async_result&) = delete;
};
template <template <typename, typename> class Associator,
typename T, typename Executor, typename DefaultCandidate>
struct associator<Associator, executor_binder<T, Executor>, DefaultCandidate>
: Associator<T, DefaultCandidate>
{
static typename Associator<T, DefaultCandidate>::type get(
const executor_binder<T, Executor>& b) noexcept
{
return Associator<T, DefaultCandidate>::get(b.get());
}
static auto get(const executor_binder<T, Executor>& b,
const DefaultCandidate& c) noexcept
-> decltype(Associator<T, DefaultCandidate>::get(b.get(), c))
{
return Associator<T, DefaultCandidate>::get(b.get(), c);
}
};
template <typename T, typename Executor, typename Executor1>
struct associated_executor<executor_binder<T, Executor>, Executor1>
{
typedef Executor type;
static auto get(const executor_binder<T, Executor>& b,
const Executor1& = Executor1()) noexcept
-> decltype(b.get_executor())
{
return b.get_executor();
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_BIND_EXECUTOR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/buffered_read_stream.hpp | //
// buffered_read_stream.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_BUFFERED_READ_STREAM_HPP
#define BOOST_ASIO_BUFFERED_READ_STREAM_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <boost/asio/async_result.hpp>
#include <boost/asio/buffered_read_stream_fwd.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/buffer_resize_guard.hpp>
#include <boost/asio/detail/buffered_stream_storage.hpp>
#include <boost/asio/detail/noncopyable.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
template <typename> class initiate_async_buffered_fill;
template <typename> class initiate_async_buffered_read_some;
} // namespace detail
/// Adds buffering to the read-related operations of a stream.
/**
* The buffered_read_stream class template can be used to add buffering to the
* synchronous and asynchronous read operations of a stream.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*
* @par Concepts:
* AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.
*/
template <typename Stream>
class buffered_read_stream
: private noncopyable
{
public:
/// The type of the next layer.
typedef remove_reference_t<Stream> next_layer_type;
/// The type of the lowest layer.
typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
/// The type of the executor associated with the object.
typedef typename lowest_layer_type::executor_type executor_type;
#if defined(GENERATING_DOCUMENTATION)
/// The default buffer size.
static const std::size_t default_buffer_size = implementation_defined;
#else
BOOST_ASIO_STATIC_CONSTANT(std::size_t, default_buffer_size = 1024);
#endif
/// Construct, passing the specified argument to initialise the next layer.
template <typename Arg>
explicit buffered_read_stream(Arg&& a)
: next_layer_(static_cast<Arg&&>(a)),
storage_(default_buffer_size)
{
}
/// Construct, passing the specified argument to initialise the next layer.
template <typename Arg>
buffered_read_stream(Arg&& a,
std::size_t buffer_size)
: next_layer_(static_cast<Arg&&>(a)),
storage_(buffer_size)
{
}
/// Get a reference to the next layer.
next_layer_type& next_layer()
{
return next_layer_;
}
/// Get a reference to the lowest layer.
lowest_layer_type& lowest_layer()
{
return next_layer_.lowest_layer();
}
/// Get a const reference to the lowest layer.
const lowest_layer_type& lowest_layer() const
{
return next_layer_.lowest_layer();
}
/// Get the executor associated with the object.
executor_type get_executor() noexcept
{
return next_layer_.lowest_layer().get_executor();
}
/// Close the stream.
void close()
{
next_layer_.close();
}
/// Close the stream.
BOOST_ASIO_SYNC_OP_VOID close(boost::system::error_code& ec)
{
next_layer_.close(ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Write the given data to the stream. Returns the number of bytes written.
/// Throws an exception on failure.
template <typename ConstBufferSequence>
std::size_t write_some(const ConstBufferSequence& buffers)
{
return next_layer_.write_some(buffers);
}
/// Write the given data to the stream. Returns the number of bytes written,
/// or 0 if an error occurred.
template <typename ConstBufferSequence>
std::size_t write_some(const ConstBufferSequence& buffers,
boost::system::error_code& ec)
{
return next_layer_.write_some(buffers, ec);
}
/// Start an asynchronous write. The data being written must be valid for the
/// lifetime of the asynchronous operation.
/**
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*/
template <typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteHandler = default_completion_token_t<executor_type>>
auto async_write_some(const ConstBufferSequence& buffers,
WriteHandler&& handler = default_completion_token_t<executor_type>())
-> decltype(
declval<conditional_t<true, Stream&, WriteHandler>>().async_write_some(
buffers, static_cast<WriteHandler&&>(handler)))
{
return next_layer_.async_write_some(buffers,
static_cast<WriteHandler&&>(handler));
}
/// Fill the buffer with some data. Returns the number of bytes placed in the
/// buffer as a result of the operation. Throws an exception on failure.
std::size_t fill();
/// Fill the buffer with some data. Returns the number of bytes placed in the
/// buffer as a result of the operation, or 0 if an error occurred.
std::size_t fill(boost::system::error_code& ec);
/// Start an asynchronous fill.
/**
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*/
template <
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadHandler = default_completion_token_t<executor_type>>
auto async_fill(
ReadHandler&& handler = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<ReadHandler,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_buffered_fill<Stream>>(),
handler, declval<detail::buffered_stream_storage*>()));
/// Read some data from the stream. Returns the number of bytes read. Throws
/// an exception on failure.
template <typename MutableBufferSequence>
std::size_t read_some(const MutableBufferSequence& buffers);
/// Read some data from the stream. Returns the number of bytes read or 0 if
/// an error occurred.
template <typename MutableBufferSequence>
std::size_t read_some(const MutableBufferSequence& buffers,
boost::system::error_code& ec);
/// Start an asynchronous read. The buffer into which the data will be read
/// must be valid for the lifetime of the asynchronous operation.
/**
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*/
template <typename MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadHandler = default_completion_token_t<executor_type>>
auto async_read_some(const MutableBufferSequence& buffers,
ReadHandler&& handler = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<ReadHandler,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_buffered_read_some<Stream>>(),
handler, declval<detail::buffered_stream_storage*>(), buffers));
/// Peek at the incoming data on the stream. Returns the number of bytes read.
/// Throws an exception on failure.
template <typename MutableBufferSequence>
std::size_t peek(const MutableBufferSequence& buffers);
/// Peek at the incoming data on the stream. Returns the number of bytes read,
/// or 0 if an error occurred.
template <typename MutableBufferSequence>
std::size_t peek(const MutableBufferSequence& buffers,
boost::system::error_code& ec);
/// Determine the amount of data that may be read without blocking.
std::size_t in_avail()
{
return storage_.size();
}
/// Determine the amount of data that may be read without blocking.
std::size_t in_avail(boost::system::error_code& ec)
{
ec = boost::system::error_code();
return storage_.size();
}
private:
/// Copy data out of the internal buffer to the specified target buffer.
/// Returns the number of bytes copied.
template <typename MutableBufferSequence>
std::size_t copy(const MutableBufferSequence& buffers)
{
std::size_t bytes_copied = boost::asio::buffer_copy(
buffers, storage_.data(), storage_.size());
storage_.consume(bytes_copied);
return bytes_copied;
}
/// Copy data from the internal buffer to the specified target buffer, without
/// removing the data from the internal buffer. Returns the number of bytes
/// copied.
template <typename MutableBufferSequence>
std::size_t peek_copy(const MutableBufferSequence& buffers)
{
return boost::asio::buffer_copy(buffers, storage_.data(), storage_.size());
}
/// The next layer.
Stream next_layer_;
// The data in the buffer.
detail::buffered_stream_storage storage_;
};
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/impl/buffered_read_stream.hpp>
#endif // BOOST_ASIO_BUFFERED_READ_STREAM_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/serial_port.hpp | //
// serial_port.hpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.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)
//
#ifndef BOOST_ASIO_SERIAL_PORT_HPP
#define BOOST_ASIO_SERIAL_PORT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HAS_SERIAL_PORT) \
|| defined(GENERATING_DOCUMENTATION)
#include <boost/asio/basic_serial_port.hpp>
namespace boost {
namespace asio {
/// Typedef for the typical usage of a serial port.
typedef basic_serial_port<> serial_port;
} // namespace asio
} // namespace boost
#endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
// || defined(GENERATING_DOCUMENTATION)
#endif // BOOST_ASIO_SERIAL_PORT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/unyield.hpp | //
// unyield.hpp
// ~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifdef reenter
# undef reenter
#endif
#ifdef yield
# undef yield
#endif
#ifdef fork
# undef fork
#endif
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/rfc2818_verification.hpp | //
// ssl/rfc2818_verification.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_RFC2818_VERIFICATION_HPP
#define BOOST_ASIO_SSL_RFC2818_VERIFICATION_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_NO_DEPRECATED)
#include <string>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/ssl/verify_context.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
/// (Deprecated. Use ssl::host_name_verification.) Verifies a certificate
/// against a hostname according to the rules described in RFC 2818.
/**
* @par Example
* The following example shows how to synchronously open a secure connection to
* a given host name:
* @code
* using boost::asio::ip::tcp;
* namespace ssl = boost::asio::ssl;
* typedef ssl::stream<tcp::socket> ssl_socket;
*
* // Create a context that uses the default paths for finding CA certificates.
* ssl::context ctx(ssl::context::sslv23);
* ctx.set_default_verify_paths();
*
* // Open a socket and connect it to the remote host.
* boost::asio::io_context io_context;
* ssl_socket sock(io_context, ctx);
* tcp::resolver resolver(io_context);
* tcp::resolver::query query("host.name", "https");
* boost::asio::connect(sock.lowest_layer(), resolver.resolve(query));
* sock.lowest_layer().set_option(tcp::no_delay(true));
*
* // Perform SSL handshake and verify the remote host's certificate.
* sock.set_verify_mode(ssl::verify_peer);
* sock.set_verify_callback(ssl::rfc2818_verification("host.name"));
* sock.handshake(ssl_socket::client);
*
* // ... read and write as normal ...
* @endcode
*/
class rfc2818_verification
{
public:
/// The type of the function object's result.
typedef bool result_type;
/// Constructor.
explicit rfc2818_verification(const std::string& host)
: host_(host)
{
}
/// Perform certificate verification.
BOOST_ASIO_DECL bool operator()(bool preverified, verify_context& ctx) const;
private:
// Helper function to check a host name against a pattern.
BOOST_ASIO_DECL static bool match_pattern(const char* pattern,
std::size_t pattern_length, const char* host);
// Helper function to check a host name against an IPv4 address
// The host name to be checked.
std::string host_;
};
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/ssl/impl/rfc2818_verification.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
#endif // BOOST_ASIO_SSL_RFC2818_VERIFICATION_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/context_base.hpp | //
// ssl/context_base.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_CONTEXT_BASE_HPP
#define BOOST_ASIO_SSL_CONTEXT_BASE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
/// The context_base class is used as a base for the basic_context class
/// template so that we have a common place to define various enums.
class context_base
{
public:
/// Different methods supported by a context.
enum method
{
/// Generic SSL version 2.
sslv2,
/// SSL version 2 client.
sslv2_client,
/// SSL version 2 server.
sslv2_server,
/// Generic SSL version 3.
sslv3,
/// SSL version 3 client.
sslv3_client,
/// SSL version 3 server.
sslv3_server,
/// Generic TLS version 1.
tlsv1,
/// TLS version 1 client.
tlsv1_client,
/// TLS version 1 server.
tlsv1_server,
/// Generic SSL/TLS.
sslv23,
/// SSL/TLS client.
sslv23_client,
/// SSL/TLS server.
sslv23_server,
/// Generic TLS version 1.1.
tlsv11,
/// TLS version 1.1 client.
tlsv11_client,
/// TLS version 1.1 server.
tlsv11_server,
/// Generic TLS version 1.2.
tlsv12,
/// TLS version 1.2 client.
tlsv12_client,
/// TLS version 1.2 server.
tlsv12_server,
/// Generic TLS version 1.3.
tlsv13,
/// TLS version 1.3 client.
tlsv13_client,
/// TLS version 1.3 server.
tlsv13_server,
/// Generic TLS.
tls,
/// TLS client.
tls_client,
/// TLS server.
tls_server
};
/// Bitmask type for SSL options.
typedef uint64_t options;
#if defined(GENERATING_DOCUMENTATION)
/// Implement various bug workarounds.
static const uint64_t default_workarounds = implementation_defined;
/// Always create a new key when using tmp_dh parameters.
static const uint64_t single_dh_use = implementation_defined;
/// Disable SSL v2.
static const uint64_t no_sslv2 = implementation_defined;
/// Disable SSL v3.
static const uint64_t no_sslv3 = implementation_defined;
/// Disable TLS v1.
static const uint64_t no_tlsv1 = implementation_defined;
/// Disable TLS v1.1.
static const uint64_t no_tlsv1_1 = implementation_defined;
/// Disable TLS v1.2.
static const uint64_t no_tlsv1_2 = implementation_defined;
/// Disable TLS v1.3.
static const uint64_t no_tlsv1_3 = implementation_defined;
/// Disable compression. Compression is disabled by default.
static const uint64_t no_compression = implementation_defined;
#else
BOOST_ASIO_STATIC_CONSTANT(uint64_t, default_workarounds = SSL_OP_ALL);
BOOST_ASIO_STATIC_CONSTANT(uint64_t, single_dh_use = SSL_OP_SINGLE_DH_USE);
BOOST_ASIO_STATIC_CONSTANT(uint64_t, no_sslv2 = SSL_OP_NO_SSLv2);
BOOST_ASIO_STATIC_CONSTANT(uint64_t, no_sslv3 = SSL_OP_NO_SSLv3);
BOOST_ASIO_STATIC_CONSTANT(uint64_t, no_tlsv1 = SSL_OP_NO_TLSv1);
# if defined(SSL_OP_NO_TLSv1_1)
BOOST_ASIO_STATIC_CONSTANT(uint64_t, no_tlsv1_1 = SSL_OP_NO_TLSv1_1);
# else // defined(SSL_OP_NO_TLSv1_1)
BOOST_ASIO_STATIC_CONSTANT(uint64_t, no_tlsv1_1 = 0x10000000L);
# endif // defined(SSL_OP_NO_TLSv1_1)
# if defined(SSL_OP_NO_TLSv1_2)
BOOST_ASIO_STATIC_CONSTANT(uint64_t, no_tlsv1_2 = SSL_OP_NO_TLSv1_2);
# else // defined(SSL_OP_NO_TLSv1_2)
BOOST_ASIO_STATIC_CONSTANT(uint64_t, no_tlsv1_2 = 0x08000000L);
# endif // defined(SSL_OP_NO_TLSv1_2)
# if defined(SSL_OP_NO_TLSv1_3)
BOOST_ASIO_STATIC_CONSTANT(uint64_t, no_tlsv1_3 = SSL_OP_NO_TLSv1_3);
# else // defined(SSL_OP_NO_TLSv1_3)
BOOST_ASIO_STATIC_CONSTANT(uint64_t, no_tlsv1_3 = 0x20000000L);
# endif // defined(SSL_OP_NO_TLSv1_3)
# if defined(SSL_OP_NO_COMPRESSION)
BOOST_ASIO_STATIC_CONSTANT(uint64_t, no_compression = SSL_OP_NO_COMPRESSION);
# else // defined(SSL_OP_NO_COMPRESSION)
BOOST_ASIO_STATIC_CONSTANT(uint64_t, no_compression = 0x20000L);
# endif // defined(SSL_OP_NO_COMPRESSION)
#endif
/// File format types.
enum file_format
{
/// ASN.1 file.
asn1,
/// PEM file.
pem
};
#if !defined(GENERATING_DOCUMENTATION)
// The following types and constants are preserved for backward compatibility.
// New programs should use the equivalents of the same names that are defined
// in the boost::asio::ssl namespace.
typedef int verify_mode;
BOOST_ASIO_STATIC_CONSTANT(int, verify_none = SSL_VERIFY_NONE);
BOOST_ASIO_STATIC_CONSTANT(int, verify_peer = SSL_VERIFY_PEER);
BOOST_ASIO_STATIC_CONSTANT(int,
verify_fail_if_no_peer_cert = SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
BOOST_ASIO_STATIC_CONSTANT(int, verify_client_once = SSL_VERIFY_CLIENT_ONCE);
#endif
/// Purpose of PEM password.
enum password_purpose
{
/// The password is needed for reading/decryption.
for_reading,
/// The password is needed for writing/encryption.
for_writing
};
protected:
/// Protected destructor to prevent deletion through this type.
~context_base()
{
}
};
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_CONTEXT_BASE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/error.hpp | //
// ssl/error.hpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_ERROR_HPP
#define BOOST_ASIO_SSL_ERROR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace error {
enum ssl_errors
{
// Error numbers are those produced by openssl.
};
extern BOOST_ASIO_DECL
const boost::system::error_category& get_ssl_category();
static const boost::system::error_category&
ssl_category BOOST_ASIO_UNUSED_VARIABLE
= boost::asio::error::get_ssl_category();
} // namespace error
namespace ssl {
namespace error {
enum stream_errors
{
#if defined(GENERATING_DOCUMENTATION)
/// The underlying stream closed before the ssl stream gracefully shut down.
stream_truncated,
/// The underlying SSL library returned a system error without providing
/// further information.
unspecified_system_error,
/// The underlying SSL library generated an unexpected result from a function
/// call.
unexpected_result
#else // defined(GENERATING_DOCUMENTATION)
# if (OPENSSL_VERSION_NUMBER < 0x10100000L) \
&& !defined(OPENSSL_IS_BORINGSSL) \
&& !defined(BOOST_ASIO_USE_WOLFSSL)
stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ),
# else
stream_truncated = 1,
# endif
unspecified_system_error = 2,
unexpected_result = 3
#endif // defined(GENERATING_DOCUMENTATION)
};
extern BOOST_ASIO_DECL
const boost::system::error_category& get_stream_category();
static const boost::system::error_category&
stream_category BOOST_ASIO_UNUSED_VARIABLE
= boost::asio::ssl::error::get_stream_category();
} // namespace error
} // namespace ssl
} // namespace asio
} // namespace boost
namespace boost {
namespace system {
template<> struct is_error_code_enum<boost::asio::error::ssl_errors>
{
static const bool value = true;
};
template<> struct is_error_code_enum<boost::asio::ssl::error::stream_errors>
{
static const bool value = true;
};
} // namespace system
} // namespace boost
namespace boost {
namespace asio {
namespace error {
inline boost::system::error_code make_error_code(ssl_errors e)
{
return boost::system::error_code(
static_cast<int>(e), get_ssl_category());
}
} // namespace error
namespace ssl {
namespace error {
inline boost::system::error_code make_error_code(stream_errors e)
{
return boost::system::error_code(
static_cast<int>(e), get_stream_category());
}
} // namespace error
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/ssl/impl/error.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // BOOST_ASIO_SSL_ERROR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/context.hpp | //
// ssl/context.hpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_CONTEXT_HPP
#define BOOST_ASIO_SSL_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <string>
#include <boost/asio/buffer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ssl/context_base.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/ssl/detail/openssl_init.hpp>
#include <boost/asio/ssl/detail/password_callback.hpp>
#include <boost/asio/ssl/detail/verify_callback.hpp>
#include <boost/asio/ssl/verify_mode.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
class context
: public context_base,
private noncopyable
{
public:
/// The native handle type of the SSL context.
typedef SSL_CTX* native_handle_type;
/// Constructor.
BOOST_ASIO_DECL explicit context(method m);
/// Construct to take ownership of a native handle.
BOOST_ASIO_DECL explicit context(native_handle_type native_handle);
/// Move-construct a context from another.
/**
* This constructor moves an SSL context from one object to another.
*
* @param other The other context object from which the move will occur.
*
* @note Following the move, the following operations only are valid for the
* moved-from object:
* @li Destruction.
* @li As a target for move-assignment.
*/
BOOST_ASIO_DECL context(context&& other);
/// Move-assign a context from another.
/**
* This assignment operator moves an SSL context from one object to another.
*
* @param other The other context object from which the move will occur.
*
* @note Following the move, the following operations only are valid for the
* moved-from object:
* @li Destruction.
* @li As a target for move-assignment.
*/
BOOST_ASIO_DECL context& operator=(context&& other);
/// Destructor.
BOOST_ASIO_DECL ~context();
/// Get the underlying implementation in the native type.
/**
* This function may be used to obtain the underlying implementation of the
* context. This is intended to allow access to context functionality that is
* not otherwise provided.
*/
BOOST_ASIO_DECL native_handle_type native_handle();
/// Clear options on the context.
/**
* This function may be used to configure the SSL options used by the context.
*
* @param o A bitmask of options. The available option values are defined in
* the context_base class. The specified options, if currently enabled on the
* context, are cleared.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_clear_options.
*/
BOOST_ASIO_DECL void clear_options(options o);
/// Clear options on the context.
/**
* This function may be used to configure the SSL options used by the context.
*
* @param o A bitmask of options. The available option values are defined in
* the context_base class. The specified options, if currently enabled on the
* context, are cleared.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_clear_options.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID clear_options(options o,
boost::system::error_code& ec);
/// Set options on the context.
/**
* This function may be used to configure the SSL options used by the context.
*
* @param o A bitmask of options. The available option values are defined in
* the context_base class. The options are bitwise-ored with any existing
* value for the options.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_set_options.
*/
BOOST_ASIO_DECL void set_options(options o);
/// Set options on the context.
/**
* This function may be used to configure the SSL options used by the context.
*
* @param o A bitmask of options. The available option values are defined in
* the context_base class. The options are bitwise-ored with any existing
* value for the options.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_set_options.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID set_options(options o,
boost::system::error_code& ec);
/// Set the peer verification mode.
/**
* This function may be used to configure the peer verification mode used by
* the context.
*
* @param v A bitmask of peer verification modes. See @ref verify_mode for
* available values.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_set_verify.
*/
BOOST_ASIO_DECL void set_verify_mode(verify_mode v);
/// Set the peer verification mode.
/**
* This function may be used to configure the peer verification mode used by
* the context.
*
* @param v A bitmask of peer verification modes. See @ref verify_mode for
* available values.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_set_verify.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID set_verify_mode(
verify_mode v, boost::system::error_code& ec);
/// Set the peer verification depth.
/**
* This function may be used to configure the maximum verification depth
* allowed by the context.
*
* @param depth Maximum depth for the certificate chain verification that
* shall be allowed.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_set_verify_depth.
*/
BOOST_ASIO_DECL void set_verify_depth(int depth);
/// Set the peer verification depth.
/**
* This function may be used to configure the maximum verification depth
* allowed by the context.
*
* @param depth Maximum depth for the certificate chain verification that
* shall be allowed.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_set_verify_depth.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID set_verify_depth(
int depth, boost::system::error_code& ec);
/// Set the callback used to verify peer certificates.
/**
* This function is used to specify a callback function that will be called
* by the implementation when it needs to verify a peer certificate.
*
* @param callback The function object to be used for verifying a certificate.
* The function signature of the handler must be:
* @code bool verify_callback(
* bool preverified, // True if the certificate passed pre-verification.
* verify_context& ctx // The peer certificate and other context.
* ); @endcode
* The return value of the callback is true if the certificate has passed
* verification, false otherwise.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_set_verify.
*/
template <typename VerifyCallback>
void set_verify_callback(VerifyCallback callback);
/// Set the callback used to verify peer certificates.
/**
* This function is used to specify a callback function that will be called
* by the implementation when it needs to verify a peer certificate.
*
* @param callback The function object to be used for verifying a certificate.
* The function signature of the handler must be:
* @code bool verify_callback(
* bool preverified, // True if the certificate passed pre-verification.
* verify_context& ctx // The peer certificate and other context.
* ); @endcode
* The return value of the callback is true if the certificate has passed
* verification, false otherwise.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_set_verify.
*/
template <typename VerifyCallback>
BOOST_ASIO_SYNC_OP_VOID set_verify_callback(VerifyCallback callback,
boost::system::error_code& ec);
/// Load a certification authority file for performing verification.
/**
* This function is used to load one or more trusted certification authorities
* from a file.
*
* @param filename The name of a file containing certification authority
* certificates in PEM format.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_load_verify_locations.
*/
BOOST_ASIO_DECL void load_verify_file(const std::string& filename);
/// Load a certification authority file for performing verification.
/**
* This function is used to load the certificates for one or more trusted
* certification authorities from a file.
*
* @param filename The name of a file containing certification authority
* certificates in PEM format.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_load_verify_locations.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID load_verify_file(
const std::string& filename, boost::system::error_code& ec);
/// Add certification authority for performing verification.
/**
* This function is used to add one trusted certification authority
* from a memory buffer.
*
* @param ca The buffer containing the certification authority certificate.
* The certificate must use the PEM format.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_get_cert_store and @c X509_STORE_add_cert.
*/
BOOST_ASIO_DECL void add_certificate_authority(const const_buffer& ca);
/// Add certification authority for performing verification.
/**
* This function is used to add one trusted certification authority
* from a memory buffer.
*
* @param ca The buffer containing the certification authority certificate.
* The certificate must use the PEM format.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_get_cert_store and @c X509_STORE_add_cert.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID add_certificate_authority(
const const_buffer& ca, boost::system::error_code& ec);
/// Configures the context to use the default directories for finding
/// certification authority certificates.
/**
* This function specifies that the context should use the default,
* system-dependent directories for locating certification authority
* certificates.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_set_default_verify_paths.
*/
BOOST_ASIO_DECL void set_default_verify_paths();
/// Configures the context to use the default directories for finding
/// certification authority certificates.
/**
* This function specifies that the context should use the default,
* system-dependent directories for locating certification authority
* certificates.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_set_default_verify_paths.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID set_default_verify_paths(
boost::system::error_code& ec);
/// Add a directory containing certificate authority files to be used for
/// performing verification.
/**
* This function is used to specify the name of a directory containing
* certification authority certificates. Each file in the directory must
* contain a single certificate. The files must be named using the subject
* name's hash and an extension of ".0".
*
* @param path The name of a directory containing the certificates.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_load_verify_locations.
*/
BOOST_ASIO_DECL void add_verify_path(const std::string& path);
/// Add a directory containing certificate authority files to be used for
/// performing verification.
/**
* This function is used to specify the name of a directory containing
* certification authority certificates. Each file in the directory must
* contain a single certificate. The files must be named using the subject
* name's hash and an extension of ".0".
*
* @param path The name of a directory containing the certificates.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_load_verify_locations.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID add_verify_path(
const std::string& path, boost::system::error_code& ec);
/// Use a certificate from a memory buffer.
/**
* This function is used to load a certificate into the context from a buffer.
*
* @param certificate The buffer containing the certificate.
*
* @param format The certificate format (ASN.1 or PEM).
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_use_certificate or SSL_CTX_use_certificate_ASN1.
*/
BOOST_ASIO_DECL void use_certificate(
const const_buffer& certificate, file_format format);
/// Use a certificate from a memory buffer.
/**
* This function is used to load a certificate into the context from a buffer.
*
* @param certificate The buffer containing the certificate.
*
* @param format The certificate format (ASN.1 or PEM).
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_use_certificate or SSL_CTX_use_certificate_ASN1.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_certificate(
const const_buffer& certificate, file_format format,
boost::system::error_code& ec);
/// Use a certificate from a file.
/**
* This function is used to load a certificate into the context from a file.
*
* @param filename The name of the file containing the certificate.
*
* @param format The file format (ASN.1 or PEM).
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_use_certificate_file.
*/
BOOST_ASIO_DECL void use_certificate_file(
const std::string& filename, file_format format);
/// Use a certificate from a file.
/**
* This function is used to load a certificate into the context from a file.
*
* @param filename The name of the file containing the certificate.
*
* @param format The file format (ASN.1 or PEM).
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_use_certificate_file.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_certificate_file(
const std::string& filename, file_format format,
boost::system::error_code& ec);
/// Use a certificate chain from a memory buffer.
/**
* This function is used to load a certificate chain into the context from a
* buffer.
*
* @param chain The buffer containing the certificate chain. The certificate
* chain must use the PEM format.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_use_certificate and SSL_CTX_add_extra_chain_cert.
*/
BOOST_ASIO_DECL void use_certificate_chain(const const_buffer& chain);
/// Use a certificate chain from a memory buffer.
/**
* This function is used to load a certificate chain into the context from a
* buffer.
*
* @param chain The buffer containing the certificate chain. The certificate
* chain must use the PEM format.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_use_certificate and SSL_CTX_add_extra_chain_cert.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_certificate_chain(
const const_buffer& chain, boost::system::error_code& ec);
/// Use a certificate chain from a file.
/**
* This function is used to load a certificate chain into the context from a
* file.
*
* @param filename The name of the file containing the certificate. The file
* must use the PEM format.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_use_certificate_chain_file.
*/
BOOST_ASIO_DECL void use_certificate_chain_file(const std::string& filename);
/// Use a certificate chain from a file.
/**
* This function is used to load a certificate chain into the context from a
* file.
*
* @param filename The name of the file containing the certificate. The file
* must use the PEM format.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_use_certificate_chain_file.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_certificate_chain_file(
const std::string& filename, boost::system::error_code& ec);
/// Use a private key from a memory buffer.
/**
* This function is used to load a private key into the context from a buffer.
*
* @param private_key The buffer containing the private key.
*
* @param format The private key format (ASN.1 or PEM).
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_use_PrivateKey or SSL_CTX_use_PrivateKey_ASN1.
*/
BOOST_ASIO_DECL void use_private_key(
const const_buffer& private_key, file_format format);
/// Use a private key from a memory buffer.
/**
* This function is used to load a private key into the context from a buffer.
*
* @param private_key The buffer containing the private key.
*
* @param format The private key format (ASN.1 or PEM).
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_use_PrivateKey or SSL_CTX_use_PrivateKey_ASN1.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_private_key(
const const_buffer& private_key, file_format format,
boost::system::error_code& ec);
/// Use a private key from a file.
/**
* This function is used to load a private key into the context from a file.
*
* @param filename The name of the file containing the private key.
*
* @param format The file format (ASN.1 or PEM).
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_use_PrivateKey_file.
*/
BOOST_ASIO_DECL void use_private_key_file(
const std::string& filename, file_format format);
/// Use a private key from a file.
/**
* This function is used to load a private key into the context from a file.
*
* @param filename The name of the file containing the private key.
*
* @param format The file format (ASN.1 or PEM).
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_use_PrivateKey_file.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_private_key_file(
const std::string& filename, file_format format,
boost::system::error_code& ec);
/// Use an RSA private key from a memory buffer.
/**
* This function is used to load an RSA private key into the context from a
* buffer.
*
* @param private_key The buffer containing the RSA private key.
*
* @param format The private key format (ASN.1 or PEM).
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_use_RSAPrivateKey or SSL_CTX_use_RSAPrivateKey_ASN1.
*/
BOOST_ASIO_DECL void use_rsa_private_key(
const const_buffer& private_key, file_format format);
/// Use an RSA private key from a memory buffer.
/**
* This function is used to load an RSA private key into the context from a
* buffer.
*
* @param private_key The buffer containing the RSA private key.
*
* @param format The private key format (ASN.1 or PEM).
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_use_RSAPrivateKey or SSL_CTX_use_RSAPrivateKey_ASN1.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_rsa_private_key(
const const_buffer& private_key, file_format format,
boost::system::error_code& ec);
/// Use an RSA private key from a file.
/**
* This function is used to load an RSA private key into the context from a
* file.
*
* @param filename The name of the file containing the RSA private key.
*
* @param format The file format (ASN.1 or PEM).
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_use_RSAPrivateKey_file.
*/
BOOST_ASIO_DECL void use_rsa_private_key_file(
const std::string& filename, file_format format);
/// Use an RSA private key from a file.
/**
* This function is used to load an RSA private key into the context from a
* file.
*
* @param filename The name of the file containing the RSA private key.
*
* @param format The file format (ASN.1 or PEM).
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_use_RSAPrivateKey_file.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_rsa_private_key_file(
const std::string& filename, file_format format,
boost::system::error_code& ec);
/// Use the specified memory buffer to obtain the temporary Diffie-Hellman
/// parameters.
/**
* This function is used to load Diffie-Hellman parameters into the context
* from a buffer.
*
* @param dh The memory buffer containing the Diffie-Hellman parameters. The
* buffer must use the PEM format.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_set_tmp_dh.
*/
BOOST_ASIO_DECL void use_tmp_dh(const const_buffer& dh);
/// Use the specified memory buffer to obtain the temporary Diffie-Hellman
/// parameters.
/**
* This function is used to load Diffie-Hellman parameters into the context
* from a buffer.
*
* @param dh The memory buffer containing the Diffie-Hellman parameters. The
* buffer must use the PEM format.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_set_tmp_dh.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_tmp_dh(
const const_buffer& dh, boost::system::error_code& ec);
/// Use the specified file to obtain the temporary Diffie-Hellman parameters.
/**
* This function is used to load Diffie-Hellman parameters into the context
* from a file.
*
* @param filename The name of the file containing the Diffie-Hellman
* parameters. The file must use the PEM format.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_set_tmp_dh.
*/
BOOST_ASIO_DECL void use_tmp_dh_file(const std::string& filename);
/// Use the specified file to obtain the temporary Diffie-Hellman parameters.
/**
* This function is used to load Diffie-Hellman parameters into the context
* from a file.
*
* @param filename The name of the file containing the Diffie-Hellman
* parameters. The file must use the PEM format.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_set_tmp_dh.
*/
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID use_tmp_dh_file(
const std::string& filename, boost::system::error_code& ec);
/// Set the password callback.
/**
* This function is used to specify a callback function to obtain password
* information about an encrypted key in PEM format.
*
* @param callback The function object to be used for obtaining the password.
* The function signature of the handler must be:
* @code std::string password_callback(
* std::size_t max_length, // The maximum size for a password.
* password_purpose purpose // Whether password is for reading or writing.
* ); @endcode
* The return value of the callback is a string containing the password.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_CTX_set_default_passwd_cb.
*/
template <typename PasswordCallback>
void set_password_callback(PasswordCallback callback);
/// Set the password callback.
/**
* This function is used to specify a callback function to obtain password
* information about an encrypted key in PEM format.
*
* @param callback The function object to be used for obtaining the password.
* The function signature of the handler must be:
* @code std::string password_callback(
* std::size_t max_length, // The maximum size for a password.
* password_purpose purpose // Whether password is for reading or writing.
* ); @endcode
* The return value of the callback is a string containing the password.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_CTX_set_default_passwd_cb.
*/
template <typename PasswordCallback>
BOOST_ASIO_SYNC_OP_VOID set_password_callback(PasswordCallback callback,
boost::system::error_code& ec);
private:
struct bio_cleanup;
struct x509_cleanup;
struct evp_pkey_cleanup;
struct rsa_cleanup;
struct dh_cleanup;
// Helper function used to set a peer certificate verification callback.
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID do_set_verify_callback(
detail::verify_callback_base* callback, boost::system::error_code& ec);
// Callback used when the SSL implementation wants to verify a certificate.
BOOST_ASIO_DECL static int verify_callback_function(
int preverified, X509_STORE_CTX* ctx);
// Helper function used to set a password callback.
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID do_set_password_callback(
detail::password_callback_base* callback, boost::system::error_code& ec);
// Callback used when the SSL implementation wants a password.
BOOST_ASIO_DECL static int password_callback_function(
char* buf, int size, int purpose, void* data);
// Helper function to set the temporary Diffie-Hellman parameters from a BIO.
BOOST_ASIO_DECL BOOST_ASIO_SYNC_OP_VOID do_use_tmp_dh(
BIO* bio, boost::system::error_code& ec);
// Helper function to make a BIO from a memory buffer.
BOOST_ASIO_DECL BIO* make_buffer_bio(const const_buffer& b);
// Translate an SSL error into an error code.
BOOST_ASIO_DECL static boost::system::error_code translate_error(long error);
// The underlying native implementation.
native_handle_type handle_;
// Ensure openssl is initialised.
boost::asio::ssl::detail::openssl_init<> init_;
};
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/ssl/impl/context.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/ssl/impl/context.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // BOOST_ASIO_SSL_CONTEXT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/host_name_verification.hpp | //
// ssl/host_name_verification.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_HOST_NAME_VERIFICATION_HPP
#define BOOST_ASIO_SSL_HOST_NAME_VERIFICATION_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <string>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/ssl/verify_context.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
/// Verifies a certificate against a host_name according to the rules described
/// in RFC 6125.
/**
* @par Example
* The following example shows how to synchronously open a secure connection to
* a given host name:
* @code
* using boost::asio::ip::tcp;
* namespace ssl = boost::asio::ssl;
* typedef ssl::stream<tcp::socket> ssl_socket;
*
* // Create a context that uses the default paths for finding CA certificates.
* ssl::context ctx(ssl::context::sslv23);
* ctx.set_default_verify_paths();
*
* // Open a socket and connect it to the remote host.
* boost::asio::io_context io_context;
* ssl_socket sock(io_context, ctx);
* tcp::resolver resolver(io_context);
* tcp::resolver::query query("host.name", "https");
* boost::asio::connect(sock.lowest_layer(), resolver.resolve(query));
* sock.lowest_layer().set_option(tcp::no_delay(true));
*
* // Perform SSL handshake and verify the remote host's certificate.
* sock.set_verify_mode(ssl::verify_peer);
* sock.set_verify_callback(ssl::host_name_verification("host.name"));
* sock.handshake(ssl_socket::client);
*
* // ... read and write as normal ...
* @endcode
*/
class host_name_verification
{
public:
/// The type of the function object's result.
typedef bool result_type;
/// Constructor.
explicit host_name_verification(const std::string& host)
: host_(host)
{
}
/// Perform certificate verification.
BOOST_ASIO_DECL bool operator()(bool preverified, verify_context& ctx) const;
private:
// Helper function to check a host name against an IPv4 address
// The host name to be checked.
std::string host_;
};
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/ssl/impl/host_name_verification.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // BOOST_ASIO_SSL_HOST_NAME_VERIFICATION_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/verify_mode.hpp | //
// ssl/verify_mode.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_VERIFY_MODE_HPP
#define BOOST_ASIO_SSL_VERIFY_MODE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
/// Bitmask type for peer verification.
/**
* Possible values are:
*
* @li @ref verify_none
* @li @ref verify_peer
* @li @ref verify_fail_if_no_peer_cert
* @li @ref verify_client_once
*/
typedef int verify_mode;
#if defined(GENERATING_DOCUMENTATION)
/// No verification.
const int verify_none = implementation_defined;
/// Verify the peer.
const int verify_peer = implementation_defined;
/// Fail verification if the peer has no certificate. Ignored unless
/// @ref verify_peer is set.
const int verify_fail_if_no_peer_cert = implementation_defined;
/// Do not request client certificate on renegotiation. Ignored unless
/// @ref verify_peer is set.
const int verify_client_once = implementation_defined;
#else
const int verify_none = SSL_VERIFY_NONE;
const int verify_peer = SSL_VERIFY_PEER;
const int verify_fail_if_no_peer_cert = SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
const int verify_client_once = SSL_VERIFY_CLIENT_ONCE;
#endif
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_VERIFY_MODE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/stream_base.hpp | //
// ssl/stream_base.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_STREAM_BASE_HPP
#define BOOST_ASIO_SSL_STREAM_BASE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
/// The stream_base class is used as a base for the boost::asio::ssl::stream
/// class template so that we have a common place to define various enums.
class stream_base
{
public:
/// Different handshake types.
enum handshake_type
{
/// Perform handshaking as a client.
client,
/// Perform handshaking as a server.
server
};
protected:
/// Protected destructor to prevent deletion through this type.
~stream_base()
{
}
};
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_STREAM_BASE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/stream.hpp | //
// ssl/stream.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_STREAM_HPP
#define BOOST_ASIO_SSL_STREAM_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/detail/buffer_sequence_adapter.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/noncopyable.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/asio/ssl/detail/buffered_handshake_op.hpp>
#include <boost/asio/ssl/detail/handshake_op.hpp>
#include <boost/asio/ssl/detail/io.hpp>
#include <boost/asio/ssl/detail/read_op.hpp>
#include <boost/asio/ssl/detail/shutdown_op.hpp>
#include <boost/asio/ssl/detail/stream_core.hpp>
#include <boost/asio/ssl/detail/write_op.hpp>
#include <boost/asio/ssl/stream_base.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
/// Provides stream-oriented functionality using SSL.
/**
* The stream class template provides asynchronous and blocking stream-oriented
* functionality using SSL.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe. The application must also ensure that all
* asynchronous operations are performed within the same implicit or explicit
* strand.
*
* @par Example
* To use the SSL stream template with an ip::tcp::socket, you would write:
* @code
* boost::asio::io_context my_context;
* boost::asio::ssl::context ctx(boost::asio::ssl::context::sslv23);
* boost::asio::ssl::stream<boost::asio::ip::tcp::socket> sock(my_context, ctx);
* @endcode
*
* @par Concepts:
* AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.
*/
template <typename Stream>
class stream :
public stream_base,
private noncopyable
{
private:
class initiate_async_handshake;
class initiate_async_buffered_handshake;
class initiate_async_shutdown;
class initiate_async_write_some;
class initiate_async_read_some;
public:
/// The native handle type of the SSL stream.
typedef SSL* native_handle_type;
/// Structure for use with deprecated impl_type.
struct impl_struct
{
SSL* ssl;
};
/// The type of the next layer.
typedef remove_reference_t<Stream> next_layer_type;
/// The type of the lowest layer.
typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
/// The type of the executor associated with the object.
typedef typename lowest_layer_type::executor_type executor_type;
/// Construct a stream.
/**
* This constructor creates a stream and initialises the underlying stream
* object.
*
* @param arg The argument to be passed to initialise the underlying stream.
*
* @param ctx The SSL context to be used for the stream.
*/
template <typename Arg>
stream(Arg&& arg, context& ctx)
: next_layer_(static_cast<Arg&&>(arg)),
core_(ctx.native_handle(), next_layer_.lowest_layer().get_executor())
{
}
/// Construct a stream from an existing native implementation.
/**
* This constructor creates a stream and initialises the underlying stream
* object. On success, ownership of the native implementation is transferred
* to the stream, and it will be cleaned up when the stream is destroyed.
*
* @param arg The argument to be passed to initialise the underlying stream.
*
* @param handle An existing native SSL implementation.
*/
template <typename Arg>
stream(Arg&& arg, native_handle_type handle)
: next_layer_(static_cast<Arg&&>(arg)),
core_(handle, next_layer_.lowest_layer().get_executor())
{
}
/// Move-construct a stream from another.
/**
* @param other The other stream object from which the move will occur. Must
* have no outstanding asynchronous operations associated with it. Following
* the move, @c other has a valid but unspecified state where the only safe
* operation is destruction, or use as the target of a move assignment.
*/
stream(stream&& other)
: next_layer_(static_cast<Stream&&>(other.next_layer_)),
core_(static_cast<detail::stream_core&&>(other.core_))
{
}
/// Move-assign a stream from another.
/**
* @param other The other stream object from which the move will occur. Must
* have no outstanding asynchronous operations associated with it. Following
* the move, @c other has a valid but unspecified state where the only safe
* operation is destruction, or use as the target of a move assignment.
*/
stream& operator=(stream&& other)
{
if (this != &other)
{
next_layer_ = static_cast<Stream&&>(other.next_layer_);
core_ = static_cast<detail::stream_core&&>(other.core_);
}
return *this;
}
/// Destructor.
/**
* @note A @c stream object must not be destroyed while there are pending
* asynchronous operations associated with it.
*/
~stream()
{
}
/// Get the executor associated with the object.
/**
* This function may be used to obtain the executor object that the stream
* uses to dispatch handlers for asynchronous operations.
*
* @return A copy of the executor that stream will use to dispatch handlers.
*/
executor_type get_executor() noexcept
{
return next_layer_.lowest_layer().get_executor();
}
/// Get the underlying implementation in the native type.
/**
* This function may be used to obtain the underlying implementation of the
* context. This is intended to allow access to context functionality that is
* not otherwise provided.
*
* @par Example
* The native_handle() function returns a pointer of type @c SSL* that is
* suitable for passing to functions such as @c SSL_get_verify_result and
* @c SSL_get_peer_certificate:
* @code
* boost::asio::ssl::stream<asio:ip::tcp::socket> sock(my_context, ctx);
*
* // ... establish connection and perform handshake ...
*
* if (X509* cert = SSL_get_peer_certificate(sock.native_handle()))
* {
* if (SSL_get_verify_result(sock.native_handle()) == X509_V_OK)
* {
* // ...
* }
* }
* @endcode
*/
native_handle_type native_handle()
{
return core_.engine_.native_handle();
}
/// Get a reference to the next layer.
/**
* This function returns a reference to the next layer in a stack of stream
* layers.
*
* @return A reference to the next layer in the stack of stream layers.
* Ownership is not transferred to the caller.
*/
const next_layer_type& next_layer() const
{
return next_layer_;
}
/// Get a reference to the next layer.
/**
* This function returns a reference to the next layer in a stack of stream
* layers.
*
* @return A reference to the next layer in the stack of stream layers.
* Ownership is not transferred to the caller.
*/
next_layer_type& next_layer()
{
return next_layer_;
}
/// Get a reference to the lowest layer.
/**
* This function returns a reference to the lowest layer in a stack of
* stream layers.
*
* @return A reference to the lowest layer in the stack of stream layers.
* Ownership is not transferred to the caller.
*/
lowest_layer_type& lowest_layer()
{
return next_layer_.lowest_layer();
}
/// Get a reference to the lowest layer.
/**
* This function returns a reference to the lowest layer in a stack of
* stream layers.
*
* @return A reference to the lowest layer in the stack of stream layers.
* Ownership is not transferred to the caller.
*/
const lowest_layer_type& lowest_layer() const
{
return next_layer_.lowest_layer();
}
/// Set the peer verification mode.
/**
* This function may be used to configure the peer verification mode used by
* the stream. The new mode will override the mode inherited from the context.
*
* @param v A bitmask of peer verification modes. See @ref verify_mode for
* available values.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_set_verify.
*/
void set_verify_mode(verify_mode v)
{
boost::system::error_code ec;
set_verify_mode(v, ec);
boost::asio::detail::throw_error(ec, "set_verify_mode");
}
/// Set the peer verification mode.
/**
* This function may be used to configure the peer verification mode used by
* the stream. The new mode will override the mode inherited from the context.
*
* @param v A bitmask of peer verification modes. See @ref verify_mode for
* available values.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_set_verify.
*/
BOOST_ASIO_SYNC_OP_VOID set_verify_mode(
verify_mode v, boost::system::error_code& ec)
{
core_.engine_.set_verify_mode(v, ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Set the peer verification depth.
/**
* This function may be used to configure the maximum verification depth
* allowed by the stream.
*
* @param depth Maximum depth for the certificate chain verification that
* shall be allowed.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_set_verify_depth.
*/
void set_verify_depth(int depth)
{
boost::system::error_code ec;
set_verify_depth(depth, ec);
boost::asio::detail::throw_error(ec, "set_verify_depth");
}
/// Set the peer verification depth.
/**
* This function may be used to configure the maximum verification depth
* allowed by the stream.
*
* @param depth Maximum depth for the certificate chain verification that
* shall be allowed.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_set_verify_depth.
*/
BOOST_ASIO_SYNC_OP_VOID set_verify_depth(
int depth, boost::system::error_code& ec)
{
core_.engine_.set_verify_depth(depth, ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Set the callback used to verify peer certificates.
/**
* This function is used to specify a callback function that will be called
* by the implementation when it needs to verify a peer certificate.
*
* @param callback The function object to be used for verifying a certificate.
* The function signature of the handler must be:
* @code bool verify_callback(
* bool preverified, // True if the certificate passed pre-verification.
* verify_context& ctx // The peer certificate and other context.
* ); @endcode
* The return value of the callback is true if the certificate has passed
* verification, false otherwise.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note Calls @c SSL_set_verify.
*/
template <typename VerifyCallback>
void set_verify_callback(VerifyCallback callback)
{
boost::system::error_code ec;
this->set_verify_callback(callback, ec);
boost::asio::detail::throw_error(ec, "set_verify_callback");
}
/// Set the callback used to verify peer certificates.
/**
* This function is used to specify a callback function that will be called
* by the implementation when it needs to verify a peer certificate.
*
* @param callback The function object to be used for verifying a certificate.
* The function signature of the handler must be:
* @code bool verify_callback(
* bool preverified, // True if the certificate passed pre-verification.
* verify_context& ctx // The peer certificate and other context.
* ); @endcode
* The return value of the callback is true if the certificate has passed
* verification, false otherwise.
*
* @param ec Set to indicate what error occurred, if any.
*
* @note Calls @c SSL_set_verify.
*/
template <typename VerifyCallback>
BOOST_ASIO_SYNC_OP_VOID set_verify_callback(VerifyCallback callback,
boost::system::error_code& ec)
{
core_.engine_.set_verify_callback(
new detail::verify_callback<VerifyCallback>(callback), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Perform SSL handshaking.
/**
* This function is used to perform SSL handshaking on the stream. The
* function call will block until handshaking is complete or an error occurs.
*
* @param type The type of handshaking to be performed, i.e. as a client or as
* a server.
*
* @throws boost::system::system_error Thrown on failure.
*/
void handshake(handshake_type type)
{
boost::system::error_code ec;
handshake(type, ec);
boost::asio::detail::throw_error(ec, "handshake");
}
/// Perform SSL handshaking.
/**
* This function is used to perform SSL handshaking on the stream. The
* function call will block until handshaking is complete or an error occurs.
*
* @param type The type of handshaking to be performed, i.e. as a client or as
* a server.
*
* @param ec Set to indicate what error occurred, if any.
*/
BOOST_ASIO_SYNC_OP_VOID handshake(handshake_type type,
boost::system::error_code& ec)
{
detail::io(next_layer_, core_, detail::handshake_op(type), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Perform SSL handshaking.
/**
* This function is used to perform SSL handshaking on the stream. The
* function call will block until handshaking is complete or an error occurs.
*
* @param type The type of handshaking to be performed, i.e. as a client or as
* a server.
*
* @param buffers The buffered data to be reused for the handshake.
*
* @throws boost::system::system_error Thrown on failure.
*/
template <typename ConstBufferSequence>
void handshake(handshake_type type, const ConstBufferSequence& buffers)
{
boost::system::error_code ec;
handshake(type, buffers, ec);
boost::asio::detail::throw_error(ec, "handshake");
}
/// Perform SSL handshaking.
/**
* This function is used to perform SSL handshaking on the stream. The
* function call will block until handshaking is complete or an error occurs.
*
* @param type The type of handshaking to be performed, i.e. as a client or as
* a server.
*
* @param buffers The buffered data to be reused for the handshake.
*
* @param ec Set to indicate what error occurred, if any.
*/
template <typename ConstBufferSequence>
BOOST_ASIO_SYNC_OP_VOID handshake(handshake_type type,
const ConstBufferSequence& buffers, boost::system::error_code& ec)
{
detail::io(next_layer_, core_,
detail::buffered_handshake_op<ConstBufferSequence>(type, buffers), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Start an asynchronous SSL handshake.
/**
* This function is used to asynchronously perform an SSL handshake on the
* stream. It is an initiating function for an @ref asynchronous_operation,
* and always returns immediately.
*
* @param type The type of handshaking to be performed, i.e. as a client or as
* a server.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the handshake completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error // Result of operation.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code) @endcode
*
* @par Per-Operation Cancellation
* This asynchronous operation supports cancellation for the following
* boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* if they are also supported by the @c Stream type's @c async_read_some and
* @c async_write_some operations.
*/
template <
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code))
HandshakeToken = default_completion_token_t<executor_type>>
auto async_handshake(handshake_type type,
HandshakeToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<HandshakeToken,
void (boost::system::error_code)>(
declval<initiate_async_handshake>(), token, type))
{
return async_initiate<HandshakeToken,
void (boost::system::error_code)>(
initiate_async_handshake(this), token, type);
}
/// Start an asynchronous SSL handshake.
/**
* This function is used to asynchronously perform an SSL handshake on the
* stream. It is an initiating function for an @ref asynchronous_operation,
* and always returns immediately.
*
* @param type The type of handshaking to be performed, i.e. as a client or as
* a server.
*
* @param buffers The buffered data to be reused for the handshake. Although
* the buffers object may be copied as necessary, ownership of the underlying
* buffers is retained by the caller, which must guarantee that they remain
* valid until the completion handler is called.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the handshake completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Amount of buffers used in handshake.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @par Per-Operation Cancellation
* This asynchronous operation supports cancellation for the following
* boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* if they are also supported by the @c Stream type's @c async_read_some and
* @c async_write_some operations.
*/
template <typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) BufferedHandshakeToken
= default_completion_token_t<executor_type>>
auto async_handshake(handshake_type type, const ConstBufferSequence& buffers,
BufferedHandshakeToken&& token
= default_completion_token_t<executor_type>(),
constraint_t<
is_const_buffer_sequence<ConstBufferSequence>::value
> = 0)
-> decltype(
async_initiate<BufferedHandshakeToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_buffered_handshake>(), token, type, buffers))
{
return async_initiate<BufferedHandshakeToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_buffered_handshake(this), token, type, buffers);
}
/// Shut down SSL on the stream.
/**
* This function is used to shut down SSL on the stream. The function call
* will block until SSL has been shut down or an error occurs.
*
* @throws boost::system::system_error Thrown on failure.
*/
void shutdown()
{
boost::system::error_code ec;
shutdown(ec);
boost::asio::detail::throw_error(ec, "shutdown");
}
/// Shut down SSL on the stream.
/**
* This function is used to shut down SSL on the stream. The function call
* will block until SSL has been shut down or an error occurs.
*
* @param ec Set to indicate what error occurred, if any.
*/
BOOST_ASIO_SYNC_OP_VOID shutdown(boost::system::error_code& ec)
{
detail::io(next_layer_, core_, detail::shutdown_op(), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
/// Asynchronously shut down SSL on the stream.
/**
* This function is used to asynchronously shut down SSL on the stream. It is
* an initiating function for an @ref asynchronous_operation, and always
* returns immediately.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the shutdown completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error // Result of operation.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code) @endcode
*
* @par Per-Operation Cancellation
* This asynchronous operation supports cancellation for the following
* boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* if they are also supported by the @c Stream type's @c async_read_some and
* @c async_write_some operations.
*/
template <
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code))
ShutdownToken
= default_completion_token_t<executor_type>>
auto async_shutdown(
ShutdownToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<ShutdownToken,
void (boost::system::error_code)>(
declval<initiate_async_shutdown>(), token))
{
return async_initiate<ShutdownToken,
void (boost::system::error_code)>(
initiate_async_shutdown(this), token);
}
/// Write some data to the stream.
/**
* This function is used to write data on the stream. The function call will
* block until one or more bytes of data has been written successfully, or
* until an error occurs.
*
* @param buffers The data to be written.
*
* @returns The number of bytes written.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note The write_some operation may not transmit all of the data to the
* peer. Consider using the @ref write function if you need to ensure that all
* data is written before the blocking operation completes.
*/
template <typename ConstBufferSequence>
std::size_t write_some(const ConstBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t n = write_some(buffers, ec);
boost::asio::detail::throw_error(ec, "write_some");
return n;
}
/// Write some data to the stream.
/**
* This function is used to write data on the stream. The function call will
* block until one or more bytes of data has been written successfully, or
* until an error occurs.
*
* @param buffers The data to be written to the stream.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns The number of bytes written. Returns 0 if an error occurred.
*
* @note The write_some operation may not transmit all of the data to the
* peer. Consider using the @ref write function if you need to ensure that all
* data is written before the blocking operation completes.
*/
template <typename ConstBufferSequence>
std::size_t write_some(const ConstBufferSequence& buffers,
boost::system::error_code& ec)
{
return detail::io(next_layer_, core_,
detail::write_op<ConstBufferSequence>(buffers), ec);
}
/// Start an asynchronous write.
/**
* This function is used to asynchronously write one or more bytes of data to
* the stream. It is an initiating function for an @ref
* asynchronous_operation, and always returns immediately.
*
* @param buffers The data to be written to the stream. Although the buffers
* object may be copied as necessary, ownership of the underlying buffers is
* retained by the caller, which must guarantee that they remain valid until
* the completion handler is called.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the write completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes written.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @note The async_write_some operation may not transmit all of the data to
* the peer. Consider using the @ref async_write function if you need to
* ensure that all data is written before the asynchronous operation
* completes.
*
* @par Per-Operation Cancellation
* This asynchronous operation supports cancellation for the following
* boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* if they are also supported by the @c Stream type's @c async_read_some and
* @c async_write_some operations.
*/
template <typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken = default_completion_token_t<executor_type>>
auto async_write_some(const ConstBufferSequence& buffers,
WriteToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_write_some>(), token, buffers))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_write_some(this), token, buffers);
}
/// Read some data from the stream.
/**
* This function is used to read data from the stream. The function call will
* block until one or more bytes of data has been read successfully, or until
* an error occurs.
*
* @param buffers The buffers into which the data will be read.
*
* @returns The number of bytes read.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note The read_some operation may not read all of the requested number of
* bytes. Consider using the @ref read function if you need to ensure that the
* requested amount of data is read before the blocking operation completes.
*/
template <typename MutableBufferSequence>
std::size_t read_some(const MutableBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t n = read_some(buffers, ec);
boost::asio::detail::throw_error(ec, "read_some");
return n;
}
/// Read some data from the stream.
/**
* This function is used to read data from the stream. The function call will
* block until one or more bytes of data has been read successfully, or until
* an error occurs.
*
* @param buffers The buffers into which the data will be read.
*
* @param ec Set to indicate what error occurred, if any.
*
* @returns The number of bytes read. Returns 0 if an error occurred.
*
* @note The read_some operation may not read all of the requested number of
* bytes. Consider using the @ref read function if you need to ensure that the
* requested amount of data is read before the blocking operation completes.
*/
template <typename MutableBufferSequence>
std::size_t read_some(const MutableBufferSequence& buffers,
boost::system::error_code& ec)
{
return detail::io(next_layer_, core_,
detail::read_op<MutableBufferSequence>(buffers), ec);
}
/// Start an asynchronous read.
/**
* This function is used to asynchronously read one or more bytes of data from
* the stream. It is an initiating function for an @ref
* asynchronous_operation, and always returns immediately.
*
* @param buffers The buffers into which the data will be read. Although the
* buffers object may be copied as necessary, ownership of the underlying
* buffers is retained by the caller, which must guarantee that they remain
* valid until the completion handler is called.
*
* @param token The @ref completion_token that will be used to produce a
* completion handler, which will be called when the read completes.
* Potential completion tokens include @ref use_future, @ref use_awaitable,
* @ref yield_context, or a function object with the correct completion
* signature. The function signature of the completion handler must be:
* @code void handler(
* const boost::system::error_code& error, // Result of operation.
* std::size_t bytes_transferred // Number of bytes read.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
* not, the completion 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 boost::asio::post().
*
* @par Completion Signature
* @code void(boost::system::error_code, std::size_t) @endcode
*
* @note The async_read_some operation may not read all of the requested
* number of bytes. Consider using the @ref async_read function if you need to
* ensure that the requested amount of data is read before the asynchronous
* operation completes.
*
* @par Per-Operation Cancellation
* This asynchronous operation supports cancellation for the following
* boost::asio::cancellation_type values:
*
* @li @c cancellation_type::terminal
*
* @li @c cancellation_type::partial
*
* if they are also supported by the @c Stream type's @c async_read_some and
* @c async_write_some operations.
*/
template <typename MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken = default_completion_token_t<executor_type>>
auto async_read_some(const MutableBufferSequence& buffers,
ReadToken&& token = default_completion_token_t<executor_type>())
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<initiate_async_read_some>(), token, buffers))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
initiate_async_read_some(this), token, buffers);
}
private:
class initiate_async_handshake
{
public:
typedef typename stream::executor_type executor_type;
explicit initiate_async_handshake(stream* self)
: self_(self)
{
}
executor_type get_executor() const noexcept
{
return self_->get_executor();
}
template <typename HandshakeHandler>
void operator()(HandshakeHandler&& handler,
handshake_type type) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a HandshakeHandler.
BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(HandshakeHandler, handler) type_check;
boost::asio::detail::non_const_lvalue<HandshakeHandler> handler2(handler);
detail::async_io(self_->next_layer_, self_->core_,
detail::handshake_op(type), handler2.value);
}
private:
stream* self_;
};
class initiate_async_buffered_handshake
{
public:
typedef typename stream::executor_type executor_type;
explicit initiate_async_buffered_handshake(stream* self)
: self_(self)
{
}
executor_type get_executor() const noexcept
{
return self_->get_executor();
}
template <typename BufferedHandshakeHandler, typename ConstBufferSequence>
void operator()(BufferedHandshakeHandler&& handler,
handshake_type type, const ConstBufferSequence& buffers) const
{
// If you get an error on the following line it means that your
// handler does not meet the documented type requirements for a
// BufferedHandshakeHandler.
BOOST_ASIO_BUFFERED_HANDSHAKE_HANDLER_CHECK(
BufferedHandshakeHandler, handler) type_check;
boost::asio::detail::non_const_lvalue<
BufferedHandshakeHandler> handler2(handler);
detail::async_io(self_->next_layer_, self_->core_,
detail::buffered_handshake_op<ConstBufferSequence>(type, buffers),
handler2.value);
}
private:
stream* self_;
};
class initiate_async_shutdown
{
public:
typedef typename stream::executor_type executor_type;
explicit initiate_async_shutdown(stream* self)
: self_(self)
{
}
executor_type get_executor() const noexcept
{
return self_->get_executor();
}
template <typename ShutdownHandler>
void operator()(ShutdownHandler&& handler) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ShutdownHandler.
BOOST_ASIO_HANDSHAKE_HANDLER_CHECK(ShutdownHandler, handler) type_check;
boost::asio::detail::non_const_lvalue<ShutdownHandler> handler2(handler);
detail::async_io(self_->next_layer_, self_->core_,
detail::shutdown_op(), handler2.value);
}
private:
stream* self_;
};
class initiate_async_write_some
{
public:
typedef typename stream::executor_type executor_type;
explicit initiate_async_write_some(stream* self)
: self_(self)
{
}
executor_type get_executor() const noexcept
{
return self_->get_executor();
}
template <typename WriteHandler, typename ConstBufferSequence>
void operator()(WriteHandler&& handler,
const ConstBufferSequence& buffers) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
boost::asio::detail::non_const_lvalue<WriteHandler> handler2(handler);
detail::async_io(self_->next_layer_, self_->core_,
detail::write_op<ConstBufferSequence>(buffers), handler2.value);
}
private:
stream* self_;
};
class initiate_async_read_some
{
public:
typedef typename stream::executor_type executor_type;
explicit initiate_async_read_some(stream* self)
: self_(self)
{
}
executor_type get_executor() const noexcept
{
return self_->get_executor();
}
template <typename ReadHandler, typename MutableBufferSequence>
void operator()(ReadHandler&& handler,
const MutableBufferSequence& buffers) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
boost::asio::detail::non_const_lvalue<ReadHandler> handler2(handler);
detail::async_io(self_->next_layer_, self_->core_,
detail::read_op<MutableBufferSequence>(buffers), handler2.value);
}
private:
stream* self_;
};
Stream next_layer_;
detail::stream_core core_;
};
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_STREAM_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/verify_context.hpp | //
// ssl/verify_context.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_VERIFY_CONTEXT_HPP
#define BOOST_ASIO_SSL_VERIFY_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/noncopyable.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
/// A simple wrapper around the X509_STORE_CTX type, used during verification of
/// a peer certificate.
/**
* @note The verify_context does not own the underlying X509_STORE_CTX object.
*/
class verify_context
: private noncopyable
{
public:
/// The native handle type of the verification context.
typedef X509_STORE_CTX* native_handle_type;
/// Constructor.
explicit verify_context(native_handle_type handle)
: handle_(handle)
{
}
/// Get the underlying implementation in the native type.
/**
* This function may be used to obtain the underlying implementation of the
* context. This is intended to allow access to context functionality that is
* not otherwise provided.
*/
native_handle_type native_handle()
{
return handle_;
}
private:
// The underlying native implementation.
native_handle_type handle_;
};
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_VERIFY_CONTEXT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/impl/context.hpp | //
// ssl/impl/context.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
// Copyright (c) 2005-2024 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)
//
#ifndef BOOST_ASIO_SSL_IMPL_CONTEXT_HPP
#define BOOST_ASIO_SSL_IMPL_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
template <typename VerifyCallback>
void context::set_verify_callback(VerifyCallback callback)
{
boost::system::error_code ec;
this->set_verify_callback(callback, ec);
boost::asio::detail::throw_error(ec, "set_verify_callback");
}
template <typename VerifyCallback>
BOOST_ASIO_SYNC_OP_VOID context::set_verify_callback(
VerifyCallback callback, boost::system::error_code& ec)
{
do_set_verify_callback(
new detail::verify_callback<VerifyCallback>(callback), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
template <typename PasswordCallback>
void context::set_password_callback(PasswordCallback callback)
{
boost::system::error_code ec;
this->set_password_callback(callback, ec);
boost::asio::detail::throw_error(ec, "set_password_callback");
}
template <typename PasswordCallback>
BOOST_ASIO_SYNC_OP_VOID context::set_password_callback(
PasswordCallback callback, boost::system::error_code& ec)
{
do_set_password_callback(
new detail::password_callback<PasswordCallback>(callback), ec);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_IMPL_CONTEXT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/impl/src.hpp | //
// impl/ssl/src.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_IMPL_SRC_HPP
#define BOOST_ASIO_SSL_IMPL_SRC_HPP
#define BOOST_ASIO_SOURCE
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# error Do not compile Asio library source with BOOST_ASIO_HEADER_ONLY defined
#endif
#include <boost/asio/ssl/impl/context.ipp>
#include <boost/asio/ssl/impl/error.ipp>
#include <boost/asio/ssl/detail/impl/engine.ipp>
#include <boost/asio/ssl/detail/impl/openssl_init.ipp>
#include <boost/asio/ssl/impl/host_name_verification.ipp>
#include <boost/asio/ssl/impl/rfc2818_verification.ipp>
#endif // BOOST_ASIO_SSL_IMPL_SRC_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/read_op.hpp | //
// ssl/detail/read_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_READ_OP_HPP
#define BOOST_ASIO_SSL_DETAIL_READ_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/buffer_sequence_adapter.hpp>
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace detail {
template <typename MutableBufferSequence>
class read_op
{
public:
static constexpr const char* tracking_name()
{
return "ssl::stream<>::async_read_some";
}
read_op(const MutableBufferSequence& buffers)
: buffers_(buffers)
{
}
engine::want operator()(engine& eng,
boost::system::error_code& ec,
std::size_t& bytes_transferred) const
{
boost::asio::mutable_buffer buffer =
boost::asio::detail::buffer_sequence_adapter<boost::asio::mutable_buffer,
MutableBufferSequence>::first(buffers_);
return eng.read(buffer, ec, bytes_transferred);
}
template <typename Handler>
void call_handler(Handler& handler,
const boost::system::error_code& ec,
const std::size_t& bytes_transferred) const
{
static_cast<Handler&&>(handler)(ec, bytes_transferred);
}
private:
MutableBufferSequence buffers_;
};
} // namespace detail
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_DETAIL_READ_OP_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/verify_callback.hpp | //
// ssl/detail/verify_callback.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_VERIFY_CALLBACK_HPP
#define BOOST_ASIO_SSL_DETAIL_VERIFY_CALLBACK_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/ssl/verify_context.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace detail {
class verify_callback_base
{
public:
virtual ~verify_callback_base()
{
}
virtual bool call(bool preverified, verify_context& ctx) = 0;
};
template <typename VerifyCallback>
class verify_callback : public verify_callback_base
{
public:
explicit verify_callback(VerifyCallback callback)
: callback_(callback)
{
}
virtual bool call(bool preverified, verify_context& ctx)
{
return callback_(preverified, ctx);
}
private:
VerifyCallback callback_;
};
} // namespace detail
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_DETAIL_VERIFY_CALLBACK_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/shutdown_op.hpp | //
// ssl/detail/shutdown_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_SHUTDOWN_OP_HPP
#define BOOST_ASIO_SSL_DETAIL_SHUTDOWN_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace detail {
class shutdown_op
{
public:
static constexpr const char* tracking_name()
{
return "ssl::stream<>::async_shutdown";
}
engine::want operator()(engine& eng,
boost::system::error_code& ec,
std::size_t& bytes_transferred) const
{
bytes_transferred = 0;
return eng.shutdown(ec);
}
template <typename Handler>
void call_handler(Handler& handler,
const boost::system::error_code& ec,
const std::size_t&) const
{
if (ec == boost::asio::error::eof)
{
// The engine only generates an eof when the shutdown notification has
// been received from the peer. This indicates that the shutdown has
// completed successfully, and thus need not be passed on to the handler.
static_cast<Handler&&>(handler)(boost::system::error_code());
}
else
{
static_cast<Handler&&>(handler)(ec);
}
}
};
} // namespace detail
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_DETAIL_SHUTDOWN_OP_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/openssl_init.hpp | //
// ssl/detail/openssl_init.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_OPENSSL_INIT_HPP
#define BOOST_ASIO_SSL_DETAIL_OPENSSL_INIT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstring>
#include <boost/asio/detail/memory.hpp>
#include <boost/asio/detail/noncopyable.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace detail {
class openssl_init_base
: private noncopyable
{
protected:
// Class that performs the actual initialisation.
class do_init;
// Helper function to manage a do_init singleton. The static instance of the
// openssl_init object ensures that this function is always called before
// main, and therefore before any other threads can get started. The do_init
// instance must be static in this function to ensure that it gets
// initialised before any other global objects try to use it.
BOOST_ASIO_DECL static boost::asio::detail::shared_ptr<do_init> instance();
#if !defined(SSL_OP_NO_COMPRESSION) \
&& (OPENSSL_VERSION_NUMBER >= 0x00908000L)
// Get an empty stack of compression methods, to be used when disabling
// compression.
BOOST_ASIO_DECL static STACK_OF(SSL_COMP)* get_null_compression_methods();
#endif // !defined(SSL_OP_NO_COMPRESSION)
// && (OPENSSL_VERSION_NUMBER >= 0x00908000L)
};
template <bool Do_Init = true>
class openssl_init : private openssl_init_base
{
public:
// Constructor.
openssl_init()
: ref_(instance())
{
using namespace std; // For memmove.
// Ensure openssl_init::instance_ is linked in.
openssl_init* tmp = &instance_;
memmove(&tmp, &tmp, sizeof(openssl_init*));
}
// Destructor.
~openssl_init()
{
}
#if !defined(SSL_OP_NO_COMPRESSION) \
&& (OPENSSL_VERSION_NUMBER >= 0x00908000L)
using openssl_init_base::get_null_compression_methods;
#endif // !defined(SSL_OP_NO_COMPRESSION)
// && (OPENSSL_VERSION_NUMBER >= 0x00908000L)
private:
// Instance to force initialisation of openssl at global scope.
static openssl_init instance_;
// Reference to singleton do_init object to ensure that openssl does not get
// cleaned up until the last user has finished with it.
boost::asio::detail::shared_ptr<do_init> ref_;
};
template <bool Do_Init>
openssl_init<Do_Init> openssl_init<Do_Init>::instance_;
} // namespace detail
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/ssl/detail/impl/openssl_init.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // BOOST_ASIO_SSL_DETAIL_OPENSSL_INIT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/write_op.hpp | //
// ssl/detail/write_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_WRITE_OP_HPP
#define BOOST_ASIO_SSL_DETAIL_WRITE_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/buffer_sequence_adapter.hpp>
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace detail {
template <typename ConstBufferSequence>
class write_op
{
public:
static constexpr const char* tracking_name()
{
return "ssl::stream<>::async_write_some";
}
write_op(const ConstBufferSequence& buffers)
: buffers_(buffers)
{
}
engine::want operator()(engine& eng,
boost::system::error_code& ec,
std::size_t& bytes_transferred) const
{
unsigned char storage[
boost::asio::detail::buffer_sequence_adapter<boost::asio::const_buffer,
ConstBufferSequence>::linearisation_storage_size];
boost::asio::const_buffer buffer =
boost::asio::detail::buffer_sequence_adapter<boost::asio::const_buffer,
ConstBufferSequence>::linearise(buffers_, boost::asio::buffer(storage));
return eng.write(buffer, ec, bytes_transferred);
}
template <typename Handler>
void call_handler(Handler& handler,
const boost::system::error_code& ec,
const std::size_t& bytes_transferred) const
{
static_cast<Handler&&>(handler)(ec, bytes_transferred);
}
private:
ConstBufferSequence buffers_;
};
} // namespace detail
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_DETAIL_WRITE_OP_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/buffered_handshake_op.hpp | //
// ssl/detail/buffered_handshake_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_BUFFERED_HANDSHAKE_OP_HPP
#define BOOST_ASIO_SSL_DETAIL_BUFFERED_HANDSHAKE_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace detail {
template <typename ConstBufferSequence>
class buffered_handshake_op
{
public:
static constexpr const char* tracking_name()
{
return "ssl::stream<>::async_buffered_handshake";
}
buffered_handshake_op(stream_base::handshake_type type,
const ConstBufferSequence& buffers)
: type_(type),
buffers_(buffers),
total_buffer_size_(boost::asio::buffer_size(buffers_))
{
}
engine::want operator()(engine& eng,
boost::system::error_code& ec,
std::size_t& bytes_transferred) const
{
return this->process(eng, ec, bytes_transferred,
boost::asio::buffer_sequence_begin(buffers_),
boost::asio::buffer_sequence_end(buffers_));
}
template <typename Handler>
void call_handler(Handler& handler,
const boost::system::error_code& ec,
const std::size_t& bytes_transferred) const
{
static_cast<Handler&&>(handler)(ec, bytes_transferred);
}
private:
template <typename Iterator>
engine::want process(engine& eng,
boost::system::error_code& ec,
std::size_t& bytes_transferred,
Iterator begin, Iterator end) const
{
Iterator iter = begin;
std::size_t accumulated_size = 0;
for (;;)
{
engine::want want = eng.handshake(type_, ec);
if (want != engine::want_input_and_retry
|| bytes_transferred == total_buffer_size_)
return want;
// Find the next buffer piece to be fed to the engine.
while (iter != end)
{
const_buffer buffer(*iter);
// Skip over any buffers which have already been consumed by the engine.
if (bytes_transferred >= accumulated_size + buffer.size())
{
accumulated_size += buffer.size();
++iter;
continue;
}
// The current buffer may have been partially consumed by the engine on
// a previous iteration. If so, adjust the buffer to point to the
// unused portion.
if (bytes_transferred > accumulated_size)
buffer = buffer + (bytes_transferred - accumulated_size);
// Pass the buffer to the engine, and update the bytes transferred to
// reflect the total number of bytes consumed so far.
bytes_transferred += buffer.size();
buffer = eng.put_input(buffer);
bytes_transferred -= buffer.size();
break;
}
}
}
stream_base::handshake_type type_;
ConstBufferSequence buffers_;
std::size_t total_buffer_size_;
};
} // namespace detail
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_DETAIL_BUFFERED_HANDSHAKE_OP_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/password_callback.hpp | //
// ssl/detail/password_callback.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_PASSWORD_CALLBACK_HPP
#define BOOST_ASIO_SSL_DETAIL_PASSWORD_CALLBACK_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <string>
#include <boost/asio/ssl/context_base.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace detail {
class password_callback_base
{
public:
virtual ~password_callback_base()
{
}
virtual std::string call(std::size_t size,
context_base::password_purpose purpose) = 0;
};
template <typename PasswordCallback>
class password_callback : public password_callback_base
{
public:
explicit password_callback(PasswordCallback callback)
: callback_(callback)
{
}
virtual std::string call(std::size_t size,
context_base::password_purpose purpose)
{
return callback_(size, purpose);
}
private:
PasswordCallback callback_;
};
} // namespace detail
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_DETAIL_PASSWORD_CALLBACK_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/openssl_types.hpp | //
// ssl/detail/openssl_types.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_OPENSSL_TYPES_HPP
#define BOOST_ASIO_SSL_DETAIL_OPENSSL_TYPES_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/socket_types.hpp>
#if defined(BOOST_ASIO_USE_WOLFSSL)
# include <wolfssl/options.h>
#endif // defined(BOOST_ASIO_USE_WOLFSSL)
#include <openssl/conf.h>
#include <openssl/ssl.h>
#if !defined(OPENSSL_NO_ENGINE)
# include <openssl/engine.h>
#endif // !defined(OPENSSL_NO_ENGINE)
#include <openssl/dh.h>
#include <openssl/err.h>
#include <openssl/rsa.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#endif // BOOST_ASIO_SSL_DETAIL_OPENSSL_TYPES_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/stream_core.hpp | //
// ssl/detail/stream_core.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP
#define BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
# include <boost/asio/deadline_timer.hpp>
#else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
# include <boost/asio/steady_timer.hpp>
#endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace detail {
struct stream_core
{
// According to the OpenSSL documentation, this is the buffer size that is
// sufficient to hold the largest possible TLS record.
enum { max_tls_record_size = 17 * 1024 };
template <typename Executor>
stream_core(SSL_CTX* context, const Executor& ex)
: engine_(context),
pending_read_(ex),
pending_write_(ex),
output_buffer_space_(max_tls_record_size),
output_buffer_(boost::asio::buffer(output_buffer_space_)),
input_buffer_space_(max_tls_record_size),
input_buffer_(boost::asio::buffer(input_buffer_space_))
{
pending_read_.expires_at(neg_infin());
pending_write_.expires_at(neg_infin());
}
template <typename Executor>
stream_core(SSL* ssl_impl, const Executor& ex)
: engine_(ssl_impl),
pending_read_(ex),
pending_write_(ex),
output_buffer_space_(max_tls_record_size),
output_buffer_(boost::asio::buffer(output_buffer_space_)),
input_buffer_space_(max_tls_record_size),
input_buffer_(boost::asio::buffer(input_buffer_space_))
{
pending_read_.expires_at(neg_infin());
pending_write_.expires_at(neg_infin());
}
stream_core(stream_core&& other)
: engine_(static_cast<engine&&>(other.engine_)),
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
pending_read_(
static_cast<boost::asio::deadline_timer&&>(
other.pending_read_)),
pending_write_(
static_cast<boost::asio::deadline_timer&&>(
other.pending_write_)),
#else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
pending_read_(
static_cast<boost::asio::steady_timer&&>(
other.pending_read_)),
pending_write_(
static_cast<boost::asio::steady_timer&&>(
other.pending_write_)),
#endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
output_buffer_space_(
static_cast<std::vector<unsigned char>&&>(
other.output_buffer_space_)),
output_buffer_(other.output_buffer_),
input_buffer_space_(
static_cast<std::vector<unsigned char>&&>(
other.input_buffer_space_)),
input_buffer_(other.input_buffer_),
input_(other.input_)
{
other.output_buffer_ = boost::asio::mutable_buffer(0, 0);
other.input_buffer_ = boost::asio::mutable_buffer(0, 0);
other.input_ = boost::asio::const_buffer(0, 0);
}
~stream_core()
{
}
stream_core& operator=(stream_core&& other)
{
if (this != &other)
{
engine_ = static_cast<engine&&>(other.engine_);
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
pending_read_ =
static_cast<boost::asio::deadline_timer&&>(
other.pending_read_);
pending_write_ =
static_cast<boost::asio::deadline_timer&&>(
other.pending_write_);
#else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
pending_read_ =
static_cast<boost::asio::steady_timer&&>(
other.pending_read_);
pending_write_ =
static_cast<boost::asio::steady_timer&&>(
other.pending_write_);
#endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
output_buffer_space_ =
static_cast<std::vector<unsigned char>&&>(
other.output_buffer_space_);
output_buffer_ = other.output_buffer_;
input_buffer_space_ =
static_cast<std::vector<unsigned char>&&>(
other.input_buffer_space_);
input_buffer_ = other.input_buffer_;
input_ = other.input_;
other.output_buffer_ = boost::asio::mutable_buffer(0, 0);
other.input_buffer_ = boost::asio::mutable_buffer(0, 0);
other.input_ = boost::asio::const_buffer(0, 0);
}
return *this;
}
// The SSL engine.
engine engine_;
#if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
// Timer used for storing queued read operations.
boost::asio::deadline_timer pending_read_;
// Timer used for storing queued write operations.
boost::asio::deadline_timer pending_write_;
// Helper function for obtaining a time value that always fires.
static boost::asio::deadline_timer::time_type neg_infin()
{
return boost::posix_time::neg_infin;
}
// Helper function for obtaining a time value that never fires.
static boost::asio::deadline_timer::time_type pos_infin()
{
return boost::posix_time::pos_infin;
}
// Helper function to get a timer's expiry time.
static boost::asio::deadline_timer::time_type expiry(
const boost::asio::deadline_timer& timer)
{
return timer.expires_at();
}
#else // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
// Timer used for storing queued read operations.
boost::asio::steady_timer pending_read_;
// Timer used for storing queued write operations.
boost::asio::steady_timer pending_write_;
// Helper function for obtaining a time value that always fires.
static boost::asio::steady_timer::time_point neg_infin()
{
return (boost::asio::steady_timer::time_point::min)();
}
// Helper function for obtaining a time value that never fires.
static boost::asio::steady_timer::time_point pos_infin()
{
return (boost::asio::steady_timer::time_point::max)();
}
// Helper function to get a timer's expiry time.
static boost::asio::steady_timer::time_point expiry(
const boost::asio::steady_timer& timer)
{
return timer.expiry();
}
#endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
// Buffer space used to prepare output intended for the transport.
std::vector<unsigned char> output_buffer_space_;
// A buffer that may be used to prepare output intended for the transport.
boost::asio::mutable_buffer output_buffer_;
// Buffer space used to read input intended for the engine.
std::vector<unsigned char> input_buffer_space_;
// A buffer that may be used to read input intended for the engine.
boost::asio::mutable_buffer input_buffer_;
// The buffer pointing to the engine's unconsumed input.
boost::asio::const_buffer input_;
};
} // namespace detail
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_DETAIL_STREAM_CORE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/engine.hpp | //
// ssl/detail/engine.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_ENGINE_HPP
#define BOOST_ASIO_SSL_DETAIL_ENGINE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/detail/static_mutex.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/asio/ssl/detail/verify_callback.hpp>
#include <boost/asio/ssl/stream_base.hpp>
#include <boost/asio/ssl/verify_mode.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace detail {
class engine
{
public:
enum want
{
// Returned by functions to indicate that the engine wants input. The input
// buffer should be updated to point to the data. The engine then needs to
// be called again to retry the operation.
want_input_and_retry = -2,
// Returned by functions to indicate that the engine wants to write output.
// The output buffer points to the data to be written. The engine then
// needs to be called again to retry the operation.
want_output_and_retry = -1,
// Returned by functions to indicate that the engine doesn't need input or
// output.
want_nothing = 0,
// Returned by functions to indicate that the engine wants to write output.
// The output buffer points to the data to be written. After that the
// operation is complete, and the engine does not need to be called again.
want_output = 1
};
// Construct a new engine for the specified context.
BOOST_ASIO_DECL explicit engine(SSL_CTX* context);
// Construct a new engine for an existing native SSL implementation.
BOOST_ASIO_DECL explicit engine(SSL* ssl_impl);
// Move construct from another engine.
BOOST_ASIO_DECL engine(engine&& other) noexcept;
// Destructor.
BOOST_ASIO_DECL ~engine();
// Move assign from another engine.
BOOST_ASIO_DECL engine& operator=(engine&& other) noexcept;
// Get the underlying implementation in the native type.
BOOST_ASIO_DECL SSL* native_handle();
// Set the peer verification mode.
BOOST_ASIO_DECL boost::system::error_code set_verify_mode(
verify_mode v, boost::system::error_code& ec);
// Set the peer verification depth.
BOOST_ASIO_DECL boost::system::error_code set_verify_depth(
int depth, boost::system::error_code& ec);
// Set a peer certificate verification callback.
BOOST_ASIO_DECL boost::system::error_code set_verify_callback(
verify_callback_base* callback, boost::system::error_code& ec);
// Perform an SSL handshake using either SSL_connect (client-side) or
// SSL_accept (server-side).
BOOST_ASIO_DECL want handshake(
stream_base::handshake_type type, boost::system::error_code& ec);
// Perform a graceful shutdown of the SSL session.
BOOST_ASIO_DECL want shutdown(boost::system::error_code& ec);
// Write bytes to the SSL session.
BOOST_ASIO_DECL want write(const boost::asio::const_buffer& data,
boost::system::error_code& ec, std::size_t& bytes_transferred);
// Read bytes from the SSL session.
BOOST_ASIO_DECL want read(const boost::asio::mutable_buffer& data,
boost::system::error_code& ec, std::size_t& bytes_transferred);
// Get output data to be written to the transport.
BOOST_ASIO_DECL boost::asio::mutable_buffer get_output(
const boost::asio::mutable_buffer& data);
// Put input data that was read from the transport.
BOOST_ASIO_DECL boost::asio::const_buffer put_input(
const boost::asio::const_buffer& data);
// Map an error::eof code returned by the underlying transport according to
// the type and state of the SSL session. Returns a const reference to the
// error code object, suitable for passing to a completion handler.
BOOST_ASIO_DECL const boost::system::error_code& map_error_code(
boost::system::error_code& ec) const;
private:
// Disallow copying and assignment.
engine(const engine&);
engine& operator=(const engine&);
// Callback used when the SSL implementation wants to verify a certificate.
BOOST_ASIO_DECL static int verify_callback_function(
int preverified, X509_STORE_CTX* ctx);
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
// The SSL_accept function may not be thread safe. This mutex is used to
// protect all calls to the SSL_accept function.
BOOST_ASIO_DECL static boost::asio::detail::static_mutex& accept_mutex();
#endif // (OPENSSL_VERSION_NUMBER < 0x10000000L)
// Perform one operation. Returns >= 0 on success or error, want_read if the
// operation needs more input, or want_write if it needs to write some output
// before the operation can complete.
BOOST_ASIO_DECL want perform(int (engine::* op)(void*, std::size_t),
void* data, std::size_t length, boost::system::error_code& ec,
std::size_t* bytes_transferred);
// Adapt the SSL_accept function to the signature needed for perform().
BOOST_ASIO_DECL int do_accept(void*, std::size_t);
// Adapt the SSL_connect function to the signature needed for perform().
BOOST_ASIO_DECL int do_connect(void*, std::size_t);
// Adapt the SSL_shutdown function to the signature needed for perform().
BOOST_ASIO_DECL int do_shutdown(void*, std::size_t);
// Adapt the SSL_read function to the signature needed for perform().
BOOST_ASIO_DECL int do_read(void* data, std::size_t length);
// Adapt the SSL_write function to the signature needed for perform().
BOOST_ASIO_DECL int do_write(void* data, std::size_t length);
SSL* ssl_;
BIO* ext_bio_;
};
} // namespace detail
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/ssl/detail/impl/engine.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // BOOST_ASIO_SSL_DETAIL_ENGINE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/handshake_op.hpp | //
// ssl/detail/handshake_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_HANDSHAKE_OP_HPP
#define BOOST_ASIO_SSL_DETAIL_HANDSHAKE_OP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace detail {
class handshake_op
{
public:
static constexpr const char* tracking_name()
{
return "ssl::stream<>::async_handshake";
}
handshake_op(stream_base::handshake_type type)
: type_(type)
{
}
engine::want operator()(engine& eng,
boost::system::error_code& ec,
std::size_t& bytes_transferred) const
{
bytes_transferred = 0;
return eng.handshake(type_, ec);
}
template <typename Handler>
void call_handler(Handler& handler,
const boost::system::error_code& ec,
const std::size_t&) const
{
static_cast<Handler&&>(handler)(ec);
}
private:
stream_base::handshake_type type_;
};
} // namespace detail
} // namespace ssl
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_DETAIL_HANDSHAKE_OP_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/ssl/detail/io.hpp | //
// ssl/detail/io.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_SSL_DETAIL_IO_HPP
#define BOOST_ASIO_SSL_DETAIL_IO_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/base_from_cancellation_state.hpp>
#include <boost/asio/detail/handler_tracking.hpp>
#include <boost/asio/ssl/detail/engine.hpp>
#include <boost/asio/ssl/detail/stream_core.hpp>
#include <boost/asio/write.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace ssl {
namespace detail {
template <typename Stream, typename Operation>
std::size_t io(Stream& next_layer, stream_core& core,
const Operation& op, boost::system::error_code& ec)
{
boost::system::error_code io_ec;
std::size_t bytes_transferred = 0;
do switch (op(core.engine_, ec, bytes_transferred))
{
case engine::want_input_and_retry:
// If the input buffer is empty then we need to read some more data from
// the underlying transport.
if (core.input_.size() == 0)
{
core.input_ = boost::asio::buffer(core.input_buffer_,
next_layer.read_some(core.input_buffer_, io_ec));
if (!ec)
ec = io_ec;
}
// Pass the new input data to the engine.
core.input_ = core.engine_.put_input(core.input_);
// Try the operation again.
continue;
case engine::want_output_and_retry:
// Get output data from the engine and write it to the underlying
// transport.
boost::asio::write(next_layer,
core.engine_.get_output(core.output_buffer_), io_ec);
if (!ec)
ec = io_ec;
// Try the operation again.
continue;
case engine::want_output:
// Get output data from the engine and write it to the underlying
// transport.
boost::asio::write(next_layer,
core.engine_.get_output(core.output_buffer_), io_ec);
if (!ec)
ec = io_ec;
// Operation is complete. Return result to caller.
core.engine_.map_error_code(ec);
return bytes_transferred;
default:
// Operation is complete. Return result to caller.
core.engine_.map_error_code(ec);
return bytes_transferred;
} while (!ec);
// Operation failed. Return result to caller.
core.engine_.map_error_code(ec);
return 0;
}
template <typename Stream, typename Operation, typename Handler>
class io_op
: public boost::asio::detail::base_from_cancellation_state<Handler>
{
public:
io_op(Stream& next_layer, stream_core& core,
const Operation& op, Handler& handler)
: boost::asio::detail::base_from_cancellation_state<Handler>(handler),
next_layer_(next_layer),
core_(core),
op_(op),
start_(0),
want_(engine::want_nothing),
bytes_transferred_(0),
handler_(static_cast<Handler&&>(handler))
{
}
io_op(const io_op& other)
: boost::asio::detail::base_from_cancellation_state<Handler>(other),
next_layer_(other.next_layer_),
core_(other.core_),
op_(other.op_),
start_(other.start_),
want_(other.want_),
ec_(other.ec_),
bytes_transferred_(other.bytes_transferred_),
handler_(other.handler_)
{
}
io_op(io_op&& other)
: boost::asio::detail::base_from_cancellation_state<Handler>(
static_cast<
boost::asio::detail::base_from_cancellation_state<Handler>&&>(other)),
next_layer_(other.next_layer_),
core_(other.core_),
op_(static_cast<Operation&&>(other.op_)),
start_(other.start_),
want_(other.want_),
ec_(other.ec_),
bytes_transferred_(other.bytes_transferred_),
handler_(static_cast<Handler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred = ~std::size_t(0), int start = 0)
{
switch (start_ = start)
{
case 1: // Called after at least one async operation.
do
{
switch (want_ = op_(core_.engine_, ec_, bytes_transferred_))
{
case engine::want_input_and_retry:
// If the input buffer already has data in it we can pass it to the
// engine and then retry the operation immediately.
if (core_.input_.size() != 0)
{
core_.input_ = core_.engine_.put_input(core_.input_);
continue;
}
// The engine wants more data to be read from input. However, we
// cannot allow more than one read operation at a time on the
// underlying transport. The pending_read_ timer's expiry is set to
// pos_infin if a read is in progress, and neg_infin otherwise.
if (core_.expiry(core_.pending_read_) == core_.neg_infin())
{
// Prevent other read operations from being started.
core_.pending_read_.expires_at(core_.pos_infin());
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, Operation::tracking_name()));
// Start reading some data from the underlying transport.
next_layer_.async_read_some(
boost::asio::buffer(core_.input_buffer_),
static_cast<io_op&&>(*this));
}
else
{
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, Operation::tracking_name()));
// Wait until the current read operation completes.
core_.pending_read_.async_wait(static_cast<io_op&&>(*this));
}
// Yield control until asynchronous operation completes. Control
// resumes at the "default:" label below.
return;
case engine::want_output_and_retry:
case engine::want_output:
// The engine wants some data to be written to the output. However, we
// cannot allow more than one write operation at a time on the
// underlying transport. The pending_write_ timer's expiry is set to
// pos_infin if a write is in progress, and neg_infin otherwise.
if (core_.expiry(core_.pending_write_) == core_.neg_infin())
{
// Prevent other write operations from being started.
core_.pending_write_.expires_at(core_.pos_infin());
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, Operation::tracking_name()));
// Start writing all the data to the underlying transport.
boost::asio::async_write(next_layer_,
core_.engine_.get_output(core_.output_buffer_),
static_cast<io_op&&>(*this));
}
else
{
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, Operation::tracking_name()));
// Wait until the current write operation completes.
core_.pending_write_.async_wait(static_cast<io_op&&>(*this));
}
// Yield control until asynchronous operation completes. Control
// resumes at the "default:" label below.
return;
default:
// The SSL operation is done and we can invoke the handler, but we
// have to keep in mind that this function might be being called from
// the async operation's initiating function. In this case we're not
// allowed to call the handler directly. Instead, issue a zero-sized
// read so the handler runs "as-if" posted using io_context::post().
if (start)
{
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, Operation::tracking_name()));
next_layer_.async_read_some(
boost::asio::buffer(core_.input_buffer_, 0),
static_cast<io_op&&>(*this));
// Yield control until asynchronous operation completes. Control
// resumes at the "default:" label below.
return;
}
else
{
// Continue on to run handler directly.
break;
}
}
default:
if (bytes_transferred == ~std::size_t(0))
bytes_transferred = 0; // Timer cancellation, no data transferred.
else if (!ec_)
ec_ = ec;
switch (want_)
{
case engine::want_input_and_retry:
// Add received data to the engine's input.
core_.input_ = boost::asio::buffer(
core_.input_buffer_, bytes_transferred);
core_.input_ = core_.engine_.put_input(core_.input_);
// Release any waiting read operations.
core_.pending_read_.expires_at(core_.neg_infin());
// Check for cancellation before continuing.
if (this->cancelled() != cancellation_type::none)
{
ec_ = boost::asio::error::operation_aborted;
break;
}
// Try the operation again.
continue;
case engine::want_output_and_retry:
// Release any waiting write operations.
core_.pending_write_.expires_at(core_.neg_infin());
// Check for cancellation before continuing.
if (this->cancelled() != cancellation_type::none)
{
ec_ = boost::asio::error::operation_aborted;
break;
}
// Try the operation again.
continue;
case engine::want_output:
// Release any waiting write operations.
core_.pending_write_.expires_at(core_.neg_infin());
// Fall through to call handler.
default:
// Pass the result to the handler.
op_.call_handler(handler_,
core_.engine_.map_error_code(ec_),
ec_ ? 0 : bytes_transferred_);
// Our work here is done.
return;
}
} while (!ec_);
// Operation failed. Pass the result to the handler.
op_.call_handler(handler_, core_.engine_.map_error_code(ec_), 0);
}
}
//private:
Stream& next_layer_;
stream_core& core_;
Operation op_;
int start_;
engine::want want_;
boost::system::error_code ec_;
std::size_t bytes_transferred_;
Handler handler_;
};
template <typename Stream, typename Operation, typename Handler>
inline bool asio_handler_is_continuation(
io_op<Stream, Operation, Handler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(this_handler->handler_);
}
template <typename Stream, typename Operation, typename Handler>
inline void async_io(Stream& next_layer, stream_core& core,
const Operation& op, Handler& handler)
{
io_op<Stream, Operation, Handler>(
next_layer, core, op, handler)(
boost::system::error_code(), 0, 1);
}
} // namespace detail
} // namespace ssl
template <template <typename, typename> class Associator,
typename Stream, typename Operation,
typename Handler, typename DefaultCandidate>
struct associator<Associator,
ssl::detail::io_op<Stream, Operation, Handler>,
DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const ssl::detail::io_op<Stream, Operation, Handler>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const ssl::detail::io_op<Stream, Operation, Handler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_SSL_DETAIL_IO_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/redirect_error.hpp |
// impl/redirect_error.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_REDIRECT_ERROR_HPP
#define BOOST_ASIO_IMPL_REDIRECT_ERROR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/associator.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/system/system_error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
// Class to adapt a redirect_error_t as a completion handler.
template <typename Handler>
class redirect_error_handler
{
public:
typedef void result_type;
template <typename CompletionToken>
redirect_error_handler(redirect_error_t<CompletionToken> e)
: ec_(e.ec_),
handler_(static_cast<CompletionToken&&>(e.token_))
{
}
template <typename RedirectedHandler>
redirect_error_handler(boost::system::error_code& ec,
RedirectedHandler&& h)
: ec_(ec),
handler_(static_cast<RedirectedHandler&&>(h))
{
}
void operator()()
{
static_cast<Handler&&>(handler_)();
}
template <typename Arg, typename... Args>
enable_if_t<
!is_same<decay_t<Arg>, boost::system::error_code>::value
>
operator()(Arg&& arg, Args&&... args)
{
static_cast<Handler&&>(handler_)(
static_cast<Arg&&>(arg),
static_cast<Args&&>(args)...);
}
template <typename... Args>
void operator()(const boost::system::error_code& ec, Args&&... args)
{
ec_ = ec;
static_cast<Handler&&>(handler_)(static_cast<Args&&>(args)...);
}
//private:
boost::system::error_code& ec_;
Handler handler_;
};
template <typename Handler>
inline bool asio_handler_is_continuation(
redirect_error_handler<Handler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Signature>
struct redirect_error_signature
{
typedef Signature type;
};
template <typename R, typename... Args>
struct redirect_error_signature<R(boost::system::error_code, Args...)>
{
typedef R type(Args...);
};
template <typename R, typename... Args>
struct redirect_error_signature<R(const boost::system::error_code&, Args...)>
{
typedef R type(Args...);
};
template <typename R, typename... Args>
struct redirect_error_signature<R(boost::system::error_code, Args...) &>
{
typedef R type(Args...) &;
};
template <typename R, typename... Args>
struct redirect_error_signature<R(const boost::system::error_code&, Args...) &>
{
typedef R type(Args...) &;
};
template <typename R, typename... Args>
struct redirect_error_signature<R(boost::system::error_code, Args...) &&>
{
typedef R type(Args...) &&;
};
template <typename R, typename... Args>
struct redirect_error_signature<R(const boost::system::error_code&, Args...) &&>
{
typedef R type(Args...) &&;
};
#if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
template <typename R, typename... Args>
struct redirect_error_signature<
R(boost::system::error_code, Args...) noexcept>
{
typedef R type(Args...) & noexcept;
};
template <typename R, typename... Args>
struct redirect_error_signature<
R(const boost::system::error_code&, Args...) noexcept>
{
typedef R type(Args...) & noexcept;
};
template <typename R, typename... Args>
struct redirect_error_signature<
R(boost::system::error_code, Args...) & noexcept>
{
typedef R type(Args...) & noexcept;
};
template <typename R, typename... Args>
struct redirect_error_signature<
R(const boost::system::error_code&, Args...) & noexcept>
{
typedef R type(Args...) & noexcept;
};
template <typename R, typename... Args>
struct redirect_error_signature<
R(boost::system::error_code, Args...) && noexcept>
{
typedef R type(Args...) && noexcept;
};
template <typename R, typename... Args>
struct redirect_error_signature<
R(const boost::system::error_code&, Args...) && noexcept>
{
typedef R type(Args...) && noexcept;
};
#endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <typename CompletionToken, typename Signature>
struct async_result<redirect_error_t<CompletionToken>, Signature>
: async_result<CompletionToken,
typename detail::redirect_error_signature<Signature>::type>
{
struct init_wrapper
{
explicit init_wrapper(boost::system::error_code& ec)
: ec_(ec)
{
}
template <typename Handler, typename Initiation, typename... Args>
void operator()(Handler&& handler,
Initiation&& initiation, Args&&... args) const
{
static_cast<Initiation&&>(initiation)(
detail::redirect_error_handler<decay_t<Handler>>(
ec_, static_cast<Handler&&>(handler)),
static_cast<Args&&>(args)...);
}
boost::system::error_code& ec_;
};
template <typename Initiation, typename RawCompletionToken, typename... Args>
static auto initiate(Initiation&& initiation,
RawCompletionToken&& token, Args&&... args)
-> decltype(
async_initiate<CompletionToken,
typename detail::redirect_error_signature<Signature>::type>(
declval<init_wrapper>(), token.token_,
static_cast<Initiation&&>(initiation),
static_cast<Args&&>(args)...))
{
return async_initiate<CompletionToken,
typename detail::redirect_error_signature<Signature>::type>(
init_wrapper(token.ec_), token.token_,
static_cast<Initiation&&>(initiation),
static_cast<Args&&>(args)...);
}
};
template <template <typename, typename> class Associator,
typename Handler, typename DefaultCandidate>
struct associator<Associator,
detail::redirect_error_handler<Handler>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::redirect_error_handler<Handler>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::redirect_error_handler<Handler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_REDIRECT_ERROR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/read.hpp | //
// impl/read.hpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_READ_HPP
#define BOOST_ASIO_IMPL_READ_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <algorithm>
#include <boost/asio/associator.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/detail/array_fwd.hpp>
#include <boost/asio/detail/base_from_cancellation_state.hpp>
#include <boost/asio/detail/base_from_completion_cond.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/dependent_type.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_tracking.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail
{
template <typename SyncReadStream, typename MutableBufferSequence,
typename MutableBufferIterator, typename CompletionCondition>
std::size_t read_buffer_seq(SyncReadStream& s,
const MutableBufferSequence& buffers, const MutableBufferIterator&,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<mutable_buffer,
MutableBufferSequence, MutableBufferIterator> tmp(buffers);
while (!tmp.empty())
{
if (std::size_t max_size = detail::adapt_completion_condition_result(
completion_condition(ec, tmp.total_consumed())))
tmp.consume(s.read_some(tmp.prepare(max_size), ec));
else
break;
}
return tmp.total_consumed();
}
} // namespace detail
template <typename SyncReadStream, typename MutableBufferSequence,
typename CompletionCondition>
std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec,
constraint_t<
is_mutable_buffer_sequence<MutableBufferSequence>::value
>)
{
return detail::read_buffer_seq(s, buffers,
boost::asio::buffer_sequence_begin(buffers),
static_cast<CompletionCondition&&>(completion_condition), ec);
}
template <typename SyncReadStream, typename MutableBufferSequence>
inline std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
constraint_t<
is_mutable_buffer_sequence<MutableBufferSequence>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read(s, buffers, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "read");
return bytes_transferred;
}
template <typename SyncReadStream, typename MutableBufferSequence>
inline std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
boost::system::error_code& ec,
constraint_t<
is_mutable_buffer_sequence<MutableBufferSequence>::value
>)
{
return read(s, buffers, transfer_all(), ec);
}
template <typename SyncReadStream, typename MutableBufferSequence,
typename CompletionCondition>
inline std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
CompletionCondition completion_condition,
constraint_t<
is_mutable_buffer_sequence<MutableBufferSequence>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read(s, buffers,
static_cast<CompletionCondition&&>(completion_condition), ec);
boost::asio::detail::throw_error(ec, "read");
return bytes_transferred;
}
#if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
template <typename SyncReadStream, typename DynamicBuffer_v1,
typename CompletionCondition>
std::size_t read(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
decay_t<DynamicBuffer_v1> b(
static_cast<DynamicBuffer_v1&&>(buffers));
ec = boost::system::error_code();
std::size_t total_transferred = 0;
std::size_t max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
std::size_t bytes_available = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(max_size, b.max_size() - b.size()));
while (bytes_available > 0)
{
std::size_t bytes_transferred = s.read_some(b.prepare(bytes_available), ec);
b.commit(bytes_transferred);
total_transferred += bytes_transferred;
max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
bytes_available = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(max_size, b.max_size() - b.size()));
}
return total_transferred;
}
template <typename SyncReadStream, typename DynamicBuffer_v1>
inline std::size_t read(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read(s,
static_cast<DynamicBuffer_v1&&>(buffers), transfer_all(), ec);
boost::asio::detail::throw_error(ec, "read");
return bytes_transferred;
}
template <typename SyncReadStream, typename DynamicBuffer_v1>
inline std::size_t read(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
return read(s, static_cast<DynamicBuffer_v1&&>(buffers),
transfer_all(), ec);
}
template <typename SyncReadStream, typename DynamicBuffer_v1,
typename CompletionCondition>
inline std::size_t read(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
CompletionCondition completion_condition,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read(s,
static_cast<DynamicBuffer_v1&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition), ec);
boost::asio::detail::throw_error(ec, "read");
return bytes_transferred;
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename SyncReadStream, typename Allocator,
typename CompletionCondition>
inline std::size_t read(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
return read(s, basic_streambuf_ref<Allocator>(b),
static_cast<CompletionCondition&&>(completion_condition), ec);
}
template <typename SyncReadStream, typename Allocator>
inline std::size_t read(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b)
{
return read(s, basic_streambuf_ref<Allocator>(b));
}
template <typename SyncReadStream, typename Allocator>
inline std::size_t read(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
boost::system::error_code& ec)
{
return read(s, basic_streambuf_ref<Allocator>(b), ec);
}
template <typename SyncReadStream, typename Allocator,
typename CompletionCondition>
inline std::size_t read(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition)
{
return read(s, basic_streambuf_ref<Allocator>(b),
static_cast<CompletionCondition&&>(completion_condition));
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
#endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
template <typename SyncReadStream, typename DynamicBuffer_v2,
typename CompletionCondition>
std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
CompletionCondition completion_condition, boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
DynamicBuffer_v2& b = buffers;
ec = boost::system::error_code();
std::size_t total_transferred = 0;
std::size_t max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
std::size_t bytes_available = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(max_size, b.max_size() - b.size()));
while (bytes_available > 0)
{
std::size_t pos = b.size();
b.grow(bytes_available);
std::size_t bytes_transferred = s.read_some(
b.data(pos, bytes_available), ec);
b.shrink(bytes_available - bytes_transferred);
total_transferred += bytes_transferred;
max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
bytes_available = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(max_size, b.max_size() - b.size()));
}
return total_transferred;
}
template <typename SyncReadStream, typename DynamicBuffer_v2>
inline std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read(s,
static_cast<DynamicBuffer_v2&&>(buffers), transfer_all(), ec);
boost::asio::detail::throw_error(ec, "read");
return bytes_transferred;
}
template <typename SyncReadStream, typename DynamicBuffer_v2>
inline std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
return read(s, static_cast<DynamicBuffer_v2&&>(buffers),
transfer_all(), ec);
}
template <typename SyncReadStream, typename DynamicBuffer_v2,
typename CompletionCondition>
inline std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
CompletionCondition completion_condition,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read(s,
static_cast<DynamicBuffer_v2&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition), ec);
boost::asio::detail::throw_error(ec, "read");
return bytes_transferred;
}
namespace detail
{
template <typename AsyncReadStream, typename MutableBufferSequence,
typename MutableBufferIterator, typename CompletionCondition,
typename ReadHandler>
class read_op
: public base_from_cancellation_state<ReadHandler>,
base_from_completion_cond<CompletionCondition>
{
public:
read_op(AsyncReadStream& stream, const MutableBufferSequence& buffers,
CompletionCondition& completion_condition, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
base_from_completion_cond<CompletionCondition>(completion_condition),
stream_(stream),
buffers_(buffers),
start_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_op(const read_op& other)
: base_from_cancellation_state<ReadHandler>(other),
base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
handler_(other.handler_)
{
}
read_op(read_op&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
base_from_completion_cond<CompletionCondition>(
static_cast<base_from_completion_cond<CompletionCondition>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<buffers_type&&>(other.buffers_)),
start_(other.start_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t max_size;
switch (start_ = start)
{
case 1:
max_size = this->check_for_completion(ec, buffers_.total_consumed());
for (;;)
{
{
BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_read"));
stream_.async_read_some(buffers_.prepare(max_size),
static_cast<read_op&&>(*this));
}
return; default:
buffers_.consume(bytes_transferred);
if ((!ec && bytes_transferred == 0) || buffers_.empty())
break;
max_size = this->check_for_completion(ec, buffers_.total_consumed());
if (max_size == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
static_cast<ReadHandler&&>(handler_)(
static_cast<const boost::system::error_code&>(ec),
static_cast<const std::size_t&>(buffers_.total_consumed()));
}
}
//private:
typedef boost::asio::detail::consuming_buffers<mutable_buffer,
MutableBufferSequence, MutableBufferIterator> buffers_type;
AsyncReadStream& stream_;
buffers_type buffers_;
int start_;
ReadHandler handler_;
};
template <typename AsyncReadStream, typename MutableBufferSequence,
typename MutableBufferIterator, typename CompletionCondition,
typename ReadHandler>
inline bool asio_handler_is_continuation(
read_op<AsyncReadStream, MutableBufferSequence, MutableBufferIterator,
CompletionCondition, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncReadStream, typename MutableBufferSequence,
typename MutableBufferIterator, typename CompletionCondition,
typename ReadHandler>
inline void start_read_op(AsyncReadStream& stream,
const MutableBufferSequence& buffers, const MutableBufferIterator&,
CompletionCondition& completion_condition, ReadHandler& handler)
{
read_op<AsyncReadStream, MutableBufferSequence,
MutableBufferIterator, CompletionCondition, ReadHandler>(
stream, buffers, completion_condition, handler)(
boost::system::error_code(), 0, 1);
}
template <typename AsyncReadStream>
class initiate_async_read
{
public:
typedef typename AsyncReadStream::executor_type executor_type;
explicit initiate_async_read(AsyncReadStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename ReadHandler, typename MutableBufferSequence,
typename CompletionCondition>
void operator()(ReadHandler&& handler,
const MutableBufferSequence& buffers,
CompletionCondition&& completion_cond) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
start_read_op(stream_, buffers,
boost::asio::buffer_sequence_begin(buffers),
completion_cond2.value, handler2.value);
}
private:
AsyncReadStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncReadStream, typename MutableBufferSequence,
typename MutableBufferIterator, typename CompletionCondition,
typename ReadHandler, typename DefaultCandidate>
struct associator<Associator,
detail::read_op<AsyncReadStream, MutableBufferSequence,
MutableBufferIterator, CompletionCondition, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_op<AsyncReadStream, MutableBufferSequence,
MutableBufferIterator, CompletionCondition, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_op<AsyncReadStream, MutableBufferSequence,
MutableBufferIterator, CompletionCondition, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncReadStream,
typename MutableBufferSequence, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, ReadToken&& token,
constraint_t<
is_mutable_buffer_sequence<MutableBufferSequence>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read<AsyncReadStream>>(), token, buffers,
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read<AsyncReadStream>(s), token, buffers,
static_cast<CompletionCondition&&>(completion_condition));
}
template <typename AsyncReadStream, typename MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read(AsyncReadStream& s,
const MutableBufferSequence& buffers, ReadToken&& token,
constraint_t<
is_mutable_buffer_sequence<MutableBufferSequence>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read<AsyncReadStream>>(),
token, buffers, transfer_all()))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read<AsyncReadStream>(s),
token, buffers, transfer_all());
}
#if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
namespace detail
{
template <typename AsyncReadStream, typename DynamicBuffer_v1,
typename CompletionCondition, typename ReadHandler>
class read_dynbuf_v1_op
: public base_from_cancellation_state<ReadHandler>,
base_from_completion_cond<CompletionCondition>
{
public:
template <typename BufferSequence>
read_dynbuf_v1_op(AsyncReadStream& stream,
BufferSequence&& buffers,
CompletionCondition& completion_condition, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
base_from_completion_cond<CompletionCondition>(completion_condition),
stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
start_(0),
total_transferred_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_dynbuf_v1_op(const read_dynbuf_v1_op& other)
: base_from_cancellation_state<ReadHandler>(other),
base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_dynbuf_v1_op(read_dynbuf_v1_op&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
base_from_completion_cond<CompletionCondition>(
static_cast<base_from_completion_cond<CompletionCondition>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v1&&>(other.buffers_)),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t max_size, bytes_available;
switch (start_ = start)
{
case 1:
max_size = this->check_for_completion(ec, total_transferred_);
bytes_available = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(max_size,
buffers_.max_size() - buffers_.size()));
for (;;)
{
{
BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_read"));
stream_.async_read_some(buffers_.prepare(bytes_available),
static_cast<read_dynbuf_v1_op&&>(*this));
}
return; default:
total_transferred_ += bytes_transferred;
buffers_.commit(bytes_transferred);
max_size = this->check_for_completion(ec, total_transferred_);
bytes_available = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(max_size,
buffers_.max_size() - buffers_.size()));
if ((!ec && bytes_transferred == 0) || bytes_available == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
static_cast<ReadHandler&&>(handler_)(
static_cast<const boost::system::error_code&>(ec),
static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncReadStream& stream_;
DynamicBuffer_v1 buffers_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
template <typename AsyncReadStream, typename DynamicBuffer_v1,
typename CompletionCondition, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_dynbuf_v1_op<AsyncReadStream, DynamicBuffer_v1,
CompletionCondition, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncReadStream>
class initiate_async_read_dynbuf_v1
{
public:
typedef typename AsyncReadStream::executor_type executor_type;
explicit initiate_async_read_dynbuf_v1(AsyncReadStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename ReadHandler, typename DynamicBuffer_v1,
typename CompletionCondition>
void operator()(ReadHandler&& handler,
DynamicBuffer_v1&& buffers,
CompletionCondition&& completion_cond) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
read_dynbuf_v1_op<AsyncReadStream, decay_t<DynamicBuffer_v1>,
CompletionCondition, decay_t<ReadHandler>>(
stream_, static_cast<DynamicBuffer_v1&&>(buffers),
completion_cond2.value, handler2.value)(
boost::system::error_code(), 0, 1);
}
private:
AsyncReadStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncReadStream, typename DynamicBuffer_v1,
typename CompletionCondition, typename ReadHandler,
typename DefaultCandidate>
struct associator<Associator,
detail::read_dynbuf_v1_op<AsyncReadStream,
DynamicBuffer_v1, CompletionCondition, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_dynbuf_v1_op<AsyncReadStream, DynamicBuffer_v1,
CompletionCondition, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_dynbuf_v1_op<AsyncReadStream,
DynamicBuffer_v1, CompletionCondition, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncReadStream, typename DynamicBuffer_v1,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read(AsyncReadStream& s,
DynamicBuffer_v1&& buffers, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v1&&>(buffers), transfer_all()))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_dynbuf_v1<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v1&&>(buffers), transfer_all());
}
template <typename AsyncReadStream,
typename DynamicBuffer_v1, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read(AsyncReadStream& s, DynamicBuffer_v1&& buffers,
CompletionCondition completion_condition, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v1&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_dynbuf_v1<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v1&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition));
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename AsyncReadStream, typename Allocator,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read(AsyncReadStream& s,
basic_streambuf<Allocator>& b, ReadToken&& token)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream>>(),
token, basic_streambuf_ref<Allocator>(b), transfer_all()))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_dynbuf_v1<AsyncReadStream>(s),
token, basic_streambuf_ref<Allocator>(b), transfer_all());
}
template <typename AsyncReadStream,
typename Allocator, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, ReadToken&& token)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_dynbuf_v1<AsyncReadStream>>(),
token, basic_streambuf_ref<Allocator>(b),
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_dynbuf_v1<AsyncReadStream>(s),
token, basic_streambuf_ref<Allocator>(b),
static_cast<CompletionCondition&&>(completion_condition));
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
#endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
namespace detail
{
template <typename AsyncReadStream, typename DynamicBuffer_v2,
typename CompletionCondition, typename ReadHandler>
class read_dynbuf_v2_op
: public base_from_cancellation_state<ReadHandler>,
base_from_completion_cond<CompletionCondition>
{
public:
template <typename BufferSequence>
read_dynbuf_v2_op(AsyncReadStream& stream,
BufferSequence&& buffers,
CompletionCondition& completion_condition, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
base_from_completion_cond<CompletionCondition>(completion_condition),
stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
start_(0),
total_transferred_(0),
bytes_available_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_dynbuf_v2_op(const read_dynbuf_v2_op& other)
: base_from_cancellation_state<ReadHandler>(other),
base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
total_transferred_(other.total_transferred_),
bytes_available_(other.bytes_available_),
handler_(other.handler_)
{
}
read_dynbuf_v2_op(read_dynbuf_v2_op&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
base_from_completion_cond<CompletionCondition>(
static_cast<base_from_completion_cond<CompletionCondition>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v2&&>(other.buffers_)),
start_(other.start_),
total_transferred_(other.total_transferred_),
bytes_available_(other.bytes_available_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t max_size, pos;
switch (start_ = start)
{
case 1:
max_size = this->check_for_completion(ec, total_transferred_);
bytes_available_ = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(max_size,
buffers_.max_size() - buffers_.size()));
for (;;)
{
pos = buffers_.size();
buffers_.grow(bytes_available_);
{
BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_read"));
stream_.async_read_some(buffers_.data(pos, bytes_available_),
static_cast<read_dynbuf_v2_op&&>(*this));
}
return; default:
total_transferred_ += bytes_transferred;
buffers_.shrink(bytes_available_ - bytes_transferred);
max_size = this->check_for_completion(ec, total_transferred_);
bytes_available_ = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(max_size,
buffers_.max_size() - buffers_.size()));
if ((!ec && bytes_transferred == 0) || bytes_available_ == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
static_cast<ReadHandler&&>(handler_)(
static_cast<const boost::system::error_code&>(ec),
static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncReadStream& stream_;
DynamicBuffer_v2 buffers_;
int start_;
std::size_t total_transferred_;
std::size_t bytes_available_;
ReadHandler handler_;
};
template <typename AsyncReadStream, typename DynamicBuffer_v2,
typename CompletionCondition, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_dynbuf_v2_op<AsyncReadStream, DynamicBuffer_v2,
CompletionCondition, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncReadStream>
class initiate_async_read_dynbuf_v2
{
public:
typedef typename AsyncReadStream::executor_type executor_type;
explicit initiate_async_read_dynbuf_v2(AsyncReadStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename ReadHandler, typename DynamicBuffer_v2,
typename CompletionCondition>
void operator()(ReadHandler&& handler,
DynamicBuffer_v2&& buffers,
CompletionCondition&& completion_cond) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
read_dynbuf_v2_op<AsyncReadStream, decay_t<DynamicBuffer_v2>,
CompletionCondition, decay_t<ReadHandler>>(
stream_, static_cast<DynamicBuffer_v2&&>(buffers),
completion_cond2.value, handler2.value)(
boost::system::error_code(), 0, 1);
}
private:
AsyncReadStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncReadStream, typename DynamicBuffer_v2,
typename CompletionCondition, typename ReadHandler,
typename DefaultCandidate>
struct associator<Associator,
detail::read_dynbuf_v2_op<AsyncReadStream,
DynamicBuffer_v2, CompletionCondition, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_dynbuf_v2_op<AsyncReadStream, DynamicBuffer_v2,
CompletionCondition, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_dynbuf_v2_op<AsyncReadStream,
DynamicBuffer_v2, CompletionCondition, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncReadStream, typename DynamicBuffer_v2,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read(AsyncReadStream& s,
DynamicBuffer_v2 buffers, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_dynbuf_v2<AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v2&&>(buffers), transfer_all()))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_dynbuf_v2<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v2&&>(buffers), transfer_all());
}
template <typename AsyncReadStream,
typename DynamicBuffer_v2, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read(AsyncReadStream& s, DynamicBuffer_v2 buffers,
CompletionCondition completion_condition, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_dynbuf_v2<AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v2&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_dynbuf_v2<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v2&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition));
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_READ_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/serial_port_base.hpp | //
// impl/serial_port_base.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.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)
//
#ifndef BOOST_ASIO_IMPL_SERIAL_PORT_BASE_HPP
#define BOOST_ASIO_IMPL_SERIAL_PORT_BASE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
inline serial_port_base::baud_rate::baud_rate(unsigned int rate)
: value_(rate)
{
}
inline unsigned int serial_port_base::baud_rate::value() const
{
return value_;
}
inline serial_port_base::flow_control::type
serial_port_base::flow_control::value() const
{
return value_;
}
inline serial_port_base::parity::type serial_port_base::parity::value() const
{
return value_;
}
inline serial_port_base::stop_bits::type
serial_port_base::stop_bits::value() const
{
return value_;
}
inline unsigned int serial_port_base::character_size::value() const
{
return value_;
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_SERIAL_PORT_BASE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/read_until.hpp | //
// impl/read_until.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_READ_UNTIL_HPP
#define BOOST_ASIO_IMPL_READ_UNTIL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <boost/asio/associator.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/buffers_iterator.hpp>
#include <boost/asio/detail/base_from_cancellation_state.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_tracking.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/limits.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail
{
// Algorithm that finds a subsequence of equal values in a sequence. Returns
// (iterator,true) if a full match was found, in which case the iterator
// points to the beginning of the match. Returns (iterator,false) if a
// partial match was found at the end of the first sequence, in which case
// the iterator points to the beginning of the partial match. Returns
// (last1,false) if no full or partial match was found.
template <typename Iterator1, typename Iterator2>
std::pair<Iterator1, bool> partial_search(
Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
{
for (Iterator1 iter1 = first1; iter1 != last1; ++iter1)
{
Iterator1 test_iter1 = iter1;
Iterator2 test_iter2 = first2;
for (;; ++test_iter1, ++test_iter2)
{
if (test_iter2 == last2)
return std::make_pair(iter1, true);
if (test_iter1 == last1)
{
if (test_iter2 != first2)
return std::make_pair(iter1, false);
else
break;
}
if (*test_iter1 != *test_iter2)
break;
}
}
return std::make_pair(last1, false);
}
} // namespace detail
#if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
template <typename SyncReadStream, typename DynamicBuffer_v1>
inline std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v1&& buffers, char delim,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_until(s,
static_cast<DynamicBuffer_v1&&>(buffers), delim, ec);
boost::asio::detail::throw_error(ec, "read_until");
return bytes_transferred;
}
template <typename SyncReadStream, typename DynamicBuffer_v1>
std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
char delim, boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
decay_t<DynamicBuffer_v1> b(
static_cast<DynamicBuffer_v1&&>(buffers));
std::size_t search_position = 0;
for (;;)
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v1::const_buffers_type buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers = b.data();
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position;
iterator end = iterator::end(data_buffers);
// Look for a match.
iterator iter = std::find(start_pos, end, delim);
if (iter != end)
{
// Found a match. We're done.
ec = boost::system::error_code();
return iter - begin + 1;
}
else
{
// No match. Next search can start with the new data.
search_position = end - begin;
}
// Check if buffer is full.
if (b.size() == b.max_size())
{
ec = error::not_found;
return 0;
}
// Need more data.
std::size_t bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(65536, b.max_size() - b.size()));
b.commit(s.read_some(b.prepare(bytes_to_read), ec));
if (ec)
return 0;
}
}
template <typename SyncReadStream, typename DynamicBuffer_v1>
inline std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
BOOST_ASIO_STRING_VIEW_PARAM delim,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_until(s,
static_cast<DynamicBuffer_v1&&>(buffers), delim, ec);
boost::asio::detail::throw_error(ec, "read_until");
return bytes_transferred;
}
template <typename SyncReadStream, typename DynamicBuffer_v1>
std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
BOOST_ASIO_STRING_VIEW_PARAM delim, boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
decay_t<DynamicBuffer_v1> b(
static_cast<DynamicBuffer_v1&&>(buffers));
std::size_t search_position = 0;
for (;;)
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v1::const_buffers_type buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers = b.data();
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position;
iterator end = iterator::end(data_buffers);
// Look for a match.
std::pair<iterator, bool> result = detail::partial_search(
start_pos, end, delim.begin(), delim.end());
if (result.first != end)
{
if (result.second)
{
// Full match. We're done.
ec = boost::system::error_code();
return result.first - begin + delim.length();
}
else
{
// Partial match. Next search needs to start from beginning of match.
search_position = result.first - begin;
}
}
else
{
// No match. Next search can start with the new data.
search_position = end - begin;
}
// Check if buffer is full.
if (b.size() == b.max_size())
{
ec = error::not_found;
return 0;
}
// Need more data.
std::size_t bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(65536, b.max_size() - b.size()));
b.commit(s.read_some(b.prepare(bytes_to_read), ec));
if (ec)
return 0;
}
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if defined(BOOST_ASIO_HAS_BOOST_REGEX)
namespace detail {
struct regex_match_flags
{
template <typename T>
operator T() const
{
return T::match_default | T::match_partial;
}
};
} // namespace detail
template <typename SyncReadStream, typename DynamicBuffer_v1, typename Traits>
inline std::size_t read_until(SyncReadStream& s, DynamicBuffer_v1&& buffers,
const boost::basic_regex<char, Traits>& expr,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_until(s,
static_cast<DynamicBuffer_v1&&>(buffers), expr, ec);
boost::asio::detail::throw_error(ec, "read_until");
return bytes_transferred;
}
template <typename SyncReadStream, typename DynamicBuffer_v1, typename Traits>
std::size_t read_until(SyncReadStream& s, DynamicBuffer_v1&& buffers,
const boost::basic_regex<char, Traits>& expr, boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
decay_t<DynamicBuffer_v1> b(
static_cast<DynamicBuffer_v1&&>(buffers));
std::size_t search_position = 0;
for (;;)
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v1::const_buffers_type buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers = b.data();
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position;
iterator end = iterator::end(data_buffers);
// Look for a match.
boost::match_results<iterator,
typename std::vector<boost::sub_match<iterator>>::allocator_type>
match_results;
if (regex_search(start_pos, end, match_results,
expr, detail::regex_match_flags()))
{
if (match_results[0].matched)
{
// Full match. We're done.
ec = boost::system::error_code();
return match_results[0].second - begin;
}
else
{
// Partial match. Next search needs to start from beginning of match.
search_position = match_results[0].first - begin;
}
}
else
{
// No match. Next search can start with the new data.
search_position = end - begin;
}
// Check if buffer is full.
if (b.size() == b.max_size())
{
ec = error::not_found;
return 0;
}
// Need more data.
std::size_t bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(65536, b.max_size() - b.size()));
b.commit(s.read_some(b.prepare(bytes_to_read), ec));
if (ec)
return 0;
}
}
#endif // defined(BOOST_ASIO_HAS_BOOST_REGEX)
template <typename SyncReadStream,
typename DynamicBuffer_v1, typename MatchCondition>
inline std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
MatchCondition match_condition,
constraint_t<
is_match_condition<MatchCondition>::value
>,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_until(s,
static_cast<DynamicBuffer_v1&&>(buffers),
match_condition, ec);
boost::asio::detail::throw_error(ec, "read_until");
return bytes_transferred;
}
template <typename SyncReadStream,
typename DynamicBuffer_v1, typename MatchCondition>
std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v1&& buffers,
MatchCondition match_condition, boost::system::error_code& ec,
constraint_t<
is_match_condition<MatchCondition>::value
>,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
decay_t<DynamicBuffer_v1> b(
static_cast<DynamicBuffer_v1&&>(buffers));
std::size_t search_position = 0;
for (;;)
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v1::const_buffers_type buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers = b.data();
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position;
iterator end = iterator::end(data_buffers);
// Look for a match.
std::pair<iterator, bool> result = match_condition(start_pos, end);
if (result.second)
{
// Full match. We're done.
ec = boost::system::error_code();
return result.first - begin;
}
else if (result.first != end)
{
// Partial match. Next search needs to start from beginning of match.
search_position = result.first - begin;
}
else
{
// No match. Next search can start with the new data.
search_position = end - begin;
}
// Check if buffer is full.
if (b.size() == b.max_size())
{
ec = error::not_found;
return 0;
}
// Need more data.
std::size_t bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(65536, b.max_size() - b.size()));
b.commit(s.read_some(b.prepare(bytes_to_read), ec));
if (ec)
return 0;
}
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename SyncReadStream, typename Allocator>
inline std::size_t read_until(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b, char delim)
{
return read_until(s, basic_streambuf_ref<Allocator>(b), delim);
}
template <typename SyncReadStream, typename Allocator>
inline std::size_t read_until(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b, char delim,
boost::system::error_code& ec)
{
return read_until(s, basic_streambuf_ref<Allocator>(b), delim, ec);
}
template <typename SyncReadStream, typename Allocator>
inline std::size_t read_until(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
BOOST_ASIO_STRING_VIEW_PARAM delim)
{
return read_until(s, basic_streambuf_ref<Allocator>(b), delim);
}
template <typename SyncReadStream, typename Allocator>
inline std::size_t read_until(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
BOOST_ASIO_STRING_VIEW_PARAM delim, boost::system::error_code& ec)
{
return read_until(s, basic_streambuf_ref<Allocator>(b), delim, ec);
}
#if defined(BOOST_ASIO_HAS_BOOST_REGEX)
template <typename SyncReadStream, typename Allocator, typename Traits>
inline std::size_t read_until(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
const boost::basic_regex<char, Traits>& expr)
{
return read_until(s, basic_streambuf_ref<Allocator>(b), expr);
}
template <typename SyncReadStream, typename Allocator, typename Traits>
inline std::size_t read_until(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
const boost::basic_regex<char, Traits>& expr,
boost::system::error_code& ec)
{
return read_until(s, basic_streambuf_ref<Allocator>(b), expr, ec);
}
#endif // defined(BOOST_ASIO_HAS_BOOST_REGEX)
template <typename SyncReadStream, typename Allocator, typename MatchCondition>
inline std::size_t read_until(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b, MatchCondition match_condition,
constraint_t<is_match_condition<MatchCondition>::value>)
{
return read_until(s, basic_streambuf_ref<Allocator>(b), match_condition);
}
template <typename SyncReadStream, typename Allocator, typename MatchCondition>
inline std::size_t read_until(SyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
MatchCondition match_condition, boost::system::error_code& ec,
constraint_t<is_match_condition<MatchCondition>::value>)
{
return read_until(s, basic_streambuf_ref<Allocator>(b), match_condition, ec);
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
#endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
template <typename SyncReadStream, typename DynamicBuffer_v2>
inline std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v2 buffers, char delim,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_until(s,
static_cast<DynamicBuffer_v2&&>(buffers), delim, ec);
boost::asio::detail::throw_error(ec, "read_until");
return bytes_transferred;
}
template <typename SyncReadStream, typename DynamicBuffer_v2>
std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
char delim, boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
DynamicBuffer_v2& b = buffers;
std::size_t search_position = 0;
for (;;)
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v2::const_buffers_type buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers =
const_cast<const DynamicBuffer_v2&>(b).data(0, b.size());
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position;
iterator end = iterator::end(data_buffers);
// Look for a match.
iterator iter = std::find(start_pos, end, delim);
if (iter != end)
{
// Found a match. We're done.
ec = boost::system::error_code();
return iter - begin + 1;
}
else
{
// No match. Next search can start with the new data.
search_position = end - begin;
}
// Check if buffer is full.
if (b.size() == b.max_size())
{
ec = error::not_found;
return 0;
}
// Need more data.
std::size_t bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(65536, b.max_size() - b.size()));
std::size_t pos = b.size();
b.grow(bytes_to_read);
std::size_t bytes_transferred = s.read_some(b.data(pos, bytes_to_read), ec);
b.shrink(bytes_to_read - bytes_transferred);
if (ec)
return 0;
}
}
template <typename SyncReadStream, typename DynamicBuffer_v2>
inline std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v2 buffers, BOOST_ASIO_STRING_VIEW_PARAM delim,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_until(s,
static_cast<DynamicBuffer_v2&&>(buffers), delim, ec);
boost::asio::detail::throw_error(ec, "read_until");
return bytes_transferred;
}
template <typename SyncReadStream, typename DynamicBuffer_v2>
std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
BOOST_ASIO_STRING_VIEW_PARAM delim, boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
DynamicBuffer_v2& b = buffers;
std::size_t search_position = 0;
for (;;)
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v2::const_buffers_type buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers =
const_cast<const DynamicBuffer_v2&>(b).data(0, b.size());
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position;
iterator end = iterator::end(data_buffers);
// Look for a match.
std::pair<iterator, bool> result = detail::partial_search(
start_pos, end, delim.begin(), delim.end());
if (result.first != end)
{
if (result.second)
{
// Full match. We're done.
ec = boost::system::error_code();
return result.first - begin + delim.length();
}
else
{
// Partial match. Next search needs to start from beginning of match.
search_position = result.first - begin;
}
}
else
{
// No match. Next search can start with the new data.
search_position = end - begin;
}
// Check if buffer is full.
if (b.size() == b.max_size())
{
ec = error::not_found;
return 0;
}
// Need more data.
std::size_t bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(65536, b.max_size() - b.size()));
std::size_t pos = b.size();
b.grow(bytes_to_read);
std::size_t bytes_transferred = s.read_some(b.data(pos, bytes_to_read), ec);
b.shrink(bytes_to_read - bytes_transferred);
if (ec)
return 0;
}
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if defined(BOOST_ASIO_HAS_BOOST_REGEX)
template <typename SyncReadStream, typename DynamicBuffer_v2, typename Traits>
inline std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
const boost::basic_regex<char, Traits>& expr,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_until(s,
static_cast<DynamicBuffer_v2&&>(buffers), expr, ec);
boost::asio::detail::throw_error(ec, "read_until");
return bytes_transferred;
}
template <typename SyncReadStream, typename DynamicBuffer_v2, typename Traits>
std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
const boost::basic_regex<char, Traits>& expr, boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
DynamicBuffer_v2& b = buffers;
std::size_t search_position = 0;
for (;;)
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v2::const_buffers_type buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers =
const_cast<const DynamicBuffer_v2&>(b).data(0, b.size());
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position;
iterator end = iterator::end(data_buffers);
// Look for a match.
boost::match_results<iterator,
typename std::vector<boost::sub_match<iterator>>::allocator_type>
match_results;
if (regex_search(start_pos, end, match_results,
expr, detail::regex_match_flags()))
{
if (match_results[0].matched)
{
// Full match. We're done.
ec = boost::system::error_code();
return match_results[0].second - begin;
}
else
{
// Partial match. Next search needs to start from beginning of match.
search_position = match_results[0].first - begin;
}
}
else
{
// No match. Next search can start with the new data.
search_position = end - begin;
}
// Check if buffer is full.
if (b.size() == b.max_size())
{
ec = error::not_found;
return 0;
}
// Need more data.
std::size_t bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(65536, b.max_size() - b.size()));
std::size_t pos = b.size();
b.grow(bytes_to_read);
std::size_t bytes_transferred = s.read_some(b.data(pos, bytes_to_read), ec);
b.shrink(bytes_to_read - bytes_transferred);
if (ec)
return 0;
}
}
#endif // defined(BOOST_ASIO_HAS_BOOST_REGEX)
template <typename SyncReadStream,
typename DynamicBuffer_v2, typename MatchCondition>
inline std::size_t read_until(SyncReadStream& s,
DynamicBuffer_v2 buffers, MatchCondition match_condition,
constraint_t<
is_match_condition<MatchCondition>::value
>,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_until(s,
static_cast<DynamicBuffer_v2&&>(buffers),
match_condition, ec);
boost::asio::detail::throw_error(ec, "read_until");
return bytes_transferred;
}
template <typename SyncReadStream,
typename DynamicBuffer_v2, typename MatchCondition>
std::size_t read_until(SyncReadStream& s, DynamicBuffer_v2 buffers,
MatchCondition match_condition, boost::system::error_code& ec,
constraint_t<
is_match_condition<MatchCondition>::value
>,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
DynamicBuffer_v2& b = buffers;
std::size_t search_position = 0;
for (;;)
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v2::const_buffers_type buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers =
const_cast<const DynamicBuffer_v2&>(b).data(0, b.size());
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position;
iterator end = iterator::end(data_buffers);
// Look for a match.
std::pair<iterator, bool> result = match_condition(start_pos, end);
if (result.second)
{
// Full match. We're done.
ec = boost::system::error_code();
return result.first - begin;
}
else if (result.first != end)
{
// Partial match. Next search needs to start from beginning of match.
search_position = result.first - begin;
}
else
{
// No match. Next search can start with the new data.
search_position = end - begin;
}
// Check if buffer is full.
if (b.size() == b.max_size())
{
ec = error::not_found;
return 0;
}
// Need more data.
std::size_t bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512, b.capacity() - b.size()),
std::min<std::size_t>(65536, b.max_size() - b.size()));
std::size_t pos = b.size();
b.grow(bytes_to_read);
std::size_t bytes_transferred = s.read_some(b.data(pos, bytes_to_read), ec);
b.shrink(bytes_to_read - bytes_transferred);
if (ec)
return 0;
}
}
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
#if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
namespace detail
{
template <typename AsyncReadStream,
typename DynamicBuffer_v1, typename ReadHandler>
class read_until_delim_op_v1
: public base_from_cancellation_state<ReadHandler>
{
public:
template <typename BufferSequence>
read_until_delim_op_v1(AsyncReadStream& stream,
BufferSequence&& buffers,
char delim, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
delim_(delim),
start_(0),
search_position_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_until_delim_op_v1(const read_until_delim_op_v1& other)
: base_from_cancellation_state<ReadHandler>(other),
stream_(other.stream_),
buffers_(other.buffers_),
delim_(other.delim_),
start_(other.start_),
search_position_(other.search_position_),
handler_(other.handler_)
{
}
read_until_delim_op_v1(read_until_delim_op_v1&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v1&&>(other.buffers_)),
delim_(other.delim_),
start_(other.start_),
search_position_(other.search_position_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
std::size_t bytes_to_read;
switch (start_ = start)
{
case 1:
for (;;)
{
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v1::const_buffers_type
buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers = buffers_.data();
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position_;
iterator end = iterator::end(data_buffers);
// Look for a match.
iterator iter = std::find(start_pos, end, delim_);
if (iter != end)
{
// Found a match. We're done.
search_position_ = iter - begin + 1;
bytes_to_read = 0;
}
// No match yet. Check if buffer is full.
else if (buffers_.size() == buffers_.max_size())
{
search_position_ = not_found;
bytes_to_read = 0;
}
// Need to read some more data.
else
{
// Next search can start with the new data.
search_position_ = end - begin;
bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(65536,
buffers_.max_size() - buffers_.size()));
}
}
// Check if we're done.
if (!start && bytes_to_read == 0)
break;
// Start a new asynchronous read operation to obtain more data.
{
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, "async_read_until"));
stream_.async_read_some(buffers_.prepare(bytes_to_read),
static_cast<read_until_delim_op_v1&&>(*this));
}
return; default:
buffers_.commit(bytes_transferred);
if (ec || bytes_transferred == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
const boost::system::error_code result_ec =
(search_position_ == not_found)
? error::not_found : ec;
const std::size_t result_n =
(ec || search_position_ == not_found)
? 0 : search_position_;
static_cast<ReadHandler&&>(handler_)(result_ec, result_n);
}
}
//private:
AsyncReadStream& stream_;
DynamicBuffer_v1 buffers_;
char delim_;
int start_;
std::size_t search_position_;
ReadHandler handler_;
};
template <typename AsyncReadStream,
typename DynamicBuffer_v1, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_until_delim_op_v1<AsyncReadStream,
DynamicBuffer_v1, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncReadStream>
class initiate_async_read_until_delim_v1
{
public:
typedef typename AsyncReadStream::executor_type executor_type;
explicit initiate_async_read_until_delim_v1(AsyncReadStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename ReadHandler, typename DynamicBuffer_v1>
void operator()(ReadHandler&& handler,
DynamicBuffer_v1&& buffers,
char delim) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
read_until_delim_op_v1<AsyncReadStream,
decay_t<DynamicBuffer_v1>,
decay_t<ReadHandler>>(
stream_, static_cast<DynamicBuffer_v1&&>(buffers),
delim, handler2.value)(boost::system::error_code(), 0, 1);
}
private:
AsyncReadStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncReadStream, typename DynamicBuffer_v1,
typename ReadHandler, typename DefaultCandidate>
struct associator<Associator,
detail::read_until_delim_op_v1<AsyncReadStream,
DynamicBuffer_v1, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_until_delim_op_v1<AsyncReadStream,
DynamicBuffer_v1, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_until_delim_op_v1<AsyncReadStream,
DynamicBuffer_v1, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncReadStream, typename DynamicBuffer_v1,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s,
DynamicBuffer_v1&& buffers, char delim, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_delim_v1<AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v1&&>(buffers), delim))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_delim_v1<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v1&&>(buffers), delim);
}
namespace detail
{
template <typename AsyncReadStream,
typename DynamicBuffer_v1, typename ReadHandler>
class read_until_delim_string_op_v1
: public base_from_cancellation_state<ReadHandler>
{
public:
template <typename BufferSequence>
read_until_delim_string_op_v1(AsyncReadStream& stream,
BufferSequence&& buffers,
const std::string& delim, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
delim_(delim),
start_(0),
search_position_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_until_delim_string_op_v1(const read_until_delim_string_op_v1& other)
: base_from_cancellation_state<ReadHandler>(other),
stream_(other.stream_),
buffers_(other.buffers_),
delim_(other.delim_),
start_(other.start_),
search_position_(other.search_position_),
handler_(other.handler_)
{
}
read_until_delim_string_op_v1(read_until_delim_string_op_v1&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v1&&>(other.buffers_)),
delim_(static_cast<std::string&&>(other.delim_)),
start_(other.start_),
search_position_(other.search_position_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
std::size_t bytes_to_read;
switch (start_ = start)
{
case 1:
for (;;)
{
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v1::const_buffers_type
buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers = buffers_.data();
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position_;
iterator end = iterator::end(data_buffers);
// Look for a match.
std::pair<iterator, bool> result = detail::partial_search(
start_pos, end, delim_.begin(), delim_.end());
if (result.first != end && result.second)
{
// Full match. We're done.
search_position_ = result.first - begin + delim_.length();
bytes_to_read = 0;
}
// No match yet. Check if buffer is full.
else if (buffers_.size() == buffers_.max_size())
{
search_position_ = not_found;
bytes_to_read = 0;
}
// Need to read some more data.
else
{
if (result.first != end)
{
// Partial match. Next search needs to start from beginning of
// match.
search_position_ = result.first - begin;
}
else
{
// Next search can start with the new data.
search_position_ = end - begin;
}
bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(65536,
buffers_.max_size() - buffers_.size()));
}
}
// Check if we're done.
if (!start && bytes_to_read == 0)
break;
// Start a new asynchronous read operation to obtain more data.
{
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, "async_read_until"));
stream_.async_read_some(buffers_.prepare(bytes_to_read),
static_cast<read_until_delim_string_op_v1&&>(*this));
}
return; default:
buffers_.commit(bytes_transferred);
if (ec || bytes_transferred == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
const boost::system::error_code result_ec =
(search_position_ == not_found)
? error::not_found : ec;
const std::size_t result_n =
(ec || search_position_ == not_found)
? 0 : search_position_;
static_cast<ReadHandler&&>(handler_)(result_ec, result_n);
}
}
//private:
AsyncReadStream& stream_;
DynamicBuffer_v1 buffers_;
std::string delim_;
int start_;
std::size_t search_position_;
ReadHandler handler_;
};
template <typename AsyncReadStream,
typename DynamicBuffer_v1, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_until_delim_string_op_v1<AsyncReadStream,
DynamicBuffer_v1, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncReadStream>
class initiate_async_read_until_delim_string_v1
{
public:
typedef typename AsyncReadStream::executor_type executor_type;
explicit initiate_async_read_until_delim_string_v1(AsyncReadStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename ReadHandler, typename DynamicBuffer_v1>
void operator()(ReadHandler&& handler,
DynamicBuffer_v1&& buffers,
const std::string& delim) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
read_until_delim_string_op_v1<AsyncReadStream,
decay_t<DynamicBuffer_v1>,
decay_t<ReadHandler>>(
stream_, static_cast<DynamicBuffer_v1&&>(buffers),
delim, handler2.value)(boost::system::error_code(), 0, 1);
}
private:
AsyncReadStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncReadStream, typename DynamicBuffer_v1,
typename ReadHandler, typename DefaultCandidate>
struct associator<Associator,
detail::read_until_delim_string_op_v1<AsyncReadStream,
DynamicBuffer_v1, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_until_delim_string_op_v1<
AsyncReadStream, DynamicBuffer_v1, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_until_delim_string_op_v1<
AsyncReadStream, DynamicBuffer_v1, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncReadStream, typename DynamicBuffer_v1,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s, DynamicBuffer_v1&& buffers,
BOOST_ASIO_STRING_VIEW_PARAM delim, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_delim_string_v1<
AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v1&&>(buffers),
static_cast<std::string>(delim)))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_delim_string_v1<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v1&&>(buffers),
static_cast<std::string>(delim));
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if defined(BOOST_ASIO_HAS_BOOST_REGEX)
namespace detail
{
template <typename AsyncReadStream, typename DynamicBuffer_v1,
typename RegEx, typename ReadHandler>
class read_until_expr_op_v1
: public base_from_cancellation_state<ReadHandler>
{
public:
template <typename BufferSequence, typename Traits>
read_until_expr_op_v1(AsyncReadStream& stream, BufferSequence&& buffers,
const boost::basic_regex<char, Traits>& expr, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
expr_(expr),
start_(0),
search_position_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_until_expr_op_v1(const read_until_expr_op_v1& other)
: base_from_cancellation_state<ReadHandler>(other),
stream_(other.stream_),
buffers_(other.buffers_),
expr_(other.expr_),
start_(other.start_),
search_position_(other.search_position_),
handler_(other.handler_)
{
}
read_until_expr_op_v1(read_until_expr_op_v1&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v1&&>(other.buffers_)),
expr_(other.expr_),
start_(other.start_),
search_position_(other.search_position_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
std::size_t bytes_to_read;
switch (start_ = start)
{
case 1:
for (;;)
{
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v1::const_buffers_type
buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers = buffers_.data();
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position_;
iterator end = iterator::end(data_buffers);
// Look for a match.
boost::match_results<iterator,
typename std::vector<boost::sub_match<iterator>>::allocator_type>
match_results;
bool match = regex_search(start_pos, end,
match_results, expr_, regex_match_flags());
if (match && match_results[0].matched)
{
// Full match. We're done.
search_position_ = match_results[0].second - begin;
bytes_to_read = 0;
}
// No match yet. Check if buffer is full.
else if (buffers_.size() == buffers_.max_size())
{
search_position_ = not_found;
bytes_to_read = 0;
}
// Need to read some more data.
else
{
if (match)
{
// Partial match. Next search needs to start from beginning of
// match.
search_position_ = match_results[0].first - begin;
}
else
{
// Next search can start with the new data.
search_position_ = end - begin;
}
bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(65536,
buffers_.max_size() - buffers_.size()));
}
}
// Check if we're done.
if (!start && bytes_to_read == 0)
break;
// Start a new asynchronous read operation to obtain more data.
{
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, "async_read_until"));
stream_.async_read_some(buffers_.prepare(bytes_to_read),
static_cast<read_until_expr_op_v1&&>(*this));
}
return; default:
buffers_.commit(bytes_transferred);
if (ec || bytes_transferred == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
const boost::system::error_code result_ec =
(search_position_ == not_found)
? error::not_found : ec;
const std::size_t result_n =
(ec || search_position_ == not_found)
? 0 : search_position_;
static_cast<ReadHandler&&>(handler_)(result_ec, result_n);
}
}
//private:
AsyncReadStream& stream_;
DynamicBuffer_v1 buffers_;
RegEx expr_;
int start_;
std::size_t search_position_;
ReadHandler handler_;
};
template <typename AsyncReadStream, typename DynamicBuffer_v1,
typename RegEx, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_until_expr_op_v1<AsyncReadStream,
DynamicBuffer_v1, RegEx, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncReadStream>
class initiate_async_read_until_expr_v1
{
public:
typedef typename AsyncReadStream::executor_type executor_type;
explicit initiate_async_read_until_expr_v1(AsyncReadStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename ReadHandler, typename DynamicBuffer_v1, typename RegEx>
void operator()(ReadHandler&& handler,
DynamicBuffer_v1&& buffers, const RegEx& expr) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
read_until_expr_op_v1<AsyncReadStream,
decay_t<DynamicBuffer_v1>,
RegEx, decay_t<ReadHandler>>(
stream_, static_cast<DynamicBuffer_v1&&>(buffers),
expr, handler2.value)(boost::system::error_code(), 0, 1);
}
private:
AsyncReadStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncReadStream, typename DynamicBuffer_v1,
typename RegEx, typename ReadHandler, typename DefaultCandidate>
struct associator<Associator,
detail::read_until_expr_op_v1<AsyncReadStream,
DynamicBuffer_v1, RegEx, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_until_expr_op_v1<AsyncReadStream,
DynamicBuffer_v1, RegEx, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_until_expr_op_v1<AsyncReadStream,
DynamicBuffer_v1, RegEx, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncReadStream, typename DynamicBuffer_v1, typename Traits,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s, DynamicBuffer_v1&& buffers,
const boost::basic_regex<char, Traits>& expr, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_expr_v1<AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v1&&>(buffers), expr))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_expr_v1<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v1&&>(buffers), expr);
}
#endif // defined(BOOST_ASIO_HAS_BOOST_REGEX)
namespace detail
{
template <typename AsyncReadStream, typename DynamicBuffer_v1,
typename MatchCondition, typename ReadHandler>
class read_until_match_op_v1
: public base_from_cancellation_state<ReadHandler>
{
public:
template <typename BufferSequence>
read_until_match_op_v1(AsyncReadStream& stream,
BufferSequence&& buffers,
MatchCondition match_condition, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
match_condition_(match_condition),
start_(0),
search_position_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_until_match_op_v1(const read_until_match_op_v1& other)
: base_from_cancellation_state<ReadHandler>(other),
stream_(other.stream_),
buffers_(other.buffers_),
match_condition_(other.match_condition_),
start_(other.start_),
search_position_(other.search_position_),
handler_(other.handler_)
{
}
read_until_match_op_v1(read_until_match_op_v1&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v1&&>(other.buffers_)),
match_condition_(other.match_condition_),
start_(other.start_),
search_position_(other.search_position_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
std::size_t bytes_to_read;
switch (start_ = start)
{
case 1:
for (;;)
{
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v1::const_buffers_type
buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers = buffers_.data();
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position_;
iterator end = iterator::end(data_buffers);
// Look for a match.
std::pair<iterator, bool> result = match_condition_(start_pos, end);
if (result.second)
{
// Full match. We're done.
search_position_ = result.first - begin;
bytes_to_read = 0;
}
// No match yet. Check if buffer is full.
else if (buffers_.size() == buffers_.max_size())
{
search_position_ = not_found;
bytes_to_read = 0;
}
// Need to read some more data.
else
{
if (result.first != end)
{
// Partial match. Next search needs to start from beginning of
// match.
search_position_ = result.first - begin;
}
else
{
// Next search can start with the new data.
search_position_ = end - begin;
}
bytes_to_read = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(65536,
buffers_.max_size() - buffers_.size()));
}
}
// Check if we're done.
if (!start && bytes_to_read == 0)
break;
// Start a new asynchronous read operation to obtain more data.
{
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, "async_read_until"));
stream_.async_read_some(buffers_.prepare(bytes_to_read),
static_cast<read_until_match_op_v1&&>(*this));
}
return; default:
buffers_.commit(bytes_transferred);
if (ec || bytes_transferred == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
const boost::system::error_code result_ec =
(search_position_ == not_found)
? error::not_found : ec;
const std::size_t result_n =
(ec || search_position_ == not_found)
? 0 : search_position_;
static_cast<ReadHandler&&>(handler_)(result_ec, result_n);
}
}
//private:
AsyncReadStream& stream_;
DynamicBuffer_v1 buffers_;
MatchCondition match_condition_;
int start_;
std::size_t search_position_;
ReadHandler handler_;
};
template <typename AsyncReadStream, typename DynamicBuffer_v1,
typename MatchCondition, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_until_match_op_v1<AsyncReadStream, DynamicBuffer_v1,
MatchCondition, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncReadStream>
class initiate_async_read_until_match_v1
{
public:
typedef typename AsyncReadStream::executor_type executor_type;
explicit initiate_async_read_until_match_v1(AsyncReadStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename ReadHandler,
typename DynamicBuffer_v1, typename MatchCondition>
void operator()(ReadHandler&& handler,
DynamicBuffer_v1&& buffers,
MatchCondition match_condition) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
read_until_match_op_v1<AsyncReadStream,
decay_t<DynamicBuffer_v1>,
MatchCondition, decay_t<ReadHandler>>(
stream_, static_cast<DynamicBuffer_v1&&>(buffers),
match_condition, handler2.value)(boost::system::error_code(), 0, 1);
}
private:
AsyncReadStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncReadStream, typename DynamicBuffer_v1,
typename MatchCondition, typename ReadHandler, typename DefaultCandidate>
struct associator<Associator,
detail::read_until_match_op_v1<AsyncReadStream,
DynamicBuffer_v1, MatchCondition, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_until_match_op_v1<AsyncReadStream,
DynamicBuffer_v1, MatchCondition, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_until_match_op_v1<AsyncReadStream,
DynamicBuffer_v1, MatchCondition, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncReadStream,
typename DynamicBuffer_v1, typename MatchCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s, DynamicBuffer_v1&& buffers,
MatchCondition match_condition, ReadToken&& token,
constraint_t<
is_match_condition<MatchCondition>::value
>,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_match_v1<AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v1&&>(buffers),
match_condition))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_match_v1<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v1&&>(buffers),
match_condition);
}
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename AsyncReadStream, typename Allocator,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b, char delim, ReadToken&& token)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_delim_v1<AsyncReadStream>>(),
token, basic_streambuf_ref<Allocator>(b), delim))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_delim_v1<AsyncReadStream>(s),
token, basic_streambuf_ref<Allocator>(b), delim);
}
template <typename AsyncReadStream, typename Allocator,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
BOOST_ASIO_STRING_VIEW_PARAM delim, ReadToken&& token)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_delim_string_v1<
AsyncReadStream>>(),
token, basic_streambuf_ref<Allocator>(b),
static_cast<std::string>(delim)))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_delim_string_v1<AsyncReadStream>(s),
token, basic_streambuf_ref<Allocator>(b),
static_cast<std::string>(delim));
}
#if defined(BOOST_ASIO_HAS_BOOST_REGEX)
template <typename AsyncReadStream, typename Allocator, typename Traits,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
const boost::basic_regex<char, Traits>& expr, ReadToken&& token)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_expr_v1<AsyncReadStream>>(),
token, basic_streambuf_ref<Allocator>(b), expr))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_expr_v1<AsyncReadStream>(s),
token, basic_streambuf_ref<Allocator>(b), expr);
}
#endif // defined(BOOST_ASIO_HAS_BOOST_REGEX)
template <typename AsyncReadStream, typename Allocator, typename MatchCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s,
boost::asio::basic_streambuf<Allocator>& b,
MatchCondition match_condition, ReadToken&& token,
constraint_t<is_match_condition<MatchCondition>::value>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_match_v1<AsyncReadStream>>(),
token, basic_streambuf_ref<Allocator>(b), match_condition))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_match_v1<AsyncReadStream>(s),
token, basic_streambuf_ref<Allocator>(b), match_condition);
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
#endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
namespace detail
{
template <typename AsyncReadStream,
typename DynamicBuffer_v2, typename ReadHandler>
class read_until_delim_op_v2
: public base_from_cancellation_state<ReadHandler>
{
public:
template <typename BufferSequence>
read_until_delim_op_v2(AsyncReadStream& stream,
BufferSequence&& buffers,
char delim, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
delim_(delim),
start_(0),
search_position_(0),
bytes_to_read_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_until_delim_op_v2(const read_until_delim_op_v2& other)
: base_from_cancellation_state<ReadHandler>(other),
stream_(other.stream_),
buffers_(other.buffers_),
delim_(other.delim_),
start_(other.start_),
search_position_(other.search_position_),
bytes_to_read_(other.bytes_to_read_),
handler_(other.handler_)
{
}
read_until_delim_op_v2(read_until_delim_op_v2&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v2&&>(other.buffers_)),
delim_(other.delim_),
start_(other.start_),
search_position_(other.search_position_),
bytes_to_read_(other.bytes_to_read_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
std::size_t pos;
switch (start_ = start)
{
case 1:
for (;;)
{
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v2::const_buffers_type
buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers =
const_cast<const DynamicBuffer_v2&>(buffers_).data(
0, buffers_.size());
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position_;
iterator end = iterator::end(data_buffers);
// Look for a match.
iterator iter = std::find(start_pos, end, delim_);
if (iter != end)
{
// Found a match. We're done.
search_position_ = iter - begin + 1;
bytes_to_read_ = 0;
}
// No match yet. Check if buffer is full.
else if (buffers_.size() == buffers_.max_size())
{
search_position_ = not_found;
bytes_to_read_ = 0;
}
// Need to read some more data.
else
{
// Next search can start with the new data.
search_position_ = end - begin;
bytes_to_read_ = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(65536,
buffers_.max_size() - buffers_.size()));
}
}
// Check if we're done.
if (!start && bytes_to_read_ == 0)
break;
// Start a new asynchronous read operation to obtain more data.
pos = buffers_.size();
buffers_.grow(bytes_to_read_);
{
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, "async_read_until"));
stream_.async_read_some(buffers_.data(pos, bytes_to_read_),
static_cast<read_until_delim_op_v2&&>(*this));
}
return; default:
buffers_.shrink(bytes_to_read_ - bytes_transferred);
if (ec || bytes_transferred == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
const boost::system::error_code result_ec =
(search_position_ == not_found)
? error::not_found : ec;
const std::size_t result_n =
(ec || search_position_ == not_found)
? 0 : search_position_;
static_cast<ReadHandler&&>(handler_)(result_ec, result_n);
}
}
//private:
AsyncReadStream& stream_;
DynamicBuffer_v2 buffers_;
char delim_;
int start_;
std::size_t search_position_;
std::size_t bytes_to_read_;
ReadHandler handler_;
};
template <typename AsyncReadStream,
typename DynamicBuffer_v2, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_until_delim_op_v2<AsyncReadStream,
DynamicBuffer_v2, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncReadStream>
class initiate_async_read_until_delim_v2
{
public:
typedef typename AsyncReadStream::executor_type executor_type;
explicit initiate_async_read_until_delim_v2(AsyncReadStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename ReadHandler, typename DynamicBuffer_v2>
void operator()(ReadHandler&& handler,
DynamicBuffer_v2&& buffers, char delim) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
read_until_delim_op_v2<AsyncReadStream,
decay_t<DynamicBuffer_v2>,
decay_t<ReadHandler>>(
stream_, static_cast<DynamicBuffer_v2&&>(buffers),
delim, handler2.value)(boost::system::error_code(), 0, 1);
}
private:
AsyncReadStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncReadStream, typename DynamicBuffer_v2,
typename ReadHandler, typename DefaultCandidate>
struct associator<Associator,
detail::read_until_delim_op_v2<AsyncReadStream,
DynamicBuffer_v2, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_until_delim_op_v2<AsyncReadStream,
DynamicBuffer_v2, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_until_delim_op_v2<AsyncReadStream,
DynamicBuffer_v2, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncReadStream, typename DynamicBuffer_v2,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s,
DynamicBuffer_v2 buffers, char delim, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_delim_v2<AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v2&&>(buffers), delim))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_delim_v2<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v2&&>(buffers), delim);
}
namespace detail
{
template <typename AsyncReadStream,
typename DynamicBuffer_v2, typename ReadHandler>
class read_until_delim_string_op_v2
: public base_from_cancellation_state<ReadHandler>
{
public:
template <typename BufferSequence>
read_until_delim_string_op_v2(AsyncReadStream& stream,
BufferSequence&& buffers,
const std::string& delim, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
delim_(delim),
start_(0),
search_position_(0),
bytes_to_read_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_until_delim_string_op_v2(const read_until_delim_string_op_v2& other)
: base_from_cancellation_state<ReadHandler>(other),
stream_(other.stream_),
buffers_(other.buffers_),
delim_(other.delim_),
start_(other.start_),
search_position_(other.search_position_),
bytes_to_read_(other.bytes_to_read_),
handler_(other.handler_)
{
}
read_until_delim_string_op_v2(read_until_delim_string_op_v2&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v2&&>(other.buffers_)),
delim_(static_cast<std::string&&>(other.delim_)),
start_(other.start_),
search_position_(other.search_position_),
bytes_to_read_(other.bytes_to_read_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
std::size_t pos;
switch (start_ = start)
{
case 1:
for (;;)
{
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v2::const_buffers_type
buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers =
const_cast<const DynamicBuffer_v2&>(buffers_).data(
0, buffers_.size());
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position_;
iterator end = iterator::end(data_buffers);
// Look for a match.
std::pair<iterator, bool> result = detail::partial_search(
start_pos, end, delim_.begin(), delim_.end());
if (result.first != end && result.second)
{
// Full match. We're done.
search_position_ = result.first - begin + delim_.length();
bytes_to_read_ = 0;
}
// No match yet. Check if buffer is full.
else if (buffers_.size() == buffers_.max_size())
{
search_position_ = not_found;
bytes_to_read_ = 0;
}
// Need to read some more data.
else
{
if (result.first != end)
{
// Partial match. Next search needs to start from beginning of
// match.
search_position_ = result.first - begin;
}
else
{
// Next search can start with the new data.
search_position_ = end - begin;
}
bytes_to_read_ = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(65536,
buffers_.max_size() - buffers_.size()));
}
}
// Check if we're done.
if (!start && bytes_to_read_ == 0)
break;
// Start a new asynchronous read operation to obtain more data.
pos = buffers_.size();
buffers_.grow(bytes_to_read_);
{
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, "async_read_until"));
stream_.async_read_some(buffers_.data(pos, bytes_to_read_),
static_cast<read_until_delim_string_op_v2&&>(*this));
}
return; default:
buffers_.shrink(bytes_to_read_ - bytes_transferred);
if (ec || bytes_transferred == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
const boost::system::error_code result_ec =
(search_position_ == not_found)
? error::not_found : ec;
const std::size_t result_n =
(ec || search_position_ == not_found)
? 0 : search_position_;
static_cast<ReadHandler&&>(handler_)(result_ec, result_n);
}
}
//private:
AsyncReadStream& stream_;
DynamicBuffer_v2 buffers_;
std::string delim_;
int start_;
std::size_t search_position_;
std::size_t bytes_to_read_;
ReadHandler handler_;
};
template <typename AsyncReadStream,
typename DynamicBuffer_v2, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_until_delim_string_op_v2<AsyncReadStream,
DynamicBuffer_v2, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncReadStream>
class initiate_async_read_until_delim_string_v2
{
public:
typedef typename AsyncReadStream::executor_type executor_type;
explicit initiate_async_read_until_delim_string_v2(AsyncReadStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename ReadHandler, typename DynamicBuffer_v2>
void operator()(ReadHandler&& handler,
DynamicBuffer_v2&& buffers,
const std::string& delim) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
read_until_delim_string_op_v2<AsyncReadStream,
decay_t<DynamicBuffer_v2>,
decay_t<ReadHandler>>(
stream_, static_cast<DynamicBuffer_v2&&>(buffers),
delim, handler2.value)(boost::system::error_code(), 0, 1);
}
private:
AsyncReadStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncReadStream, typename DynamicBuffer_v2,
typename ReadHandler, typename DefaultCandidate>
struct associator<Associator,
detail::read_until_delim_string_op_v2<AsyncReadStream,
DynamicBuffer_v2, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_until_delim_string_op_v2<
AsyncReadStream, DynamicBuffer_v2, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_until_delim_string_op_v2<
AsyncReadStream, DynamicBuffer_v2, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncReadStream,
typename DynamicBuffer_v2,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s, DynamicBuffer_v2 buffers,
BOOST_ASIO_STRING_VIEW_PARAM delim, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_delim_string_v2<
AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v2&&>(buffers),
static_cast<std::string>(delim)))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_delim_string_v2<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v2&&>(buffers),
static_cast<std::string>(delim));
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if defined(BOOST_ASIO_HAS_BOOST_REGEX)
namespace detail
{
template <typename AsyncReadStream, typename DynamicBuffer_v2,
typename RegEx, typename ReadHandler>
class read_until_expr_op_v2
: public base_from_cancellation_state<ReadHandler>
{
public:
template <typename BufferSequence, typename Traits>
read_until_expr_op_v2(AsyncReadStream& stream, BufferSequence&& buffers,
const boost::basic_regex<char, Traits>& expr, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
expr_(expr),
start_(0),
search_position_(0),
bytes_to_read_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_until_expr_op_v2(const read_until_expr_op_v2& other)
: base_from_cancellation_state<ReadHandler>(other),
stream_(other.stream_),
buffers_(other.buffers_),
expr_(other.expr_),
start_(other.start_),
search_position_(other.search_position_),
bytes_to_read_(other.bytes_to_read_),
handler_(other.handler_)
{
}
read_until_expr_op_v2(read_until_expr_op_v2&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v2&&>(other.buffers_)),
expr_(other.expr_),
start_(other.start_),
search_position_(other.search_position_),
bytes_to_read_(other.bytes_to_read_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
std::size_t pos;
switch (start_ = start)
{
case 1:
for (;;)
{
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v2::const_buffers_type
buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers =
const_cast<const DynamicBuffer_v2&>(buffers_).data(
0, buffers_.size());
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position_;
iterator end = iterator::end(data_buffers);
// Look for a match.
boost::match_results<iterator,
typename std::vector<boost::sub_match<iterator>>::allocator_type>
match_results;
bool match = regex_search(start_pos, end,
match_results, expr_, regex_match_flags());
if (match && match_results[0].matched)
{
// Full match. We're done.
search_position_ = match_results[0].second - begin;
bytes_to_read_ = 0;
}
// No match yet. Check if buffer is full.
else if (buffers_.size() == buffers_.max_size())
{
search_position_ = not_found;
bytes_to_read_ = 0;
}
// Need to read some more data.
else
{
if (match)
{
// Partial match. Next search needs to start from beginning of
// match.
search_position_ = match_results[0].first - begin;
}
else
{
// Next search can start with the new data.
search_position_ = end - begin;
}
bytes_to_read_ = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(65536,
buffers_.max_size() - buffers_.size()));
}
}
// Check if we're done.
if (!start && bytes_to_read_ == 0)
break;
// Start a new asynchronous read operation to obtain more data.
pos = buffers_.size();
buffers_.grow(bytes_to_read_);
{
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, "async_read_until"));
stream_.async_read_some(buffers_.data(pos, bytes_to_read_),
static_cast<read_until_expr_op_v2&&>(*this));
}
return; default:
buffers_.shrink(bytes_to_read_ - bytes_transferred);
if (ec || bytes_transferred == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
const boost::system::error_code result_ec =
(search_position_ == not_found)
? error::not_found : ec;
const std::size_t result_n =
(ec || search_position_ == not_found)
? 0 : search_position_;
static_cast<ReadHandler&&>(handler_)(result_ec, result_n);
}
}
//private:
AsyncReadStream& stream_;
DynamicBuffer_v2 buffers_;
RegEx expr_;
int start_;
std::size_t search_position_;
std::size_t bytes_to_read_;
ReadHandler handler_;
};
template <typename AsyncReadStream, typename DynamicBuffer_v2,
typename RegEx, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_until_expr_op_v2<AsyncReadStream,
DynamicBuffer_v2, RegEx, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncReadStream>
class initiate_async_read_until_expr_v2
{
public:
typedef typename AsyncReadStream::executor_type executor_type;
explicit initiate_async_read_until_expr_v2(AsyncReadStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename ReadHandler, typename DynamicBuffer_v2, typename RegEx>
void operator()(ReadHandler&& handler,
DynamicBuffer_v2&& buffers,
const RegEx& expr) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
read_until_expr_op_v2<AsyncReadStream,
decay_t<DynamicBuffer_v2>,
RegEx, decay_t<ReadHandler>>(
stream_, static_cast<DynamicBuffer_v2&&>(buffers),
expr, handler2.value)(boost::system::error_code(), 0, 1);
}
private:
AsyncReadStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncReadStream, typename DynamicBuffer_v2,
typename RegEx, typename ReadHandler, typename DefaultCandidate>
struct associator<Associator,
detail::read_until_expr_op_v2<AsyncReadStream,
DynamicBuffer_v2, RegEx, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_until_expr_op_v2<AsyncReadStream,
DynamicBuffer_v2, RegEx, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_until_expr_op_v2<AsyncReadStream,
DynamicBuffer_v2, RegEx, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncReadStream, typename DynamicBuffer_v2, typename Traits,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s, DynamicBuffer_v2 buffers,
const boost::basic_regex<char, Traits>& expr, ReadToken&& token,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_expr_v2<AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v2&&>(buffers), expr))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_expr_v2<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v2&&>(buffers), expr);
}
#endif // defined(BOOST_ASIO_HAS_BOOST_REGEX)
namespace detail
{
template <typename AsyncReadStream, typename DynamicBuffer_v2,
typename MatchCondition, typename ReadHandler>
class read_until_match_op_v2
: public base_from_cancellation_state<ReadHandler>
{
public:
template <typename BufferSequence>
read_until_match_op_v2(AsyncReadStream& stream,
BufferSequence&& buffers,
MatchCondition match_condition, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
match_condition_(match_condition),
start_(0),
search_position_(0),
bytes_to_read_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_until_match_op_v2(const read_until_match_op_v2& other)
: base_from_cancellation_state<ReadHandler>(other),
stream_(other.stream_),
buffers_(other.buffers_),
match_condition_(other.match_condition_),
start_(other.start_),
search_position_(other.search_position_),
bytes_to_read_(other.bytes_to_read_),
handler_(other.handler_)
{
}
read_until_match_op_v2(read_until_match_op_v2&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v2&&>(other.buffers_)),
match_condition_(other.match_condition_),
start_(other.start_),
search_position_(other.search_position_),
bytes_to_read_(other.bytes_to_read_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
std::size_t pos;
switch (start_ = start)
{
case 1:
for (;;)
{
{
// Determine the range of the data to be searched.
typedef typename DynamicBuffer_v2::const_buffers_type
buffers_type;
typedef buffers_iterator<buffers_type> iterator;
buffers_type data_buffers =
const_cast<const DynamicBuffer_v2&>(buffers_).data(
0, buffers_.size());
iterator begin = iterator::begin(data_buffers);
iterator start_pos = begin + search_position_;
iterator end = iterator::end(data_buffers);
// Look for a match.
std::pair<iterator, bool> result = match_condition_(start_pos, end);
if (result.second)
{
// Full match. We're done.
search_position_ = result.first - begin;
bytes_to_read_ = 0;
}
// No match yet. Check if buffer is full.
else if (buffers_.size() == buffers_.max_size())
{
search_position_ = not_found;
bytes_to_read_ = 0;
}
// Need to read some more data.
else
{
if (result.first != end)
{
// Partial match. Next search needs to start from beginning of
// match.
search_position_ = result.first - begin;
}
else
{
// Next search can start with the new data.
search_position_ = end - begin;
}
bytes_to_read_ = std::min<std::size_t>(
std::max<std::size_t>(512,
buffers_.capacity() - buffers_.size()),
std::min<std::size_t>(65536,
buffers_.max_size() - buffers_.size()));
}
}
// Check if we're done.
if (!start && bytes_to_read_ == 0)
break;
// Start a new asynchronous read operation to obtain more data.
pos = buffers_.size();
buffers_.grow(bytes_to_read_);
{
BOOST_ASIO_HANDLER_LOCATION((
__FILE__, __LINE__, "async_read_until"));
stream_.async_read_some(buffers_.data(pos, bytes_to_read_),
static_cast<read_until_match_op_v2&&>(*this));
}
return; default:
buffers_.shrink(bytes_to_read_ - bytes_transferred);
if (ec || bytes_transferred == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
const boost::system::error_code result_ec =
(search_position_ == not_found)
? error::not_found : ec;
const std::size_t result_n =
(ec || search_position_ == not_found)
? 0 : search_position_;
static_cast<ReadHandler&&>(handler_)(result_ec, result_n);
}
}
//private:
AsyncReadStream& stream_;
DynamicBuffer_v2 buffers_;
MatchCondition match_condition_;
int start_;
std::size_t search_position_;
std::size_t bytes_to_read_;
ReadHandler handler_;
};
template <typename AsyncReadStream, typename DynamicBuffer_v2,
typename MatchCondition, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_until_match_op_v2<AsyncReadStream, DynamicBuffer_v2,
MatchCondition, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncReadStream>
class initiate_async_read_until_match_v2
{
public:
typedef typename AsyncReadStream::executor_type executor_type;
explicit initiate_async_read_until_match_v2(AsyncReadStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename ReadHandler,
typename DynamicBuffer_v2, typename MatchCondition>
void operator()(ReadHandler&& handler,
DynamicBuffer_v2&& buffers,
MatchCondition match_condition) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
read_until_match_op_v2<AsyncReadStream, decay_t<DynamicBuffer_v2>,
MatchCondition, decay_t<ReadHandler>>(
stream_, static_cast<DynamicBuffer_v2&&>(buffers),
match_condition, handler2.value)(boost::system::error_code(), 0, 1);
}
private:
AsyncReadStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncReadStream, typename DynamicBuffer_v2,
typename MatchCondition, typename ReadHandler, typename DefaultCandidate>
struct associator<Associator,
detail::read_until_match_op_v2<AsyncReadStream,
DynamicBuffer_v2, MatchCondition, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_until_match_op_v2<AsyncReadStream,
DynamicBuffer_v2, MatchCondition, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_until_match_op_v2<AsyncReadStream,
DynamicBuffer_v2, MatchCondition, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncReadStream,
typename DynamicBuffer_v2, typename MatchCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_until(AsyncReadStream& s, DynamicBuffer_v2 buffers,
MatchCondition match_condition, ReadToken&& token,
constraint_t<
is_match_condition<MatchCondition>::value
>,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_until_match_v2<AsyncReadStream>>(),
token, static_cast<DynamicBuffer_v2&&>(buffers),
match_condition))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_until_match_v2<AsyncReadStream>(s),
token, static_cast<DynamicBuffer_v2&&>(buffers),
match_condition);
}
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_READ_UNTIL_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/deferred.hpp | //
// impl/deferred.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_DEFERRED_HPP
#define BOOST_ASIO_IMPL_DEFERRED_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if !defined(GENERATING_DOCUMENTATION)
template <typename Signature>
class async_result<deferred_t, Signature>
{
public:
template <typename Initiation, typename... InitArgs>
static deferred_async_operation<Signature, Initiation, InitArgs...>
initiate(Initiation&& initiation, deferred_t, InitArgs&&... args)
{
return deferred_async_operation<Signature, Initiation, InitArgs...>(
deferred_init_tag{},
static_cast<Initiation&&>(initiation),
static_cast<InitArgs&&>(args)...);
}
};
template <typename... Signatures>
class async_result<deferred_t, Signatures...>
{
public:
template <typename Initiation, typename... InitArgs>
static deferred_async_operation<
deferred_signatures<Signatures...>, Initiation, InitArgs...>
initiate(Initiation&& initiation, deferred_t, InitArgs&&... args)
{
return deferred_async_operation<
deferred_signatures<Signatures...>, Initiation, InitArgs...>(
deferred_init_tag{},
static_cast<Initiation&&>(initiation),
static_cast<InitArgs&&>(args)...);
}
};
template <typename Function, typename Signature>
class async_result<deferred_function<Function>, Signature>
{
public:
template <typename Initiation, typename... InitArgs>
static auto initiate(Initiation&& initiation,
deferred_function<Function> token, InitArgs&&... init_args)
-> decltype(
deferred_sequence<
deferred_async_operation<
Signature, Initiation, InitArgs...>,
Function>(deferred_init_tag{},
deferred_async_operation<
Signature, Initiation, InitArgs...>(
deferred_init_tag{},
static_cast<Initiation&&>(initiation),
static_cast<InitArgs&&>(init_args)...),
static_cast<Function&&>(token.function_)))
{
return deferred_sequence<
deferred_async_operation<
Signature, Initiation, InitArgs...>,
Function>(deferred_init_tag{},
deferred_async_operation<
Signature, Initiation, InitArgs...>(
deferred_init_tag{},
static_cast<Initiation&&>(initiation),
static_cast<InitArgs&&>(init_args)...),
static_cast<Function&&>(token.function_));
}
};
template <typename Function, typename... Signatures>
class async_result<deferred_function<Function>, Signatures...>
{
public:
template <typename Initiation, typename... InitArgs>
static auto initiate(Initiation&& initiation,
deferred_function<Function> token, InitArgs&&... init_args)
-> decltype(
deferred_sequence<
deferred_async_operation<
deferred_signatures<Signatures...>, Initiation, InitArgs...>,
Function>(deferred_init_tag{},
deferred_async_operation<
deferred_signatures<Signatures...>, Initiation, InitArgs...>(
deferred_init_tag{},
static_cast<Initiation&&>(initiation),
static_cast<InitArgs&&>(init_args)...),
static_cast<Function&&>(token.function_)))
{
return deferred_sequence<
deferred_async_operation<
deferred_signatures<Signatures...>, Initiation, InitArgs...>,
Function>(deferred_init_tag{},
deferred_async_operation<
deferred_signatures<Signatures...>, Initiation, InitArgs...>(
deferred_init_tag{},
static_cast<Initiation&&>(initiation),
static_cast<InitArgs&&>(init_args)...),
static_cast<Function&&>(token.function_));
}
};
template <template <typename, typename> class Associator,
typename Handler, typename Tail, typename DefaultCandidate>
struct associator<Associator,
detail::deferred_sequence_handler<Handler, Tail>,
DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::deferred_sequence_handler<Handler, Tail>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::deferred_sequence_handler<Handler, Tail>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_DEFERRED_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/executor.hpp | //
// impl/executor.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_EXECUTOR_HPP
#define BOOST_ASIO_IMPL_EXECUTOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
#include <new>
#include <boost/asio/detail/atomic_count.hpp>
#include <boost/asio/detail/global.hpp>
#include <boost/asio/detail/memory.hpp>
#include <boost/asio/executor.hpp>
#include <boost/asio/system_executor.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if !defined(GENERATING_DOCUMENTATION)
// Default polymorphic executor implementation.
template <typename Executor, typename Allocator>
class executor::impl
: public executor::impl_base
{
public:
typedef BOOST_ASIO_REBIND_ALLOC(Allocator, impl) allocator_type;
static impl_base* create(const Executor& e, Allocator a = Allocator())
{
raw_mem mem(a);
impl* p = new (mem.ptr_) impl(e, a);
mem.ptr_ = 0;
return p;
}
static impl_base* create(std::nothrow_t, const Executor& e) noexcept
{
return new (std::nothrow) impl(e, std::allocator<void>());
}
impl(const Executor& e, const Allocator& a) noexcept
: impl_base(false),
ref_count_(1),
executor_(e),
allocator_(a)
{
}
impl_base* clone() const noexcept
{
detail::ref_count_up(ref_count_);
return const_cast<impl_base*>(static_cast<const impl_base*>(this));
}
void destroy() noexcept
{
if (detail::ref_count_down(ref_count_))
{
allocator_type alloc(allocator_);
impl* p = this;
p->~impl();
alloc.deallocate(p, 1);
}
}
void on_work_started() noexcept
{
executor_.on_work_started();
}
void on_work_finished() noexcept
{
executor_.on_work_finished();
}
execution_context& context() noexcept
{
return executor_.context();
}
void dispatch(function&& f)
{
executor_.dispatch(static_cast<function&&>(f), allocator_);
}
void post(function&& f)
{
executor_.post(static_cast<function&&>(f), allocator_);
}
void defer(function&& f)
{
executor_.defer(static_cast<function&&>(f), allocator_);
}
type_id_result_type target_type() const noexcept
{
return type_id<Executor>();
}
void* target() noexcept
{
return &executor_;
}
const void* target() const noexcept
{
return &executor_;
}
bool equals(const impl_base* e) const noexcept
{
if (this == e)
return true;
if (target_type() != e->target_type())
return false;
return executor_ == *static_cast<const Executor*>(e->target());
}
private:
mutable detail::atomic_count ref_count_;
Executor executor_;
Allocator allocator_;
struct raw_mem
{
allocator_type allocator_;
impl* ptr_;
explicit raw_mem(const Allocator& a)
: allocator_(a),
ptr_(allocator_.allocate(1))
{
}
~raw_mem()
{
if (ptr_)
allocator_.deallocate(ptr_, 1);
}
private:
// Disallow copying and assignment.
raw_mem(const raw_mem&);
raw_mem operator=(const raw_mem&);
};
};
// Polymorphic executor specialisation for system_executor.
template <typename Allocator>
class executor::impl<system_executor, Allocator>
: public executor::impl_base
{
public:
static impl_base* create(const system_executor&,
const Allocator& = Allocator())
{
return &detail::global<impl<system_executor, std::allocator<void>> >();
}
static impl_base* create(std::nothrow_t, const system_executor&) noexcept
{
return &detail::global<impl<system_executor, std::allocator<void>> >();
}
impl()
: impl_base(true)
{
}
impl_base* clone() const noexcept
{
return const_cast<impl_base*>(static_cast<const impl_base*>(this));
}
void destroy() noexcept
{
}
void on_work_started() noexcept
{
executor_.on_work_started();
}
void on_work_finished() noexcept
{
executor_.on_work_finished();
}
execution_context& context() noexcept
{
return executor_.context();
}
void dispatch(function&& f)
{
executor_.dispatch(static_cast<function&&>(f),
std::allocator<void>());
}
void post(function&& f)
{
executor_.post(static_cast<function&&>(f),
std::allocator<void>());
}
void defer(function&& f)
{
executor_.defer(static_cast<function&&>(f),
std::allocator<void>());
}
type_id_result_type target_type() const noexcept
{
return type_id<system_executor>();
}
void* target() noexcept
{
return &executor_;
}
const void* target() const noexcept
{
return &executor_;
}
bool equals(const impl_base* e) const noexcept
{
return this == e;
}
private:
system_executor executor_;
};
template <typename Executor>
executor::executor(Executor e)
: impl_(impl<Executor, std::allocator<void>>::create(e))
{
}
template <typename Executor>
executor::executor(std::nothrow_t, Executor e) noexcept
: impl_(impl<Executor, std::allocator<void>>::create(std::nothrow, e))
{
}
template <typename Executor, typename Allocator>
executor::executor(allocator_arg_t, const Allocator& a, Executor e)
: impl_(impl<Executor, Allocator>::create(e, a))
{
}
template <typename Function, typename Allocator>
void executor::dispatch(Function&& f,
const Allocator& a) const
{
impl_base* i = get_impl();
if (i->fast_dispatch_)
system_executor().dispatch(static_cast<Function&&>(f), a);
else
i->dispatch(function(static_cast<Function&&>(f), a));
}
template <typename Function, typename Allocator>
void executor::post(Function&& f,
const Allocator& a) const
{
get_impl()->post(function(static_cast<Function&&>(f), a));
}
template <typename Function, typename Allocator>
void executor::defer(Function&& f,
const Allocator& a) const
{
get_impl()->defer(function(static_cast<Function&&>(f), a));
}
template <typename Executor>
Executor* executor::target() noexcept
{
return impl_ && impl_->target_type() == type_id<Executor>()
? static_cast<Executor*>(impl_->target()) : 0;
}
template <typename Executor>
const Executor* executor::target() const noexcept
{
return impl_ && impl_->target_type() == type_id<Executor>()
? static_cast<Executor*>(impl_->target()) : 0;
}
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
#endif // BOOST_ASIO_IMPL_EXECUTOR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/connect_pipe.hpp | //
// impl/connect_pipe.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_CONNECT_PIPE_HPP
#define BOOST_ASIO_IMPL_CONNECT_PIPE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HAS_PIPE)
#include <boost/asio/connect_pipe.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename Executor1, typename Executor2>
void connect_pipe(basic_readable_pipe<Executor1>& read_end,
basic_writable_pipe<Executor2>& write_end)
{
boost::system::error_code ec;
boost::asio::connect_pipe(read_end, write_end, ec);
boost::asio::detail::throw_error(ec, "connect_pipe");
}
template <typename Executor1, typename Executor2>
BOOST_ASIO_SYNC_OP_VOID connect_pipe(basic_readable_pipe<Executor1>& read_end,
basic_writable_pipe<Executor2>& write_end, boost::system::error_code& ec)
{
detail::native_pipe_handle p[2];
detail::create_pipe(p, ec);
if (ec)
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
read_end.assign(p[0], ec);
if (ec)
{
detail::close_pipe(p[0]);
detail::close_pipe(p[1]);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
write_end.assign(p[1], ec);
if (ec)
{
boost::system::error_code temp_ec;
read_end.close(temp_ec);
detail::close_pipe(p[1]);
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // defined(BOOST_ASIO_HAS_PIPE)
#endif // BOOST_ASIO_IMPL_CONNECT_PIPE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/detached.hpp | //
// impl/detached.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_DETACHED_HPP
#define BOOST_ASIO_IMPL_DETACHED_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
// Class to adapt a detached_t as a completion handler.
class detached_handler
{
public:
typedef void result_type;
detached_handler(detached_t)
{
}
template <typename... Args>
void operator()(Args...)
{
}
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <typename Signature>
struct async_result<detached_t, Signature>
{
typedef boost::asio::detail::detached_handler completion_handler_type;
typedef void return_type;
explicit async_result(completion_handler_type&)
{
}
void get()
{
}
template <typename Initiation, typename RawCompletionToken, typename... Args>
static return_type initiate(Initiation&& initiation,
RawCompletionToken&&, Args&&... args)
{
static_cast<Initiation&&>(initiation)(
detail::detached_handler(detached_t()),
static_cast<Args&&>(args)...);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_DETACHED_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/system_context.hpp | //
// impl/system_context.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_SYSTEM_CONTEXT_HPP
#define BOOST_ASIO_IMPL_SYSTEM_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/system_executor.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
inline system_context::executor_type
system_context::get_executor() noexcept
{
return system_executor();
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_SYSTEM_CONTEXT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/prepend.hpp | //
// impl/prepend.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_PREPEND_HPP
#define BOOST_ASIO_IMPL_PREPEND_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/associator.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/utility.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
// Class to adapt a prepend_t as a completion handler.
template <typename Handler, typename... Values>
class prepend_handler
{
public:
typedef void result_type;
template <typename H>
prepend_handler(H&& handler, std::tuple<Values...> values)
: handler_(static_cast<H&&>(handler)),
values_(static_cast<std::tuple<Values...>&&>(values))
{
}
template <typename... Args>
void operator()(Args&&... args)
{
this->invoke(
index_sequence_for<Values...>{},
static_cast<Args&&>(args)...);
}
template <std::size_t... I, typename... Args>
void invoke(index_sequence<I...>, Args&&... args)
{
static_cast<Handler&&>(handler_)(
static_cast<Values&&>(std::get<I>(values_))...,
static_cast<Args&&>(args)...);
}
//private:
Handler handler_;
std::tuple<Values...> values_;
};
template <typename Handler>
inline bool asio_handler_is_continuation(
prepend_handler<Handler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Signature, typename... Values>
struct prepend_signature;
template <typename R, typename... Args, typename... Values>
struct prepend_signature<R(Args...), Values...>
{
typedef R type(Values..., decay_t<Args>...);
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <typename CompletionToken, typename... Values, typename Signature>
struct async_result<
prepend_t<CompletionToken, Values...>, Signature>
: async_result<CompletionToken,
typename detail::prepend_signature<
Signature, Values...>::type>
{
typedef typename detail::prepend_signature<
Signature, Values...>::type signature;
template <typename Initiation>
struct init_wrapper
{
init_wrapper(Initiation init)
: initiation_(static_cast<Initiation&&>(init))
{
}
template <typename Handler, typename... Args>
void operator()(Handler&& handler,
std::tuple<Values...> values, Args&&... args)
{
static_cast<Initiation&&>(initiation_)(
detail::prepend_handler<decay_t<Handler>, Values...>(
static_cast<Handler&&>(handler),
static_cast<std::tuple<Values...>&&>(values)),
static_cast<Args&&>(args)...);
}
Initiation initiation_;
};
template <typename Initiation, typename RawCompletionToken, typename... Args>
static auto initiate(Initiation&& initiation,
RawCompletionToken&& token, Args&&... args)
-> decltype(
async_initiate<CompletionToken, signature>(
declval<init_wrapper<decay_t<Initiation>>>(),
token.token_,
static_cast<std::tuple<Values...>&&>(token.values_),
static_cast<Args&&>(args)...))
{
return async_initiate<CompletionToken, signature>(
init_wrapper<decay_t<Initiation>>(
static_cast<Initiation&&>(initiation)),
token.token_,
static_cast<std::tuple<Values...>&&>(token.values_),
static_cast<Args&&>(args)...);
}
};
template <template <typename, typename> class Associator,
typename Handler, typename... Values, typename DefaultCandidate>
struct associator<Associator,
detail::prepend_handler<Handler, Values...>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::prepend_handler<Handler, Values...>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::prepend_handler<Handler, Values...>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_PREPEND_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/write_at.hpp | //
// impl/write_at.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_WRITE_AT_HPP
#define BOOST_ASIO_IMPL_WRITE_AT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/associator.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/detail/array_fwd.hpp>
#include <boost/asio/detail/base_from_cancellation_state.hpp>
#include <boost/asio/detail/base_from_completion_cond.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/dependent_type.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_tracking.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail
{
template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename ConstBufferIterator, typename CompletionCondition>
std::size_t write_at_buffer_sequence(SyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
const ConstBufferIterator&, CompletionCondition completion_condition,
boost::system::error_code& ec)
{
ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<const_buffer,
ConstBufferSequence, ConstBufferIterator> tmp(buffers);
while (!tmp.empty())
{
if (std::size_t max_size = detail::adapt_completion_condition_result(
completion_condition(ec, tmp.total_consumed())))
{
tmp.consume(d.write_some_at(offset + tmp.total_consumed(),
tmp.prepare(max_size), ec));
}
else
break;
}
return tmp.total_consumed();
}
} // namespace detail
template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition>
std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
return detail::write_at_buffer_sequence(d, offset, buffers,
boost::asio::buffer_sequence_begin(buffers),
static_cast<CompletionCondition&&>(completion_condition), ec);
}
template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write_at(
d, offset, buffers, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "write_at");
return bytes_transferred;
}
template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
boost::system::error_code& ec)
{
return write_at(d, offset, buffers, transfer_all(), ec);
}
template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename CompletionCondition>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write_at(d, offset, buffers,
static_cast<CompletionCondition&&>(completion_condition), ec);
boost::asio::detail::throw_error(ec, "write_at");
return bytes_transferred;
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename SyncRandomAccessWriteDevice, typename Allocator,
typename CompletionCondition>
std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
std::size_t bytes_transferred = write_at(d, offset, b.data(),
static_cast<CompletionCondition&&>(completion_condition), ec);
b.consume(bytes_transferred);
return bytes_transferred;
}
template <typename SyncRandomAccessWriteDevice, typename Allocator>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write_at(d, offset, b, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "write_at");
return bytes_transferred;
}
template <typename SyncRandomAccessWriteDevice, typename Allocator>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
boost::system::error_code& ec)
{
return write_at(d, offset, b, transfer_all(), ec);
}
template <typename SyncRandomAccessWriteDevice, typename Allocator,
typename CompletionCondition>
inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write_at(d, offset, b,
static_cast<CompletionCondition&&>(completion_condition), ec);
boost::asio::detail::throw_error(ec, "write_at");
return bytes_transferred;
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
namespace detail
{
template <typename AsyncRandomAccessWriteDevice,
typename ConstBufferSequence, typename ConstBufferIterator,
typename CompletionCondition, typename WriteHandler>
class write_at_op
: public base_from_cancellation_state<WriteHandler>,
base_from_completion_cond<CompletionCondition>
{
public:
write_at_op(AsyncRandomAccessWriteDevice& device,
uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition& completion_condition, WriteHandler& handler)
: base_from_cancellation_state<WriteHandler>(
handler, enable_partial_cancellation()),
base_from_completion_cond<CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
buffers_(buffers),
start_(0),
handler_(static_cast<WriteHandler&&>(handler))
{
}
write_at_op(const write_at_op& other)
: base_from_cancellation_state<WriteHandler>(other),
base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
handler_(other.handler_)
{
}
write_at_op(write_at_op&& other)
: base_from_cancellation_state<WriteHandler>(
static_cast<base_from_cancellation_state<WriteHandler>&&>(other)),
base_from_completion_cond<CompletionCondition>(
static_cast<base_from_completion_cond<CompletionCondition>&&>(other)),
device_(other.device_),
offset_(other.offset_),
buffers_(static_cast<buffers_type&&>(other.buffers_)),
start_(other.start_),
handler_(static_cast<WriteHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t max_size;
switch (start_ = start)
{
case 1:
max_size = this->check_for_completion(ec, buffers_.total_consumed());
for (;;)
{
{
BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_write_at"));
device_.async_write_some_at(
offset_ + buffers_.total_consumed(), buffers_.prepare(max_size),
static_cast<write_at_op&&>(*this));
}
return; default:
buffers_.consume(bytes_transferred);
if ((!ec && bytes_transferred == 0) || buffers_.empty())
break;
max_size = this->check_for_completion(ec, buffers_.total_consumed());
if (max_size == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = boost::asio::error::operation_aborted;
break;
}
}
static_cast<WriteHandler&&>(handler_)(
static_cast<const boost::system::error_code&>(ec),
static_cast<const std::size_t&>(buffers_.total_consumed()));
}
}
//private:
typedef boost::asio::detail::consuming_buffers<const_buffer,
ConstBufferSequence, ConstBufferIterator> buffers_type;
AsyncRandomAccessWriteDevice& device_;
uint64_t offset_;
buffers_type buffers_;
int start_;
WriteHandler handler_;
};
template <typename AsyncRandomAccessWriteDevice,
typename ConstBufferSequence, typename ConstBufferIterator,
typename CompletionCondition, typename WriteHandler>
inline bool asio_handler_is_continuation(
write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
ConstBufferIterator, CompletionCondition, WriteHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncRandomAccessWriteDevice,
typename ConstBufferSequence, typename ConstBufferIterator,
typename CompletionCondition, typename WriteHandler>
inline void start_write_at_op(AsyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
const ConstBufferIterator&, CompletionCondition& completion_condition,
WriteHandler& handler)
{
detail::write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
ConstBufferIterator, CompletionCondition, WriteHandler>(
d, offset, buffers, completion_condition, handler)(
boost::system::error_code(), 0, 1);
}
template <typename AsyncRandomAccessWriteDevice>
class initiate_async_write_at
{
public:
typedef typename AsyncRandomAccessWriteDevice::executor_type executor_type;
explicit initiate_async_write_at(AsyncRandomAccessWriteDevice& device)
: device_(device)
{
}
executor_type get_executor() const noexcept
{
return device_.get_executor();
}
template <typename WriteHandler, typename ConstBufferSequence,
typename CompletionCondition>
void operator()(WriteHandler&& handler,
uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition&& completion_cond) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
non_const_lvalue<WriteHandler> handler2(handler);
non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
start_write_at_op(device_, offset, buffers,
boost::asio::buffer_sequence_begin(buffers),
completion_cond2.value, handler2.value);
}
private:
AsyncRandomAccessWriteDevice& device_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
typename ConstBufferIterator, typename CompletionCondition,
typename WriteHandler, typename DefaultCandidate>
struct associator<Associator,
detail::write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
ConstBufferIterator, CompletionCondition, WriteHandler>,
DefaultCandidate>
: Associator<WriteHandler, DefaultCandidate>
{
static typename Associator<WriteHandler, DefaultCandidate>::type get(
const detail::write_at_op<AsyncRandomAccessWriteDevice,
ConstBufferSequence, ConstBufferIterator,
CompletionCondition, WriteHandler>& h) noexcept
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::write_at_op<AsyncRandomAccessWriteDevice,
ConstBufferSequence, ConstBufferIterator,
CompletionCondition, WriteHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncRandomAccessWriteDevice,
typename ConstBufferSequence, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, WriteToken&& token)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write_at<
AsyncRandomAccessWriteDevice>>(),
token, offset, buffers,
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_at<AsyncRandomAccessWriteDevice>(d),
token, offset, buffers,
static_cast<CompletionCondition&&>(completion_condition));
}
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers, WriteToken&& token)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write_at<
AsyncRandomAccessWriteDevice>>(),
token, offset, buffers, transfer_all()))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_at<AsyncRandomAccessWriteDevice>(d),
token, offset, buffers, transfer_all());
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
namespace detail
{
template <typename Allocator, typename WriteHandler>
class write_at_streambuf_op
{
public:
write_at_streambuf_op(
boost::asio::basic_streambuf<Allocator>& streambuf,
WriteHandler& handler)
: streambuf_(streambuf),
handler_(static_cast<WriteHandler&&>(handler))
{
}
write_at_streambuf_op(const write_at_streambuf_op& other)
: streambuf_(other.streambuf_),
handler_(other.handler_)
{
}
write_at_streambuf_op(write_at_streambuf_op&& other)
: streambuf_(other.streambuf_),
handler_(static_cast<WriteHandler&&>(other.handler_))
{
}
void operator()(const boost::system::error_code& ec,
const std::size_t bytes_transferred)
{
streambuf_.consume(bytes_transferred);
static_cast<WriteHandler&&>(handler_)(ec, bytes_transferred);
}
//private:
boost::asio::basic_streambuf<Allocator>& streambuf_;
WriteHandler handler_;
};
template <typename Allocator, typename WriteHandler>
inline bool asio_handler_is_continuation(
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncRandomAccessWriteDevice>
class initiate_async_write_at_streambuf
{
public:
typedef typename AsyncRandomAccessWriteDevice::executor_type executor_type;
explicit initiate_async_write_at_streambuf(
AsyncRandomAccessWriteDevice& device)
: device_(device)
{
}
executor_type get_executor() const noexcept
{
return device_.get_executor();
}
template <typename WriteHandler,
typename Allocator, typename CompletionCondition>
void operator()(WriteHandler&& handler,
uint64_t offset, basic_streambuf<Allocator>* b,
CompletionCondition&& completion_condition) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
non_const_lvalue<WriteHandler> handler2(handler);
async_write_at(device_, offset, b->data(),
static_cast<CompletionCondition&&>(completion_condition),
write_at_streambuf_op<Allocator, decay_t<WriteHandler>>(
*b, handler2.value));
}
private:
AsyncRandomAccessWriteDevice& device_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename Executor, typename WriteHandler, typename DefaultCandidate>
struct associator<Associator,
detail::write_at_streambuf_op<Executor, WriteHandler>,
DefaultCandidate>
: Associator<WriteHandler, DefaultCandidate>
{
static typename Associator<WriteHandler, DefaultCandidate>::type get(
const detail::write_at_streambuf_op<Executor, WriteHandler>& h) noexcept
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::write_at_streambuf_op<Executor, WriteHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncRandomAccessWriteDevice,
typename Allocator, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, WriteToken&& token)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write_at_streambuf<
AsyncRandomAccessWriteDevice>>(),
token, offset, &b,
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_at_streambuf<
AsyncRandomAccessWriteDevice>(d),
token, offset, &b,
static_cast<CompletionCondition&&>(completion_condition));
}
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
WriteToken&& token)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write_at_streambuf<
AsyncRandomAccessWriteDevice>>(),
token, offset, &b, transfer_all()))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_at_streambuf<
AsyncRandomAccessWriteDevice>(d),
token, offset, &b, transfer_all());
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_WRITE_AT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/as_tuple.hpp | //
// impl/as_tuple.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_AS_TUPLE_HPP
#define BOOST_ASIO_IMPL_AS_TUPLE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <tuple>
#include <boost/asio/associator.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
// Class to adapt a as_tuple_t as a completion handler.
template <typename Handler>
class as_tuple_handler
{
public:
typedef void result_type;
template <typename CompletionToken>
as_tuple_handler(as_tuple_t<CompletionToken> e)
: handler_(static_cast<CompletionToken&&>(e.token_))
{
}
template <typename RedirectedHandler>
as_tuple_handler(RedirectedHandler&& h)
: handler_(static_cast<RedirectedHandler&&>(h))
{
}
template <typename... Args>
void operator()(Args&&... args)
{
static_cast<Handler&&>(handler_)(
std::make_tuple(static_cast<Args&&>(args)...));
}
//private:
Handler handler_;
};
template <typename Handler>
inline bool asio_handler_is_continuation(
as_tuple_handler<Handler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Signature>
struct as_tuple_signature;
template <typename R, typename... Args>
struct as_tuple_signature<R(Args...)>
{
typedef R type(std::tuple<decay_t<Args>...>);
};
template <typename R, typename... Args>
struct as_tuple_signature<R(Args...) &>
{
typedef R type(std::tuple<decay_t<Args>...>) &;
};
template <typename R, typename... Args>
struct as_tuple_signature<R(Args...) &&>
{
typedef R type(std::tuple<decay_t<Args>...>) &&;
};
#if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
template <typename R, typename... Args>
struct as_tuple_signature<R(Args...) noexcept>
{
typedef R type(std::tuple<decay_t<Args>...>) noexcept;
};
template <typename R, typename... Args>
struct as_tuple_signature<R(Args...) & noexcept>
{
typedef R type(std::tuple<decay_t<Args>...>) & noexcept;
};
template <typename R, typename... Args>
struct as_tuple_signature<R(Args...) && noexcept>
{
typedef R type(std::tuple<decay_t<Args>...>) && noexcept;
};
#endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <typename CompletionToken, typename... Signatures>
struct async_result<as_tuple_t<CompletionToken>, Signatures...>
: async_result<CompletionToken,
typename detail::as_tuple_signature<Signatures>::type...>
{
template <typename Initiation>
struct init_wrapper
{
init_wrapper(Initiation init)
: initiation_(static_cast<Initiation&&>(init))
{
}
template <typename Handler, typename... Args>
void operator()(Handler&& handler, Args&&... args)
{
static_cast<Initiation&&>(initiation_)(
detail::as_tuple_handler<decay_t<Handler>>(
static_cast<Handler&&>(handler)),
static_cast<Args&&>(args)...);
}
Initiation initiation_;
};
template <typename Initiation, typename RawCompletionToken, typename... Args>
static auto initiate(Initiation&& initiation,
RawCompletionToken&& token, Args&&... args)
-> decltype(
async_initiate<
conditional_t<
is_const<remove_reference_t<RawCompletionToken>>::value,
const CompletionToken, CompletionToken>,
typename detail::as_tuple_signature<Signatures>::type...>(
init_wrapper<decay_t<Initiation>>(
static_cast<Initiation&&>(initiation)),
token.token_, static_cast<Args&&>(args)...))
{
return async_initiate<
conditional_t<
is_const<remove_reference_t<RawCompletionToken>>::value,
const CompletionToken, CompletionToken>,
typename detail::as_tuple_signature<Signatures>::type...>(
init_wrapper<decay_t<Initiation>>(
static_cast<Initiation&&>(initiation)),
token.token_, static_cast<Args&&>(args)...);
}
};
#if defined(BOOST_ASIO_MSVC)
// Workaround for MSVC internal compiler error.
template <typename CompletionToken, typename Signature>
struct async_result<as_tuple_t<CompletionToken>, Signature>
: async_result<CompletionToken,
typename detail::as_tuple_signature<Signature>::type>
{
template <typename Initiation>
struct init_wrapper
{
init_wrapper(Initiation init)
: initiation_(static_cast<Initiation&&>(init))
{
}
template <typename Handler, typename... Args>
void operator()(Handler&& handler, Args&&... args)
{
static_cast<Initiation&&>(initiation_)(
detail::as_tuple_handler<decay_t<Handler>>(
static_cast<Handler&&>(handler)),
static_cast<Args&&>(args)...);
}
Initiation initiation_;
};
template <typename Initiation, typename RawCompletionToken, typename... Args>
static auto initiate(Initiation&& initiation,
RawCompletionToken&& token, Args&&... args)
-> decltype(
async_initiate<
conditional_t<
is_const<remove_reference_t<RawCompletionToken>>::value,
const CompletionToken, CompletionToken>,
typename detail::as_tuple_signature<Signature>::type>(
init_wrapper<decay_t<Initiation>>(
static_cast<Initiation&&>(initiation)),
token.token_, static_cast<Args&&>(args)...))
{
return async_initiate<
conditional_t<
is_const<remove_reference_t<RawCompletionToken>>::value,
const CompletionToken, CompletionToken>,
typename detail::as_tuple_signature<Signature>::type>(
init_wrapper<decay_t<Initiation>>(
static_cast<Initiation&&>(initiation)),
token.token_, static_cast<Args&&>(args)...);
}
};
#endif // defined(BOOST_ASIO_MSVC)
template <template <typename, typename> class Associator,
typename Handler, typename DefaultCandidate>
struct associator<Associator,
detail::as_tuple_handler<Handler>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::as_tuple_handler<Handler>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::as_tuple_handler<Handler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_AS_TUPLE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/write.hpp | //
// impl/write.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_WRITE_HPP
#define BOOST_ASIO_IMPL_WRITE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/associator.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/detail/array_fwd.hpp>
#include <boost/asio/detail/base_from_cancellation_state.hpp>
#include <boost/asio/detail/base_from_completion_cond.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/dependent_type.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_tracking.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail
{
template <typename SyncWriteStream, typename ConstBufferSequence,
typename ConstBufferIterator, typename CompletionCondition>
std::size_t write(SyncWriteStream& s,
const ConstBufferSequence& buffers, const ConstBufferIterator&,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<const_buffer,
ConstBufferSequence, ConstBufferIterator> tmp(buffers);
while (!tmp.empty())
{
if (std::size_t max_size = detail::adapt_completion_condition_result(
completion_condition(ec, tmp.total_consumed())))
tmp.consume(s.write_some(tmp.prepare(max_size), ec));
else
break;
}
return tmp.total_consumed();
}
} // namespace detail
template <typename SyncWriteStream, typename ConstBufferSequence,
typename CompletionCondition>
inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec,
constraint_t<
is_const_buffer_sequence<ConstBufferSequence>::value
>)
{
return detail::write(s, buffers,
boost::asio::buffer_sequence_begin(buffers),
static_cast<CompletionCondition&&>(completion_condition), ec);
}
template <typename SyncWriteStream, typename ConstBufferSequence>
inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
constraint_t<
is_const_buffer_sequence<ConstBufferSequence>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write(s, buffers, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "write");
return bytes_transferred;
}
template <typename SyncWriteStream, typename ConstBufferSequence>
inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
boost::system::error_code& ec,
constraint_t<
is_const_buffer_sequence<ConstBufferSequence>::value
>)
{
return write(s, buffers, transfer_all(), ec);
}
template <typename SyncWriteStream, typename ConstBufferSequence,
typename CompletionCondition>
inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
CompletionCondition completion_condition,
constraint_t<
is_const_buffer_sequence<ConstBufferSequence>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write(s, buffers,
static_cast<CompletionCondition&&>(completion_condition), ec);
boost::asio::detail::throw_error(ec, "write");
return bytes_transferred;
}
#if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
template <typename SyncWriteStream, typename DynamicBuffer_v1,
typename CompletionCondition>
std::size_t write(SyncWriteStream& s,
DynamicBuffer_v1&& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
decay_t<DynamicBuffer_v1> b(
static_cast<DynamicBuffer_v1&&>(buffers));
std::size_t bytes_transferred = write(s, b.data(),
static_cast<CompletionCondition&&>(completion_condition), ec);
b.consume(bytes_transferred);
return bytes_transferred;
}
template <typename SyncWriteStream, typename DynamicBuffer_v1>
inline std::size_t write(SyncWriteStream& s,
DynamicBuffer_v1&& buffers,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write(s,
static_cast<DynamicBuffer_v1&&>(buffers),
transfer_all(), ec);
boost::asio::detail::throw_error(ec, "write");
return bytes_transferred;
}
template <typename SyncWriteStream, typename DynamicBuffer_v1>
inline std::size_t write(SyncWriteStream& s,
DynamicBuffer_v1&& buffers,
boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
return write(s, static_cast<DynamicBuffer_v1&&>(buffers),
transfer_all(), ec);
}
template <typename SyncWriteStream, typename DynamicBuffer_v1,
typename CompletionCondition>
inline std::size_t write(SyncWriteStream& s,
DynamicBuffer_v1&& buffers,
CompletionCondition completion_condition,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write(s,
static_cast<DynamicBuffer_v1&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition), ec);
boost::asio::detail::throw_error(ec, "write");
return bytes_transferred;
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename SyncWriteStream, typename Allocator,
typename CompletionCondition>
inline std::size_t write(SyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
return write(s, basic_streambuf_ref<Allocator>(b),
static_cast<CompletionCondition&&>(completion_condition), ec);
}
template <typename SyncWriteStream, typename Allocator>
inline std::size_t write(SyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b)
{
return write(s, basic_streambuf_ref<Allocator>(b));
}
template <typename SyncWriteStream, typename Allocator>
inline std::size_t write(SyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b,
boost::system::error_code& ec)
{
return write(s, basic_streambuf_ref<Allocator>(b), ec);
}
template <typename SyncWriteStream, typename Allocator,
typename CompletionCondition>
inline std::size_t write(SyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition)
{
return write(s, basic_streambuf_ref<Allocator>(b),
static_cast<CompletionCondition&&>(completion_condition));
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
#endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
template <typename SyncWriteStream, typename DynamicBuffer_v2,
typename CompletionCondition>
std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
CompletionCondition completion_condition, boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
std::size_t bytes_transferred = write(s, buffers.data(0, buffers.size()),
static_cast<CompletionCondition&&>(completion_condition), ec);
buffers.consume(bytes_transferred);
return bytes_transferred;
}
template <typename SyncWriteStream, typename DynamicBuffer_v2>
inline std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write(s,
static_cast<DynamicBuffer_v2&&>(buffers),
transfer_all(), ec);
boost::asio::detail::throw_error(ec, "write");
return bytes_transferred;
}
template <typename SyncWriteStream, typename DynamicBuffer_v2>
inline std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
boost::system::error_code& ec,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
return write(s, static_cast<DynamicBuffer_v2&&>(buffers),
transfer_all(), ec);
}
template <typename SyncWriteStream, typename DynamicBuffer_v2,
typename CompletionCondition>
inline std::size_t write(SyncWriteStream& s, DynamicBuffer_v2 buffers,
CompletionCondition completion_condition,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
{
boost::system::error_code ec;
std::size_t bytes_transferred = write(s,
static_cast<DynamicBuffer_v2&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition), ec);
boost::asio::detail::throw_error(ec, "write");
return bytes_transferred;
}
namespace detail
{
template <typename AsyncWriteStream, typename ConstBufferSequence,
typename ConstBufferIterator, typename CompletionCondition,
typename WriteHandler>
class write_op
: public base_from_cancellation_state<WriteHandler>,
base_from_completion_cond<CompletionCondition>
{
public:
write_op(AsyncWriteStream& stream, const ConstBufferSequence& buffers,
CompletionCondition& completion_condition, WriteHandler& handler)
: base_from_cancellation_state<WriteHandler>(
handler, enable_partial_cancellation()),
base_from_completion_cond<CompletionCondition>(completion_condition),
stream_(stream),
buffers_(buffers),
start_(0),
handler_(static_cast<WriteHandler&&>(handler))
{
}
write_op(const write_op& other)
: base_from_cancellation_state<WriteHandler>(other),
base_from_completion_cond<CompletionCondition>(other),
stream_(other.stream_),
buffers_(other.buffers_),
start_(other.start_),
handler_(other.handler_)
{
}
write_op(write_op&& other)
: base_from_cancellation_state<WriteHandler>(
static_cast<base_from_cancellation_state<WriteHandler>&&>(other)),
base_from_completion_cond<CompletionCondition>(
static_cast<base_from_completion_cond<CompletionCondition>&&>(other)),
stream_(other.stream_),
buffers_(static_cast<buffers_type&&>(other.buffers_)),
start_(other.start_),
handler_(static_cast<WriteHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t max_size;
switch (start_ = start)
{
case 1:
max_size = this->check_for_completion(ec, buffers_.total_consumed());
for (;;)
{
{
BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_write"));
stream_.async_write_some(buffers_.prepare(max_size),
static_cast<write_op&&>(*this));
}
return; default:
buffers_.consume(bytes_transferred);
if ((!ec && bytes_transferred == 0) || buffers_.empty())
break;
max_size = this->check_for_completion(ec, buffers_.total_consumed());
if (max_size == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = error::operation_aborted;
break;
}
}
static_cast<WriteHandler&&>(handler_)(
static_cast<const boost::system::error_code&>(ec),
static_cast<const std::size_t&>(buffers_.total_consumed()));
}
}
//private:
typedef boost::asio::detail::consuming_buffers<const_buffer,
ConstBufferSequence, ConstBufferIterator> buffers_type;
AsyncWriteStream& stream_;
buffers_type buffers_;
int start_;
WriteHandler handler_;
};
template <typename AsyncWriteStream, typename ConstBufferSequence,
typename ConstBufferIterator, typename CompletionCondition,
typename WriteHandler>
inline bool asio_handler_is_continuation(
write_op<AsyncWriteStream, ConstBufferSequence, ConstBufferIterator,
CompletionCondition, WriteHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncWriteStream, typename ConstBufferSequence,
typename ConstBufferIterator, typename CompletionCondition,
typename WriteHandler>
inline void start_write_op(AsyncWriteStream& stream,
const ConstBufferSequence& buffers, const ConstBufferIterator&,
CompletionCondition& completion_condition, WriteHandler& handler)
{
detail::write_op<AsyncWriteStream, ConstBufferSequence,
ConstBufferIterator, CompletionCondition, WriteHandler>(
stream, buffers, completion_condition, handler)(
boost::system::error_code(), 0, 1);
}
template <typename AsyncWriteStream>
class initiate_async_write
{
public:
typedef typename AsyncWriteStream::executor_type executor_type;
explicit initiate_async_write(AsyncWriteStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename WriteHandler, typename ConstBufferSequence,
typename CompletionCondition>
void operator()(WriteHandler&& handler,
const ConstBufferSequence& buffers,
CompletionCondition&& completion_cond) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
non_const_lvalue<WriteHandler> handler2(handler);
non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
start_write_op(stream_, buffers,
boost::asio::buffer_sequence_begin(buffers),
completion_cond2.value, handler2.value);
}
private:
AsyncWriteStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncWriteStream, typename ConstBufferSequence,
typename ConstBufferIterator, typename CompletionCondition,
typename WriteHandler, typename DefaultCandidate>
struct associator<Associator,
detail::write_op<AsyncWriteStream, ConstBufferSequence,
ConstBufferIterator, CompletionCondition, WriteHandler>,
DefaultCandidate>
: Associator<WriteHandler, DefaultCandidate>
{
static typename Associator<WriteHandler, DefaultCandidate>::type get(
const detail::write_op<AsyncWriteStream, ConstBufferSequence,
ConstBufferIterator, CompletionCondition, WriteHandler>& h) noexcept
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::write_op<AsyncWriteStream, ConstBufferSequence,
ConstBufferIterator, CompletionCondition, WriteHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncWriteStream,
typename ConstBufferSequence, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
CompletionCondition completion_condition, WriteToken&& token,
constraint_t<
is_const_buffer_sequence<ConstBufferSequence>::value
>)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write<AsyncWriteStream>>(),
token, buffers,
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write<AsyncWriteStream>(s),
token, buffers,
static_cast<CompletionCondition&&>(completion_condition));
}
template <typename AsyncWriteStream, typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write(AsyncWriteStream& s,
const ConstBufferSequence& buffers, WriteToken&& token,
constraint_t<
is_const_buffer_sequence<ConstBufferSequence>::value
>)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write<AsyncWriteStream>>(),
token, buffers, transfer_all()))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write<AsyncWriteStream>(s),
token, buffers, transfer_all());
}
#if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
namespace detail
{
template <typename AsyncWriteStream, typename DynamicBuffer_v1,
typename CompletionCondition, typename WriteHandler>
class write_dynbuf_v1_op
{
public:
template <typename BufferSequence>
write_dynbuf_v1_op(AsyncWriteStream& stream,
BufferSequence&& buffers,
CompletionCondition& completion_condition, WriteHandler& handler)
: stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
completion_condition_(
static_cast<CompletionCondition&&>(completion_condition)),
handler_(static_cast<WriteHandler&&>(handler))
{
}
write_dynbuf_v1_op(const write_dynbuf_v1_op& other)
: stream_(other.stream_),
buffers_(other.buffers_),
completion_condition_(other.completion_condition_),
handler_(other.handler_)
{
}
write_dynbuf_v1_op(write_dynbuf_v1_op&& other)
: stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v1&&>(other.buffers_)),
completion_condition_(
static_cast<CompletionCondition&&>(
other.completion_condition_)),
handler_(static_cast<WriteHandler&&>(other.handler_))
{
}
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
switch (start)
{
case 1:
async_write(stream_, buffers_.data(),
static_cast<CompletionCondition&&>(completion_condition_),
static_cast<write_dynbuf_v1_op&&>(*this));
return; default:
buffers_.consume(bytes_transferred);
static_cast<WriteHandler&&>(handler_)(ec,
static_cast<const std::size_t&>(bytes_transferred));
}
}
//private:
AsyncWriteStream& stream_;
DynamicBuffer_v1 buffers_;
CompletionCondition completion_condition_;
WriteHandler handler_;
};
template <typename AsyncWriteStream, typename DynamicBuffer_v1,
typename CompletionCondition, typename WriteHandler>
inline bool asio_handler_is_continuation(
write_dynbuf_v1_op<AsyncWriteStream, DynamicBuffer_v1,
CompletionCondition, WriteHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncWriteStream>
class initiate_async_write_dynbuf_v1
{
public:
typedef typename AsyncWriteStream::executor_type executor_type;
explicit initiate_async_write_dynbuf_v1(AsyncWriteStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename WriteHandler, typename DynamicBuffer_v1,
typename CompletionCondition>
void operator()(WriteHandler&& handler,
DynamicBuffer_v1&& buffers,
CompletionCondition&& completion_cond) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
non_const_lvalue<WriteHandler> handler2(handler);
non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
write_dynbuf_v1_op<AsyncWriteStream,
decay_t<DynamicBuffer_v1>,
CompletionCondition, decay_t<WriteHandler>>(
stream_, static_cast<DynamicBuffer_v1&&>(buffers),
completion_cond2.value, handler2.value)(
boost::system::error_code(), 0, 1);
}
private:
AsyncWriteStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncWriteStream, typename DynamicBuffer_v1,
typename CompletionCondition, typename WriteHandler,
typename DefaultCandidate>
struct associator<Associator,
detail::write_dynbuf_v1_op<AsyncWriteStream,
DynamicBuffer_v1, CompletionCondition, WriteHandler>,
DefaultCandidate>
: Associator<WriteHandler, DefaultCandidate>
{
static typename Associator<WriteHandler, DefaultCandidate>::type get(
const detail::write_dynbuf_v1_op<AsyncWriteStream, DynamicBuffer_v1,
CompletionCondition, WriteHandler>& h) noexcept
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::write_dynbuf_v1_op<AsyncWriteStream,
DynamicBuffer_v1, CompletionCondition, WriteHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncWriteStream, typename DynamicBuffer_v1,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write(AsyncWriteStream& s,
DynamicBuffer_v1&& buffers, WriteToken&& token,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(),
token, static_cast<DynamicBuffer_v1&&>(buffers),
transfer_all()))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>(s),
token, static_cast<DynamicBuffer_v1&&>(buffers),
transfer_all());
}
template <typename AsyncWriteStream,
typename DynamicBuffer_v1, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write(AsyncWriteStream& s, DynamicBuffer_v1&& buffers,
CompletionCondition completion_condition, WriteToken&& token,
constraint_t<
is_dynamic_buffer_v1<decay_t<DynamicBuffer_v1>>::value
>,
constraint_t<
!is_dynamic_buffer_v2<decay_t<DynamicBuffer_v1>>::value
>)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(),
token, static_cast<DynamicBuffer_v1&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>(s),
token, static_cast<DynamicBuffer_v1&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition));
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename AsyncWriteStream, typename Allocator,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write(AsyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b,
WriteToken&& token)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(),
token, basic_streambuf_ref<Allocator>(b), transfer_all()))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>(s),
token, basic_streambuf_ref<Allocator>(b), transfer_all());
}
template <typename AsyncWriteStream,
typename Allocator, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write(AsyncWriteStream& s,
boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, WriteToken&& token)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>>(),
token, basic_streambuf_ref<Allocator>(b),
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_dynbuf_v1<AsyncWriteStream>(s),
token, basic_streambuf_ref<Allocator>(b),
static_cast<CompletionCondition&&>(completion_condition));
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
#endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
namespace detail
{
template <typename AsyncWriteStream, typename DynamicBuffer_v2,
typename CompletionCondition, typename WriteHandler>
class write_dynbuf_v2_op
{
public:
template <typename BufferSequence>
write_dynbuf_v2_op(AsyncWriteStream& stream,
BufferSequence&& buffers,
CompletionCondition& completion_condition, WriteHandler& handler)
: stream_(stream),
buffers_(static_cast<BufferSequence&&>(buffers)),
completion_condition_(
static_cast<CompletionCondition&&>(completion_condition)),
handler_(static_cast<WriteHandler&&>(handler))
{
}
write_dynbuf_v2_op(const write_dynbuf_v2_op& other)
: stream_(other.stream_),
buffers_(other.buffers_),
completion_condition_(other.completion_condition_),
handler_(other.handler_)
{
}
write_dynbuf_v2_op(write_dynbuf_v2_op&& other)
: stream_(other.stream_),
buffers_(static_cast<DynamicBuffer_v2&&>(other.buffers_)),
completion_condition_(
static_cast<CompletionCondition&&>(
other.completion_condition_)),
handler_(static_cast<WriteHandler&&>(other.handler_))
{
}
void operator()(const boost::system::error_code& ec,
std::size_t bytes_transferred, int start = 0)
{
switch (start)
{
case 1:
async_write(stream_, buffers_.data(0, buffers_.size()),
static_cast<CompletionCondition&&>(completion_condition_),
static_cast<write_dynbuf_v2_op&&>(*this));
return; default:
buffers_.consume(bytes_transferred);
static_cast<WriteHandler&&>(handler_)(ec,
static_cast<const std::size_t&>(bytes_transferred));
}
}
//private:
AsyncWriteStream& stream_;
DynamicBuffer_v2 buffers_;
CompletionCondition completion_condition_;
WriteHandler handler_;
};
template <typename AsyncWriteStream, typename DynamicBuffer_v2,
typename CompletionCondition, typename WriteHandler>
inline bool asio_handler_is_continuation(
write_dynbuf_v2_op<AsyncWriteStream, DynamicBuffer_v2,
CompletionCondition, WriteHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncWriteStream>
class initiate_async_write_dynbuf_v2
{
public:
typedef typename AsyncWriteStream::executor_type executor_type;
explicit initiate_async_write_dynbuf_v2(AsyncWriteStream& stream)
: stream_(stream)
{
}
executor_type get_executor() const noexcept
{
return stream_.get_executor();
}
template <typename WriteHandler, typename DynamicBuffer_v2,
typename CompletionCondition>
void operator()(WriteHandler&& handler,
DynamicBuffer_v2&& buffers,
CompletionCondition&& completion_cond) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
non_const_lvalue<WriteHandler> handler2(handler);
non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
write_dynbuf_v2_op<AsyncWriteStream, decay_t<DynamicBuffer_v2>,
CompletionCondition, decay_t<WriteHandler>>(
stream_, static_cast<DynamicBuffer_v2&&>(buffers),
completion_cond2.value, handler2.value)(
boost::system::error_code(), 0, 1);
}
private:
AsyncWriteStream& stream_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncWriteStream, typename DynamicBuffer_v2,
typename CompletionCondition, typename WriteHandler,
typename DefaultCandidate>
struct associator<Associator,
detail::write_dynbuf_v2_op<AsyncWriteStream,
DynamicBuffer_v2, CompletionCondition, WriteHandler>,
DefaultCandidate>
: Associator<WriteHandler, DefaultCandidate>
{
static typename Associator<WriteHandler, DefaultCandidate>::type get(
const detail::write_dynbuf_v2_op<AsyncWriteStream, DynamicBuffer_v2,
CompletionCondition, WriteHandler>& h) noexcept
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::write_dynbuf_v2_op<AsyncWriteStream,
DynamicBuffer_v2, CompletionCondition, WriteHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncWriteStream, typename DynamicBuffer_v2,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write(AsyncWriteStream& s,
DynamicBuffer_v2 buffers, WriteToken&& token,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>>(),
token, static_cast<DynamicBuffer_v2&&>(buffers),
transfer_all()))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>(s),
token, static_cast<DynamicBuffer_v2&&>(buffers),
transfer_all());
}
template <typename AsyncWriteStream,
typename DynamicBuffer_v2, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline auto async_write(AsyncWriteStream& s, DynamicBuffer_v2 buffers,
CompletionCondition completion_condition, WriteToken&& token,
constraint_t<
is_dynamic_buffer_v2<DynamicBuffer_v2>::value
>)
-> decltype(
async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>>(),
token, static_cast<DynamicBuffer_v2&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_dynbuf_v2<AsyncWriteStream>(s),
token, static_cast<DynamicBuffer_v2&&>(buffers),
static_cast<CompletionCondition&&>(completion_condition));
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_WRITE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/use_future.hpp | //
// impl/use_future.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_USE_FUTURE_HPP
#define BOOST_ASIO_IMPL_USE_FUTURE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <tuple>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/memory.hpp>
#include <boost/asio/dispatch.hpp>
#include <boost/system/error_code.hpp>
#include <boost/asio/execution.hpp>
#include <boost/asio/packaged_task.hpp>
#include <boost/system/system_error.hpp>
#include <boost/asio/system_executor.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
template <typename T, typename F, typename... Args>
inline void promise_invoke_and_set(std::promise<T>& p,
F& f, Args&&... args)
{
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
{
p.set_value(f(static_cast<Args&&>(args)...));
}
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
catch (...)
{
p.set_exception(std::current_exception());
}
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
template <typename F, typename... Args>
inline void promise_invoke_and_set(std::promise<void>& p,
F& f, Args&&... args)
{
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
{
f(static_cast<Args&&>(args)...);
p.set_value();
}
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
catch (...)
{
p.set_exception(std::current_exception());
}
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
// A function object adapter to invoke a nullary function object and capture
// any exception thrown into a promise.
template <typename T, typename F>
class promise_invoker
{
public:
promise_invoker(const shared_ptr<std::promise<T>>& p,
F&& f)
: p_(p), f_(static_cast<F&&>(f))
{
}
void operator()()
{
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
{
f_();
}
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
catch (...)
{
p_->set_exception(std::current_exception());
}
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
private:
shared_ptr<std::promise<T>> p_;
decay_t<F> f_;
};
// An executor that adapts the system_executor to capture any exeption thrown
// by a submitted function object and save it into a promise.
template <typename T, typename Blocking = execution::blocking_t::possibly_t>
class promise_executor
{
public:
explicit promise_executor(const shared_ptr<std::promise<T>>& p)
: p_(p)
{
}
execution_context& query(execution::context_t) const noexcept
{
return boost::asio::query(system_executor(), execution::context);
}
static constexpr Blocking query(execution::blocking_t)
{
return Blocking();
}
promise_executor<T, execution::blocking_t::possibly_t>
require(execution::blocking_t::possibly_t) const
{
return promise_executor<T, execution::blocking_t::possibly_t>(p_);
}
promise_executor<T, execution::blocking_t::never_t>
require(execution::blocking_t::never_t) const
{
return promise_executor<T, execution::blocking_t::never_t>(p_);
}
template <typename F>
void execute(F&& f) const
{
boost::asio::require(system_executor(), Blocking()).execute(
promise_invoker<T, F>(p_, static_cast<F&&>(f)));
}
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
execution_context& context() const noexcept
{
return system_executor().context();
}
void on_work_started() const noexcept {}
void on_work_finished() const noexcept {}
template <typename F, typename A>
void dispatch(F&& f, const A&) const
{
promise_invoker<T, F>(p_, static_cast<F&&>(f))();
}
template <typename F, typename A>
void post(F&& f, const A& a) const
{
system_executor().post(
promise_invoker<T, F>(p_, static_cast<F&&>(f)), a);
}
template <typename F, typename A>
void defer(F&& f, const A& a) const
{
system_executor().defer(
promise_invoker<T, F>(p_, static_cast<F&&>(f)), a);
}
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
friend bool operator==(const promise_executor& a,
const promise_executor& b) noexcept
{
return a.p_ == b.p_;
}
friend bool operator!=(const promise_executor& a,
const promise_executor& b) noexcept
{
return a.p_ != b.p_;
}
private:
shared_ptr<std::promise<T>> p_;
};
// The base class for all completion handlers that create promises.
template <typename T>
class promise_creator
{
public:
typedef promise_executor<T> executor_type;
executor_type get_executor() const noexcept
{
return executor_type(p_);
}
typedef std::future<T> future_type;
future_type get_future()
{
return p_->get_future();
}
protected:
template <typename Allocator>
void create_promise(const Allocator& a)
{
BOOST_ASIO_REBIND_ALLOC(Allocator, char) b(a);
p_ = std::allocate_shared<std::promise<T>>(b, std::allocator_arg, b);
}
shared_ptr<std::promise<T>> p_;
};
// For completion signature void().
class promise_handler_0
: public promise_creator<void>
{
public:
void operator()()
{
this->p_->set_value();
}
};
// For completion signature void(error_code).
class promise_handler_ec_0
: public promise_creator<void>
{
public:
void operator()(const boost::system::error_code& ec)
{
if (ec)
{
this->p_->set_exception(
std::make_exception_ptr(
boost::system::system_error(ec)));
}
else
{
this->p_->set_value();
}
}
};
// For completion signature void(exception_ptr).
class promise_handler_ex_0
: public promise_creator<void>
{
public:
void operator()(const std::exception_ptr& ex)
{
if (ex)
{
this->p_->set_exception(ex);
}
else
{
this->p_->set_value();
}
}
};
// For completion signature void(T).
template <typename T>
class promise_handler_1
: public promise_creator<T>
{
public:
template <typename Arg>
void operator()(Arg&& arg)
{
this->p_->set_value(static_cast<Arg&&>(arg));
}
};
// For completion signature void(error_code, T).
template <typename T>
class promise_handler_ec_1
: public promise_creator<T>
{
public:
template <typename Arg>
void operator()(const boost::system::error_code& ec,
Arg&& arg)
{
if (ec)
{
this->p_->set_exception(
std::make_exception_ptr(
boost::system::system_error(ec)));
}
else
this->p_->set_value(static_cast<Arg&&>(arg));
}
};
// For completion signature void(exception_ptr, T).
template <typename T>
class promise_handler_ex_1
: public promise_creator<T>
{
public:
template <typename Arg>
void operator()(const std::exception_ptr& ex,
Arg&& arg)
{
if (ex)
this->p_->set_exception(ex);
else
this->p_->set_value(static_cast<Arg&&>(arg));
}
};
// For completion signature void(T1, ..., Tn);
template <typename T>
class promise_handler_n
: public promise_creator<T>
{
public:
template <typename... Args>
void operator()(Args&&... args)
{
this->p_->set_value(
std::forward_as_tuple(
static_cast<Args&&>(args)...));
}
};
// For completion signature void(error_code, T1, ..., Tn);
template <typename T>
class promise_handler_ec_n
: public promise_creator<T>
{
public:
template <typename... Args>
void operator()(const boost::system::error_code& ec, Args&&... args)
{
if (ec)
{
this->p_->set_exception(
std::make_exception_ptr(
boost::system::system_error(ec)));
}
else
{
this->p_->set_value(
std::forward_as_tuple(
static_cast<Args&&>(args)...));
}
}
};
// For completion signature void(exception_ptr, T1, ..., Tn);
template <typename T>
class promise_handler_ex_n
: public promise_creator<T>
{
public:
template <typename... Args>
void operator()(const std::exception_ptr& ex,
Args&&... args)
{
if (ex)
this->p_->set_exception(ex);
else
{
this->p_->set_value(
std::forward_as_tuple(
static_cast<Args&&>(args)...));
}
}
};
// Helper template to choose the appropriate concrete promise handler
// implementation based on the supplied completion signature.
template <typename> class promise_handler_selector;
template <>
class promise_handler_selector<void()>
: public promise_handler_0 {};
template <>
class promise_handler_selector<void(boost::system::error_code)>
: public promise_handler_ec_0 {};
template <>
class promise_handler_selector<void(std::exception_ptr)>
: public promise_handler_ex_0 {};
template <typename Arg>
class promise_handler_selector<void(Arg)>
: public promise_handler_1<Arg> {};
template <typename Arg>
class promise_handler_selector<void(boost::system::error_code, Arg)>
: public promise_handler_ec_1<Arg> {};
template <typename Arg>
class promise_handler_selector<void(std::exception_ptr, Arg)>
: public promise_handler_ex_1<Arg> {};
template <typename... Arg>
class promise_handler_selector<void(Arg...)>
: public promise_handler_n<std::tuple<Arg...>> {};
template <typename... Arg>
class promise_handler_selector<void(boost::system::error_code, Arg...)>
: public promise_handler_ec_n<std::tuple<Arg...>> {};
template <typename... Arg>
class promise_handler_selector<void(std::exception_ptr, Arg...)>
: public promise_handler_ex_n<std::tuple<Arg...>> {};
// Completion handlers produced from the use_future completion token, when not
// using use_future::operator().
template <typename Signature, typename Allocator>
class promise_handler
: public promise_handler_selector<Signature>
{
public:
typedef Allocator allocator_type;
typedef void result_type;
promise_handler(use_future_t<Allocator> u)
: allocator_(u.get_allocator())
{
this->create_promise(allocator_);
}
allocator_type get_allocator() const noexcept
{
return allocator_;
}
private:
Allocator allocator_;
};
template <typename Function>
struct promise_function_wrapper
{
explicit promise_function_wrapper(Function& f)
: function_(static_cast<Function&&>(f))
{
}
explicit promise_function_wrapper(const Function& f)
: function_(f)
{
}
void operator()()
{
function_();
}
Function function_;
};
// Helper base class for async_result specialisation.
template <typename Signature, typename Allocator>
class promise_async_result
{
public:
typedef promise_handler<Signature, Allocator> completion_handler_type;
typedef typename completion_handler_type::future_type return_type;
explicit promise_async_result(completion_handler_type& h)
: future_(h.get_future())
{
}
return_type get()
{
return static_cast<return_type&&>(future_);
}
private:
return_type future_;
};
// Return value from use_future::operator().
template <typename Function, typename Allocator>
class packaged_token
{
public:
packaged_token(Function f, const Allocator& a)
: function_(static_cast<Function&&>(f)),
allocator_(a)
{
}
//private:
Function function_;
Allocator allocator_;
};
// Completion handlers produced from the use_future completion token, when
// using use_future::operator().
template <typename Function, typename Allocator, typename Result>
class packaged_handler
: public promise_creator<Result>
{
public:
typedef Allocator allocator_type;
typedef void result_type;
packaged_handler(packaged_token<Function, Allocator> t)
: function_(static_cast<Function&&>(t.function_)),
allocator_(t.allocator_)
{
this->create_promise(allocator_);
}
allocator_type get_allocator() const noexcept
{
return allocator_;
}
template <typename... Args>
void operator()(Args&&... args)
{
(promise_invoke_and_set)(*this->p_,
function_, static_cast<Args&&>(args)...);
}
private:
Function function_;
Allocator allocator_;
};
// Helper base class for async_result specialisation.
template <typename Function, typename Allocator, typename Result>
class packaged_async_result
{
public:
typedef packaged_handler<Function, Allocator, Result> completion_handler_type;
typedef typename completion_handler_type::future_type return_type;
explicit packaged_async_result(completion_handler_type& h)
: future_(h.get_future())
{
}
return_type get()
{
return static_cast<return_type&&>(future_);
}
private:
return_type future_;
};
} // namespace detail
template <typename Allocator> template <typename Function>
inline detail::packaged_token<decay_t<Function>, Allocator>
use_future_t<Allocator>::operator()(Function&& f) const
{
return detail::packaged_token<decay_t<Function>, Allocator>(
static_cast<Function&&>(f), allocator_);
}
#if !defined(GENERATING_DOCUMENTATION)
template <typename Allocator, typename Result, typename... Args>
class async_result<use_future_t<Allocator>, Result(Args...)>
: public detail::promise_async_result<
void(decay_t<Args>...), Allocator>
{
public:
explicit async_result(
typename detail::promise_async_result<void(decay_t<Args>...),
Allocator>::completion_handler_type& h)
: detail::promise_async_result<
void(decay_t<Args>...), Allocator>(h)
{
}
};
template <typename Function, typename Allocator,
typename Result, typename... Args>
class async_result<detail::packaged_token<Function, Allocator>, Result(Args...)>
: public detail::packaged_async_result<Function, Allocator,
result_of_t<Function(Args...)>>
{
public:
explicit async_result(
typename detail::packaged_async_result<Function, Allocator,
result_of_t<Function(Args...)>>::completion_handler_type& h)
: detail::packaged_async_result<Function, Allocator,
result_of_t<Function(Args...)>>(h)
{
}
};
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <typename T, typename Blocking>
struct equality_comparable<
boost::asio::detail::promise_executor<T, Blocking>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename T, typename Blocking, typename Function>
struct execute_member<
boost::asio::detail::promise_executor<T, Blocking>, Function>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
template <typename T, typename Blocking, typename Property>
struct query_static_constexpr_member<
boost::asio::detail::promise_executor<T, Blocking>,
Property,
typename boost::asio::enable_if<
boost::asio::is_convertible<
Property,
boost::asio::execution::blocking_t
>::value
>::type
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef Blocking result_type;
static constexpr result_type value() noexcept
{
return Blocking();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
template <typename T, typename Blocking>
struct query_member<
boost::asio::detail::promise_executor<T, Blocking>,
execution::context_t
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef boost::asio::system_context& result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
template <typename T, typename Blocking>
struct require_member<
boost::asio::detail::promise_executor<T, Blocking>,
execution::blocking_t::possibly_t
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef boost::asio::detail::promise_executor<T,
execution::blocking_t::possibly_t> result_type;
};
template <typename T, typename Blocking>
struct require_member<
boost::asio::detail::promise_executor<T, Blocking>,
execution::blocking_t::never_t
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef boost::asio::detail::promise_executor<T,
execution::blocking_t::never_t> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
} // namespace traits
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_USE_FUTURE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/connect.hpp | //
// impl/connect.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_CONNECT_HPP
#define BOOST_ASIO_IMPL_CONNECT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <algorithm>
#include <boost/asio/associator.hpp>
#include <boost/asio/detail/base_from_cancellation_state.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_tracking.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail
{
struct default_connect_condition
{
template <typename Endpoint>
bool operator()(const boost::system::error_code&, const Endpoint&)
{
return true;
}
};
template <typename Protocol, typename Iterator>
inline typename Protocol::endpoint deref_connect_result(
Iterator iter, boost::system::error_code& ec)
{
return ec ? typename Protocol::endpoint() : *iter;
}
template <typename T, typename Iterator>
struct legacy_connect_condition_helper : T
{
typedef char (*fallback_func_type)(...);
operator fallback_func_type() const;
};
template <typename R, typename Arg1, typename Arg2, typename Iterator>
struct legacy_connect_condition_helper<R (*)(Arg1, Arg2), Iterator>
{
R operator()(Arg1, Arg2) const;
char operator()(...) const;
};
template <typename T, typename Iterator>
struct is_legacy_connect_condition
{
static char asio_connect_condition_check(char);
static char (&asio_connect_condition_check(Iterator))[2];
static const bool value =
sizeof(asio_connect_condition_check(
(declval<legacy_connect_condition_helper<T, Iterator>>())(
declval<const boost::system::error_code>(),
declval<const Iterator>()))) != 1;
};
template <typename ConnectCondition, typename Iterator>
inline Iterator call_connect_condition(ConnectCondition& connect_condition,
const boost::system::error_code& ec, Iterator next, Iterator end,
enable_if_t<is_legacy_connect_condition<
ConnectCondition, Iterator>::value>* = 0)
{
if (next != end)
return connect_condition(ec, next);
return end;
}
template <typename ConnectCondition, typename Iterator>
inline Iterator call_connect_condition(ConnectCondition& connect_condition,
const boost::system::error_code& ec, Iterator next, Iterator end,
enable_if_t<!is_legacy_connect_condition<
ConnectCondition, Iterator>::value>* = 0)
{
for (;next != end; ++next)
if (connect_condition(ec, *next))
return next;
return end;
}
}
template <typename Protocol, typename Executor, typename EndpointSequence>
typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
const EndpointSequence& endpoints,
constraint_t<is_endpoint_sequence<EndpointSequence>::value>)
{
boost::system::error_code ec;
typename Protocol::endpoint result = connect(s, endpoints, ec);
boost::asio::detail::throw_error(ec, "connect");
return result;
}
template <typename Protocol, typename Executor, typename EndpointSequence>
typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
const EndpointSequence& endpoints, boost::system::error_code& ec,
constraint_t<is_endpoint_sequence<EndpointSequence>::value>)
{
return detail::deref_connect_result<Protocol>(
connect(s, endpoints.begin(), endpoints.end(),
detail::default_connect_condition(), ec), ec);
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Protocol, typename Executor, typename Iterator>
Iterator connect(basic_socket<Protocol, Executor>& s, Iterator begin,
constraint_t<!is_endpoint_sequence<Iterator>::value>)
{
boost::system::error_code ec;
Iterator result = connect(s, begin, ec);
boost::asio::detail::throw_error(ec, "connect");
return result;
}
template <typename Protocol, typename Executor, typename Iterator>
inline Iterator connect(basic_socket<Protocol, Executor>& s,
Iterator begin, boost::system::error_code& ec,
constraint_t<!is_endpoint_sequence<Iterator>::value>)
{
return connect(s, begin, Iterator(), detail::default_connect_condition(), ec);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Protocol, typename Executor, typename Iterator>
Iterator connect(basic_socket<Protocol, Executor>& s,
Iterator begin, Iterator end)
{
boost::system::error_code ec;
Iterator result = connect(s, begin, end, ec);
boost::asio::detail::throw_error(ec, "connect");
return result;
}
template <typename Protocol, typename Executor, typename Iterator>
inline Iterator connect(basic_socket<Protocol, Executor>& s,
Iterator begin, Iterator end, boost::system::error_code& ec)
{
return connect(s, begin, end, detail::default_connect_condition(), ec);
}
template <typename Protocol, typename Executor,
typename EndpointSequence, typename ConnectCondition>
typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
const EndpointSequence& endpoints, ConnectCondition connect_condition,
constraint_t<is_endpoint_sequence<EndpointSequence>::value>)
{
boost::system::error_code ec;
typename Protocol::endpoint result = connect(
s, endpoints, connect_condition, ec);
boost::asio::detail::throw_error(ec, "connect");
return result;
}
template <typename Protocol, typename Executor,
typename EndpointSequence, typename ConnectCondition>
typename Protocol::endpoint connect(basic_socket<Protocol, Executor>& s,
const EndpointSequence& endpoints, ConnectCondition connect_condition,
boost::system::error_code& ec,
constraint_t<is_endpoint_sequence<EndpointSequence>::value>)
{
return detail::deref_connect_result<Protocol>(
connect(s, endpoints.begin(), endpoints.end(),
connect_condition, ec), ec);
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Protocol, typename Executor,
typename Iterator, typename ConnectCondition>
Iterator connect(basic_socket<Protocol, Executor>& s,
Iterator begin, ConnectCondition connect_condition,
constraint_t<!is_endpoint_sequence<Iterator>::value>)
{
boost::system::error_code ec;
Iterator result = connect(s, begin, connect_condition, ec);
boost::asio::detail::throw_error(ec, "connect");
return result;
}
template <typename Protocol, typename Executor,
typename Iterator, typename ConnectCondition>
inline Iterator connect(basic_socket<Protocol, Executor>& s,
Iterator begin, ConnectCondition connect_condition,
boost::system::error_code& ec,
constraint_t<!is_endpoint_sequence<Iterator>::value>)
{
return connect(s, begin, Iterator(), connect_condition, ec);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Protocol, typename Executor,
typename Iterator, typename ConnectCondition>
Iterator connect(basic_socket<Protocol, Executor>& s, Iterator begin,
Iterator end, ConnectCondition connect_condition)
{
boost::system::error_code ec;
Iterator result = connect(s, begin, end, connect_condition, ec);
boost::asio::detail::throw_error(ec, "connect");
return result;
}
template <typename Protocol, typename Executor,
typename Iterator, typename ConnectCondition>
Iterator connect(basic_socket<Protocol, Executor>& s, Iterator begin,
Iterator end, ConnectCondition connect_condition,
boost::system::error_code& ec)
{
ec = boost::system::error_code();
for (Iterator iter = begin; iter != end; ++iter)
{
iter = (detail::call_connect_condition(connect_condition, ec, iter, end));
if (iter != end)
{
s.close(ec);
s.connect(*iter, ec);
if (!ec)
return iter;
}
else
break;
}
if (!ec)
ec = boost::asio::error::not_found;
return end;
}
namespace detail
{
// Enable the empty base class optimisation for the connect condition.
template <typename ConnectCondition>
class base_from_connect_condition
{
protected:
explicit base_from_connect_condition(
const ConnectCondition& connect_condition)
: connect_condition_(connect_condition)
{
}
template <typename Iterator>
void check_condition(const boost::system::error_code& ec,
Iterator& iter, Iterator& end)
{
iter = detail::call_connect_condition(connect_condition_, ec, iter, end);
}
private:
ConnectCondition connect_condition_;
};
// The default_connect_condition implementation is essentially a no-op. This
// template specialisation lets us eliminate all costs associated with it.
template <>
class base_from_connect_condition<default_connect_condition>
{
protected:
explicit base_from_connect_condition(const default_connect_condition&)
{
}
template <typename Iterator>
void check_condition(const boost::system::error_code&, Iterator&, Iterator&)
{
}
};
template <typename Protocol, typename Executor, typename EndpointSequence,
typename ConnectCondition, typename RangeConnectHandler>
class range_connect_op
: public base_from_cancellation_state<RangeConnectHandler>,
base_from_connect_condition<ConnectCondition>
{
public:
range_connect_op(basic_socket<Protocol, Executor>& sock,
const EndpointSequence& endpoints,
const ConnectCondition& connect_condition,
RangeConnectHandler& handler)
: base_from_cancellation_state<RangeConnectHandler>(
handler, enable_partial_cancellation()),
base_from_connect_condition<ConnectCondition>(connect_condition),
socket_(sock),
endpoints_(endpoints),
index_(0),
start_(0),
handler_(static_cast<RangeConnectHandler&&>(handler))
{
}
range_connect_op(const range_connect_op& other)
: base_from_cancellation_state<RangeConnectHandler>(other),
base_from_connect_condition<ConnectCondition>(other),
socket_(other.socket_),
endpoints_(other.endpoints_),
index_(other.index_),
start_(other.start_),
handler_(other.handler_)
{
}
range_connect_op(range_connect_op&& other)
: base_from_cancellation_state<RangeConnectHandler>(
static_cast<base_from_cancellation_state<RangeConnectHandler>&&>(
other)),
base_from_connect_condition<ConnectCondition>(other),
socket_(other.socket_),
endpoints_(other.endpoints_),
index_(other.index_),
start_(other.start_),
handler_(static_cast<RangeConnectHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec, int start = 0)
{
this->process(ec, start,
const_cast<const EndpointSequence&>(endpoints_).begin(),
const_cast<const EndpointSequence&>(endpoints_).end());
}
//private:
template <typename Iterator>
void process(boost::system::error_code ec,
int start, Iterator begin, Iterator end)
{
Iterator iter = begin;
std::advance(iter, index_);
switch (start_ = start)
{
case 1:
for (;;)
{
this->check_condition(ec, iter, end);
index_ = std::distance(begin, iter);
if (iter != end)
{
socket_.close(ec);
BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_connect"));
socket_.async_connect(*iter,
static_cast<range_connect_op&&>(*this));
return;
}
if (start)
{
ec = boost::asio::error::not_found;
BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_connect"));
boost::asio::post(socket_.get_executor(),
detail::bind_handler(
static_cast<range_connect_op&&>(*this), ec));
return;
}
/* fall-through */ default:
if (iter == end)
break;
if (!socket_.is_open())
{
ec = boost::asio::error::operation_aborted;
break;
}
if (!ec)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = boost::asio::error::operation_aborted;
break;
}
++iter;
++index_;
}
static_cast<RangeConnectHandler&&>(handler_)(
static_cast<const boost::system::error_code&>(ec),
static_cast<const typename Protocol::endpoint&>(
ec || iter == end ? typename Protocol::endpoint() : *iter));
}
}
basic_socket<Protocol, Executor>& socket_;
EndpointSequence endpoints_;
std::size_t index_;
int start_;
RangeConnectHandler handler_;
};
template <typename Protocol, typename Executor, typename EndpointSequence,
typename ConnectCondition, typename RangeConnectHandler>
inline bool asio_handler_is_continuation(
range_connect_op<Protocol, Executor, EndpointSequence,
ConnectCondition, RangeConnectHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Protocol, typename Executor>
class initiate_async_range_connect
{
public:
typedef Executor executor_type;
explicit initiate_async_range_connect(basic_socket<Protocol, Executor>& s)
: socket_(s)
{
}
executor_type get_executor() const noexcept
{
return socket_.get_executor();
}
template <typename RangeConnectHandler,
typename EndpointSequence, typename ConnectCondition>
void operator()(RangeConnectHandler&& handler,
const EndpointSequence& endpoints,
const ConnectCondition& connect_condition) const
{
// If you get an error on the following line it means that your
// handler does not meet the documented type requirements for an
// RangeConnectHandler.
BOOST_ASIO_RANGE_CONNECT_HANDLER_CHECK(RangeConnectHandler,
handler, typename Protocol::endpoint) type_check;
non_const_lvalue<RangeConnectHandler> handler2(handler);
range_connect_op<Protocol, Executor, EndpointSequence, ConnectCondition,
decay_t<RangeConnectHandler>>(socket_, endpoints,
connect_condition, handler2.value)(boost::system::error_code(), 1);
}
private:
basic_socket<Protocol, Executor>& socket_;
};
template <typename Protocol, typename Executor, typename Iterator,
typename ConnectCondition, typename IteratorConnectHandler>
class iterator_connect_op
: public base_from_cancellation_state<IteratorConnectHandler>,
base_from_connect_condition<ConnectCondition>
{
public:
iterator_connect_op(basic_socket<Protocol, Executor>& sock,
const Iterator& begin, const Iterator& end,
const ConnectCondition& connect_condition,
IteratorConnectHandler& handler)
: base_from_cancellation_state<IteratorConnectHandler>(
handler, enable_partial_cancellation()),
base_from_connect_condition<ConnectCondition>(connect_condition),
socket_(sock),
iter_(begin),
end_(end),
start_(0),
handler_(static_cast<IteratorConnectHandler&&>(handler))
{
}
iterator_connect_op(const iterator_connect_op& other)
: base_from_cancellation_state<IteratorConnectHandler>(other),
base_from_connect_condition<ConnectCondition>(other),
socket_(other.socket_),
iter_(other.iter_),
end_(other.end_),
start_(other.start_),
handler_(other.handler_)
{
}
iterator_connect_op(iterator_connect_op&& other)
: base_from_cancellation_state<IteratorConnectHandler>(
static_cast<base_from_cancellation_state<IteratorConnectHandler>&&>(
other)),
base_from_connect_condition<ConnectCondition>(other),
socket_(other.socket_),
iter_(other.iter_),
end_(other.end_),
start_(other.start_),
handler_(static_cast<IteratorConnectHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec, int start = 0)
{
switch (start_ = start)
{
case 1:
for (;;)
{
this->check_condition(ec, iter_, end_);
if (iter_ != end_)
{
socket_.close(ec);
BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_connect"));
socket_.async_connect(*iter_,
static_cast<iterator_connect_op&&>(*this));
return;
}
if (start)
{
ec = boost::asio::error::not_found;
BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_connect"));
boost::asio::post(socket_.get_executor(),
detail::bind_handler(
static_cast<iterator_connect_op&&>(*this), ec));
return;
}
/* fall-through */ default:
if (iter_ == end_)
break;
if (!socket_.is_open())
{
ec = boost::asio::error::operation_aborted;
break;
}
if (!ec)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = boost::asio::error::operation_aborted;
break;
}
++iter_;
}
static_cast<IteratorConnectHandler&&>(handler_)(
static_cast<const boost::system::error_code&>(ec),
static_cast<const Iterator&>(iter_));
}
}
//private:
basic_socket<Protocol, Executor>& socket_;
Iterator iter_;
Iterator end_;
int start_;
IteratorConnectHandler handler_;
};
template <typename Protocol, typename Executor, typename Iterator,
typename ConnectCondition, typename IteratorConnectHandler>
inline bool asio_handler_is_continuation(
iterator_connect_op<Protocol, Executor, Iterator,
ConnectCondition, IteratorConnectHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Protocol, typename Executor>
class initiate_async_iterator_connect
{
public:
typedef Executor executor_type;
explicit initiate_async_iterator_connect(
basic_socket<Protocol, Executor>& s)
: socket_(s)
{
}
executor_type get_executor() const noexcept
{
return socket_.get_executor();
}
template <typename IteratorConnectHandler,
typename Iterator, typename ConnectCondition>
void operator()(IteratorConnectHandler&& handler,
Iterator begin, Iterator end,
const ConnectCondition& connect_condition) const
{
// If you get an error on the following line it means that your
// handler does not meet the documented type requirements for an
// IteratorConnectHandler.
BOOST_ASIO_ITERATOR_CONNECT_HANDLER_CHECK(
IteratorConnectHandler, handler, Iterator) type_check;
non_const_lvalue<IteratorConnectHandler> handler2(handler);
iterator_connect_op<Protocol, Executor, Iterator, ConnectCondition,
decay_t<IteratorConnectHandler>>(socket_, begin, end,
connect_condition, handler2.value)(boost::system::error_code(), 1);
}
private:
basic_socket<Protocol, Executor>& socket_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename Protocol, typename Executor, typename EndpointSequence,
typename ConnectCondition, typename RangeConnectHandler,
typename DefaultCandidate>
struct associator<Associator,
detail::range_connect_op<Protocol, Executor,
EndpointSequence, ConnectCondition, RangeConnectHandler>,
DefaultCandidate>
: Associator<RangeConnectHandler, DefaultCandidate>
{
static typename Associator<RangeConnectHandler, DefaultCandidate>::type get(
const detail::range_connect_op<Protocol, Executor, EndpointSequence,
ConnectCondition, RangeConnectHandler>& h) noexcept
{
return Associator<RangeConnectHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::range_connect_op<Protocol, Executor,
EndpointSequence, ConnectCondition, RangeConnectHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(
Associator<RangeConnectHandler, DefaultCandidate>::get(
h.handler_, c))
{
return Associator<RangeConnectHandler, DefaultCandidate>::get(
h.handler_, c);
}
};
template <template <typename, typename> class Associator,
typename Protocol, typename Executor, typename Iterator,
typename ConnectCondition, typename IteratorConnectHandler,
typename DefaultCandidate>
struct associator<Associator,
detail::iterator_connect_op<Protocol, Executor,
Iterator, ConnectCondition, IteratorConnectHandler>,
DefaultCandidate>
: Associator<IteratorConnectHandler, DefaultCandidate>
{
static typename Associator<IteratorConnectHandler, DefaultCandidate>::type
get(const detail::iterator_connect_op<Protocol, Executor, Iterator,
ConnectCondition, IteratorConnectHandler>& h) noexcept
{
return Associator<IteratorConnectHandler, DefaultCandidate>::get(
h.handler_);
}
static auto get(
const detail::iterator_connect_op<Protocol, Executor,
Iterator, ConnectCondition, IteratorConnectHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(
Associator<IteratorConnectHandler, DefaultCandidate>::get(
h.handler_, c))
{
return Associator<IteratorConnectHandler, DefaultCandidate>::get(
h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename Protocol, typename Executor, typename EndpointSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
typename Protocol::endpoint)) RangeConnectToken>
inline auto async_connect(basic_socket<Protocol, Executor>& s,
const EndpointSequence& endpoints, RangeConnectToken&& token,
constraint_t<is_endpoint_sequence<EndpointSequence>::value>)
-> decltype(
async_initiate<RangeConnectToken,
void (boost::system::error_code, typename Protocol::endpoint)>(
declval<detail::initiate_async_range_connect<Protocol, Executor>>(),
token, endpoints, declval<detail::default_connect_condition>()))
{
return async_initiate<RangeConnectToken,
void (boost::system::error_code, typename Protocol::endpoint)>(
detail::initiate_async_range_connect<Protocol, Executor>(s),
token, endpoints, detail::default_connect_condition());
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Protocol, typename Executor, typename Iterator,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
Iterator)) IteratorConnectToken>
inline auto async_connect(basic_socket<Protocol, Executor>& s,
Iterator begin, IteratorConnectToken&& token,
constraint_t<!is_endpoint_sequence<Iterator>::value>)
-> decltype(
async_initiate<IteratorConnectToken,
void (boost::system::error_code, Iterator)>(
declval<detail::initiate_async_iterator_connect<Protocol, Executor>>(),
token, begin, Iterator(), declval<detail::default_connect_condition>()))
{
return async_initiate<IteratorConnectToken,
void (boost::system::error_code, Iterator)>(
detail::initiate_async_iterator_connect<Protocol, Executor>(s),
token, begin, Iterator(), detail::default_connect_condition());
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Protocol, typename Executor, typename Iterator,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
Iterator)) IteratorConnectToken>
inline auto async_connect(basic_socket<Protocol, Executor>& s,
Iterator begin, Iterator end, IteratorConnectToken&& token)
-> decltype(
async_initiate<IteratorConnectToken,
void (boost::system::error_code, Iterator)>(
declval<detail::initiate_async_iterator_connect<Protocol, Executor>>(),
token, begin, end, declval<detail::default_connect_condition>()))
{
return async_initiate<IteratorConnectToken,
void (boost::system::error_code, Iterator)>(
detail::initiate_async_iterator_connect<Protocol, Executor>(s),
token, begin, end, detail::default_connect_condition());
}
template <typename Protocol, typename Executor,
typename EndpointSequence, typename ConnectCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
typename Protocol::endpoint)) RangeConnectToken>
inline auto async_connect(basic_socket<Protocol, Executor>& s,
const EndpointSequence& endpoints, ConnectCondition connect_condition,
RangeConnectToken&& token,
constraint_t<is_endpoint_sequence<EndpointSequence>::value>)
-> decltype(
async_initiate<RangeConnectToken,
void (boost::system::error_code, typename Protocol::endpoint)>(
declval<detail::initiate_async_range_connect<Protocol, Executor>>(),
token, endpoints, connect_condition))
{
return async_initiate<RangeConnectToken,
void (boost::system::error_code, typename Protocol::endpoint)>(
detail::initiate_async_range_connect<Protocol, Executor>(s),
token, endpoints, connect_condition);
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Protocol, typename Executor,
typename Iterator, typename ConnectCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
Iterator)) IteratorConnectToken>
inline auto async_connect(basic_socket<Protocol, Executor>& s, Iterator begin,
ConnectCondition connect_condition, IteratorConnectToken&& token,
constraint_t<!is_endpoint_sequence<Iterator>::value>)
-> decltype(
async_initiate<IteratorConnectToken,
void (boost::system::error_code, Iterator)>(
declval<detail::initiate_async_iterator_connect<Protocol, Executor>>(),
token, begin, Iterator(), connect_condition))
{
return async_initiate<IteratorConnectToken,
void (boost::system::error_code, Iterator)>(
detail::initiate_async_iterator_connect<Protocol, Executor>(s),
token, begin, Iterator(), connect_condition);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Protocol, typename Executor,
typename Iterator, typename ConnectCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
Iterator)) IteratorConnectToken>
inline auto async_connect(basic_socket<Protocol, Executor>& s,
Iterator begin, Iterator end, ConnectCondition connect_condition,
IteratorConnectToken&& token)
-> decltype(
async_initiate<IteratorConnectToken,
void (boost::system::error_code, Iterator)>(
declval<detail::initiate_async_iterator_connect<Protocol, Executor>>(),
token, begin, end, connect_condition))
{
return async_initiate<IteratorConnectToken,
void (boost::system::error_code, Iterator)>(
detail::initiate_async_iterator_connect<Protocol, Executor>(s),
token, begin, end, connect_condition);
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_CONNECT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/buffered_write_stream.hpp | //
// impl/buffered_write_stream.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_BUFFERED_WRITE_STREAM_HPP
#define BOOST_ASIO_IMPL_BUFFERED_WRITE_STREAM_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/associator.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename Stream>
std::size_t buffered_write_stream<Stream>::flush()
{
std::size_t bytes_written = write(next_layer_,
buffer(storage_.data(), storage_.size()));
storage_.consume(bytes_written);
return bytes_written;
}
template <typename Stream>
std::size_t buffered_write_stream<Stream>::flush(boost::system::error_code& ec)
{
std::size_t bytes_written = write(next_layer_,
buffer(storage_.data(), storage_.size()),
transfer_all(), ec);
storage_.consume(bytes_written);
return bytes_written;
}
namespace detail
{
template <typename WriteHandler>
class buffered_flush_handler
{
public:
buffered_flush_handler(detail::buffered_stream_storage& storage,
WriteHandler& handler)
: storage_(storage),
handler_(static_cast<WriteHandler&&>(handler))
{
}
buffered_flush_handler(const buffered_flush_handler& other)
: storage_(other.storage_),
handler_(other.handler_)
{
}
buffered_flush_handler(buffered_flush_handler&& other)
: storage_(other.storage_),
handler_(static_cast<WriteHandler&&>(other.handler_))
{
}
void operator()(const boost::system::error_code& ec,
const std::size_t bytes_written)
{
storage_.consume(bytes_written);
static_cast<WriteHandler&&>(handler_)(ec, bytes_written);
}
//private:
detail::buffered_stream_storage& storage_;
WriteHandler handler_;
};
template <typename WriteHandler>
inline bool asio_handler_is_continuation(
buffered_flush_handler<WriteHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Stream>
class initiate_async_buffered_flush
{
public:
typedef typename remove_reference_t<
Stream>::lowest_layer_type::executor_type executor_type;
explicit initiate_async_buffered_flush(
remove_reference_t<Stream>& next_layer)
: next_layer_(next_layer)
{
}
executor_type get_executor() const noexcept
{
return next_layer_.lowest_layer().get_executor();
}
template <typename WriteHandler>
void operator()(WriteHandler&& handler,
buffered_stream_storage* storage) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
non_const_lvalue<WriteHandler> handler2(handler);
async_write(next_layer_, buffer(storage->data(), storage->size()),
buffered_flush_handler<decay_t<WriteHandler>>(
*storage, handler2.value));
}
private:
remove_reference_t<Stream>& next_layer_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename WriteHandler, typename DefaultCandidate>
struct associator<Associator,
detail::buffered_flush_handler<WriteHandler>,
DefaultCandidate>
: Associator<WriteHandler, DefaultCandidate>
{
static typename Associator<WriteHandler, DefaultCandidate>::type get(
const detail::buffered_flush_handler<WriteHandler>& h) noexcept
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::buffered_flush_handler<WriteHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename Stream>
template <
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteHandler>
inline auto buffered_write_stream<Stream>::async_flush(WriteHandler&& handler)
-> decltype(
async_initiate<WriteHandler,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_buffered_flush<Stream>>(),
handler, declval<detail::buffered_stream_storage*>()))
{
return async_initiate<WriteHandler,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_buffered_flush<Stream>(next_layer_),
handler, &storage_);
}
template <typename Stream>
template <typename ConstBufferSequence>
std::size_t buffered_write_stream<Stream>::write_some(
const ConstBufferSequence& buffers)
{
using boost::asio::buffer_size;
if (buffer_size(buffers) == 0)
return 0;
if (storage_.size() == storage_.capacity())
this->flush();
return this->copy(buffers);
}
template <typename Stream>
template <typename ConstBufferSequence>
std::size_t buffered_write_stream<Stream>::write_some(
const ConstBufferSequence& buffers, boost::system::error_code& ec)
{
ec = boost::system::error_code();
using boost::asio::buffer_size;
if (buffer_size(buffers) == 0)
return 0;
if (storage_.size() == storage_.capacity() && !flush(ec))
return 0;
return this->copy(buffers);
}
namespace detail
{
template <typename ConstBufferSequence, typename WriteHandler>
class buffered_write_some_handler
{
public:
buffered_write_some_handler(detail::buffered_stream_storage& storage,
const ConstBufferSequence& buffers, WriteHandler& handler)
: storage_(storage),
buffers_(buffers),
handler_(static_cast<WriteHandler&&>(handler))
{
}
buffered_write_some_handler(const buffered_write_some_handler& other)
: storage_(other.storage_),
buffers_(other.buffers_),
handler_(other.handler_)
{
}
buffered_write_some_handler(buffered_write_some_handler&& other)
: storage_(other.storage_),
buffers_(other.buffers_),
handler_(static_cast<WriteHandler&&>(other.handler_))
{
}
void operator()(const boost::system::error_code& ec, std::size_t)
{
if (ec)
{
const std::size_t length = 0;
static_cast<WriteHandler&&>(handler_)(ec, length);
}
else
{
using boost::asio::buffer_size;
std::size_t orig_size = storage_.size();
std::size_t space_avail = storage_.capacity() - orig_size;
std::size_t bytes_avail = buffer_size(buffers_);
std::size_t length = bytes_avail < space_avail
? bytes_avail : space_avail;
storage_.resize(orig_size + length);
const std::size_t bytes_copied = boost::asio::buffer_copy(
storage_.data() + orig_size, buffers_, length);
static_cast<WriteHandler&&>(handler_)(ec, bytes_copied);
}
}
//private:
detail::buffered_stream_storage& storage_;
ConstBufferSequence buffers_;
WriteHandler handler_;
};
template <typename ConstBufferSequence, typename WriteHandler>
inline bool asio_handler_is_continuation(
buffered_write_some_handler<
ConstBufferSequence, WriteHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Stream>
class initiate_async_buffered_write_some
{
public:
typedef typename remove_reference_t<
Stream>::lowest_layer_type::executor_type executor_type;
explicit initiate_async_buffered_write_some(
remove_reference_t<Stream>& next_layer)
: next_layer_(next_layer)
{
}
executor_type get_executor() const noexcept
{
return next_layer_.lowest_layer().get_executor();
}
template <typename WriteHandler, typename ConstBufferSequence>
void operator()(WriteHandler&& handler,
buffered_stream_storage* storage,
const ConstBufferSequence& buffers) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
using boost::asio::buffer_size;
non_const_lvalue<WriteHandler> handler2(handler);
if (buffer_size(buffers) == 0 || storage->size() < storage->capacity())
{
next_layer_.async_write_some(BOOST_ASIO_CONST_BUFFER(0, 0),
buffered_write_some_handler<ConstBufferSequence,
decay_t<WriteHandler>>(
*storage, buffers, handler2.value));
}
else
{
initiate_async_buffered_flush<Stream>(this->next_layer_)(
buffered_write_some_handler<ConstBufferSequence,
decay_t<WriteHandler>>(
*storage, buffers, handler2.value),
storage);
}
}
private:
remove_reference_t<Stream>& next_layer_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename ConstBufferSequence, typename WriteHandler,
typename DefaultCandidate>
struct associator<Associator,
detail::buffered_write_some_handler<ConstBufferSequence, WriteHandler>,
DefaultCandidate>
: Associator<WriteHandler, DefaultCandidate>
{
static typename Associator<WriteHandler, DefaultCandidate>::type get(
const detail::buffered_write_some_handler<
ConstBufferSequence, WriteHandler>& h) noexcept
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::buffered_write_some_handler<
ConstBufferSequence, WriteHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<WriteHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename Stream>
template <typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteHandler>
inline auto buffered_write_stream<Stream>::async_write_some(
const ConstBufferSequence& buffers, WriteHandler&& handler)
-> decltype(
async_initiate<WriteHandler,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_buffered_write_some<Stream>>(),
handler, declval<detail::buffered_stream_storage*>(), buffers))
{
return async_initiate<WriteHandler,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_buffered_write_some<Stream>(next_layer_),
handler, &storage_, buffers);
}
template <typename Stream>
template <typename ConstBufferSequence>
std::size_t buffered_write_stream<Stream>::copy(
const ConstBufferSequence& buffers)
{
using boost::asio::buffer_size;
std::size_t orig_size = storage_.size();
std::size_t space_avail = storage_.capacity() - orig_size;
std::size_t bytes_avail = buffer_size(buffers);
std::size_t length = bytes_avail < space_avail ? bytes_avail : space_avail;
storage_.resize(orig_size + length);
return boost::asio::buffer_copy(
storage_.data() + orig_size, buffers, length);
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_BUFFERED_WRITE_STREAM_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/consign.hpp | //
// impl/consign.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_CONSIGN_HPP
#define BOOST_ASIO_IMPL_CONSIGN_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/associator.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/utility.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
// Class to adapt a consign_t as a completion handler.
template <typename Handler, typename... Values>
class consign_handler
{
public:
typedef void result_type;
template <typename H>
consign_handler(H&& handler, std::tuple<Values...> values)
: handler_(static_cast<H&&>(handler)),
values_(static_cast<std::tuple<Values...>&&>(values))
{
}
template <typename... Args>
void operator()(Args&&... args)
{
static_cast<Handler&&>(handler_)(static_cast<Args&&>(args)...);
}
//private:
Handler handler_;
std::tuple<Values...> values_;
};
template <typename Handler>
inline bool asio_handler_is_continuation(
consign_handler<Handler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <typename CompletionToken, typename... Values, typename... Signatures>
struct async_result<consign_t<CompletionToken, Values...>, Signatures...>
: async_result<CompletionToken, Signatures...>
{
template <typename Initiation>
struct init_wrapper
{
init_wrapper(Initiation init)
: initiation_(static_cast<Initiation&&>(init))
{
}
template <typename Handler, typename... Args>
void operator()(Handler&& handler,
std::tuple<Values...> values, Args&&... args)
{
static_cast<Initiation&&>(initiation_)(
detail::consign_handler<decay_t<Handler>, Values...>(
static_cast<Handler&&>(handler),
static_cast<std::tuple<Values...>&&>(values)),
static_cast<Args&&>(args)...);
}
Initiation initiation_;
};
template <typename Initiation, typename RawCompletionToken, typename... Args>
static auto initiate(Initiation&& initiation,
RawCompletionToken&& token, Args&&... args)
-> decltype(
async_initiate<CompletionToken, Signatures...>(
init_wrapper<decay_t<Initiation>>(
static_cast<Initiation&&>(initiation)),
token.token_, static_cast<std::tuple<Values...>&&>(token.values_),
static_cast<Args&&>(args)...))
{
return async_initiate<CompletionToken, Signatures...>(
init_wrapper<decay_t<Initiation>>(
static_cast<Initiation&&>(initiation)),
token.token_, static_cast<std::tuple<Values...>&&>(token.values_),
static_cast<Args&&>(args)...);
}
};
template <template <typename, typename> class Associator,
typename Handler, typename... Values, typename DefaultCandidate>
struct associator<Associator,
detail::consign_handler<Handler, Values...>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::consign_handler<Handler, Values...>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::consign_handler<Handler, Values...>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_CONSIGN_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/system_executor.hpp | //
// impl/system_executor.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_SYSTEM_EXECUTOR_HPP
#define BOOST_ASIO_IMPL_SYSTEM_EXECUTOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/executor_op.hpp>
#include <boost/asio/detail/global.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/system_context.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename Blocking, typename Relationship, typename Allocator>
inline system_context&
basic_system_executor<Blocking, Relationship, Allocator>::query(
execution::context_t) noexcept
{
return detail::global<system_context>();
}
template <typename Blocking, typename Relationship, typename Allocator>
inline std::size_t
basic_system_executor<Blocking, Relationship, Allocator>::query(
execution::occupancy_t) const noexcept
{
return detail::global<system_context>().num_threads_;
}
template <typename Blocking, typename Relationship, typename Allocator>
template <typename Function>
inline void
basic_system_executor<Blocking, Relationship, Allocator>::do_execute(
Function&& f, execution::blocking_t::possibly_t) const
{
// Obtain a non-const instance of the function.
detail::non_const_lvalue<Function> f2(f);
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
{
#endif// !defined(BOOST_ASIO_NO_EXCEPTIONS)
detail::fenced_block b(detail::fenced_block::full);
static_cast<decay_t<Function>&&>(f2.value)();
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
catch (...)
{
std::terminate();
}
#endif// !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
template <typename Blocking, typename Relationship, typename Allocator>
template <typename Function>
inline void
basic_system_executor<Blocking, Relationship, Allocator>::do_execute(
Function&& f, execution::blocking_t::always_t) const
{
// Obtain a non-const instance of the function.
detail::non_const_lvalue<Function> f2(f);
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
{
#endif// !defined(BOOST_ASIO_NO_EXCEPTIONS)
detail::fenced_block b(detail::fenced_block::full);
static_cast<decay_t<Function>&&>(f2.value)();
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
catch (...)
{
std::terminate();
}
#endif// !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
template <typename Blocking, typename Relationship, typename Allocator>
template <typename Function>
void basic_system_executor<Blocking, Relationship, Allocator>::do_execute(
Function&& f, execution::blocking_t::never_t) const
{
system_context& ctx = detail::global<system_context>();
// Allocate and construct an operation to wrap the function.
typedef detail::executor_op<decay_t<Function>, Allocator> op;
typename op::ptr p = { detail::addressof(allocator_),
op::ptr::allocate(allocator_), 0 };
p.p = new (p.v) op(static_cast<Function&&>(f), allocator_);
if (is_same<Relationship, execution::relationship_t::continuation_t>::value)
{
BOOST_ASIO_HANDLER_CREATION((ctx, *p.p,
"system_executor", &ctx, 0, "execute(blk=never,rel=cont)"));
}
else
{
BOOST_ASIO_HANDLER_CREATION((ctx, *p.p,
"system_executor", &ctx, 0, "execute(blk=never,rel=fork)"));
}
ctx.scheduler_.post_immediate_completion(p.p,
is_same<Relationship, execution::relationship_t::continuation_t>::value);
p.v = p.p = 0;
}
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Blocking, typename Relationship, typename Allocator>
inline system_context& basic_system_executor<
Blocking, Relationship, Allocator>::context() const noexcept
{
return detail::global<system_context>();
}
template <typename Blocking, typename Relationship, typename Allocator>
template <typename Function, typename OtherAllocator>
void basic_system_executor<Blocking, Relationship, Allocator>::dispatch(
Function&& f, const OtherAllocator&) const
{
decay_t<Function>(static_cast<Function&&>(f))();
}
template <typename Blocking, typename Relationship, typename Allocator>
template <typename Function, typename OtherAllocator>
void basic_system_executor<Blocking, Relationship, Allocator>::post(
Function&& f, const OtherAllocator& a) const
{
system_context& ctx = detail::global<system_context>();
// Allocate and construct an operation to wrap the function.
typedef detail::executor_op<decay_t<Function>, OtherAllocator> op;
typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 };
p.p = new (p.v) op(static_cast<Function&&>(f), a);
BOOST_ASIO_HANDLER_CREATION((ctx, *p.p,
"system_executor", &this->context(), 0, "post"));
ctx.scheduler_.post_immediate_completion(p.p, false);
p.v = p.p = 0;
}
template <typename Blocking, typename Relationship, typename Allocator>
template <typename Function, typename OtherAllocator>
void basic_system_executor<Blocking, Relationship, Allocator>::defer(
Function&& f, const OtherAllocator& a) const
{
system_context& ctx = detail::global<system_context>();
// Allocate and construct an operation to wrap the function.
typedef detail::executor_op<decay_t<Function>, OtherAllocator> op;
typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 };
p.p = new (p.v) op(static_cast<Function&&>(f), a);
BOOST_ASIO_HANDLER_CREATION((ctx, *p.p,
"system_executor", &this->context(), 0, "defer"));
ctx.scheduler_.post_immediate_completion(p.p, true);
p.v = p.p = 0;
}
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_SYSTEM_EXECUTOR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/use_awaitable.hpp | //
// impl/use_awaitable.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_USE_AWAITABLE_HPP
#define BOOST_ASIO_IMPL_USE_AWAITABLE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/cancellation_signal.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
template <typename Executor, typename T>
class awaitable_handler_base
: public awaitable_thread<Executor>
{
public:
typedef void result_type;
typedef awaitable<T, Executor> awaitable_type;
// Construct from the entry point of a new thread of execution.
awaitable_handler_base(awaitable<awaitable_thread_entry_point, Executor> a,
const Executor& ex, cancellation_slot pcs, cancellation_state cs)
: awaitable_thread<Executor>(std::move(a), ex, pcs, cs)
{
}
// Transfer ownership from another awaitable_thread.
explicit awaitable_handler_base(awaitable_thread<Executor>* h)
: awaitable_thread<Executor>(std::move(*h))
{
}
protected:
awaitable_frame<T, Executor>* frame() noexcept
{
return static_cast<awaitable_frame<T, Executor>*>(
this->entry_point()->top_of_stack_);
}
};
template <typename, typename...>
class awaitable_handler;
template <typename Executor>
class awaitable_handler<Executor>
: public awaitable_handler_base<Executor, void>
{
public:
using awaitable_handler_base<Executor, void>::awaitable_handler_base;
void operator()()
{
this->frame()->attach_thread(this);
this->frame()->return_void();
this->frame()->clear_cancellation_slot();
this->frame()->pop_frame();
this->pump();
}
};
template <typename Executor>
class awaitable_handler<Executor, boost::system::error_code>
: public awaitable_handler_base<Executor, void>
{
public:
using awaitable_handler_base<Executor, void>::awaitable_handler_base;
void operator()(const boost::system::error_code& ec)
{
this->frame()->attach_thread(this);
if (ec)
this->frame()->set_error(ec);
else
this->frame()->return_void();
this->frame()->clear_cancellation_slot();
this->frame()->pop_frame();
this->pump();
}
};
template <typename Executor>
class awaitable_handler<Executor, std::exception_ptr>
: public awaitable_handler_base<Executor, void>
{
public:
using awaitable_handler_base<Executor, void>::awaitable_handler_base;
void operator()(std::exception_ptr ex)
{
this->frame()->attach_thread(this);
if (ex)
this->frame()->set_except(ex);
else
this->frame()->return_void();
this->frame()->clear_cancellation_slot();
this->frame()->pop_frame();
this->pump();
}
};
template <typename Executor, typename T>
class awaitable_handler<Executor, T>
: public awaitable_handler_base<Executor, T>
{
public:
using awaitable_handler_base<Executor, T>::awaitable_handler_base;
template <typename Arg>
void operator()(Arg&& arg)
{
this->frame()->attach_thread(this);
this->frame()->return_value(std::forward<Arg>(arg));
this->frame()->clear_cancellation_slot();
this->frame()->pop_frame();
this->pump();
}
};
template <typename Executor, typename T>
class awaitable_handler<Executor, boost::system::error_code, T>
: public awaitable_handler_base<Executor, T>
{
public:
using awaitable_handler_base<Executor, T>::awaitable_handler_base;
template <typename Arg>
void operator()(const boost::system::error_code& ec, Arg&& arg)
{
this->frame()->attach_thread(this);
if (ec)
this->frame()->set_error(ec);
else
this->frame()->return_value(std::forward<Arg>(arg));
this->frame()->clear_cancellation_slot();
this->frame()->pop_frame();
this->pump();
}
};
template <typename Executor, typename T>
class awaitable_handler<Executor, std::exception_ptr, T>
: public awaitable_handler_base<Executor, T>
{
public:
using awaitable_handler_base<Executor, T>::awaitable_handler_base;
template <typename Arg>
void operator()(std::exception_ptr ex, Arg&& arg)
{
this->frame()->attach_thread(this);
if (ex)
this->frame()->set_except(ex);
else
this->frame()->return_value(std::forward<Arg>(arg));
this->frame()->clear_cancellation_slot();
this->frame()->pop_frame();
this->pump();
}
};
template <typename Executor, typename... Ts>
class awaitable_handler
: public awaitable_handler_base<Executor, std::tuple<Ts...>>
{
public:
using awaitable_handler_base<Executor,
std::tuple<Ts...>>::awaitable_handler_base;
template <typename... Args>
void operator()(Args&&... args)
{
this->frame()->attach_thread(this);
this->frame()->return_values(std::forward<Args>(args)...);
this->frame()->clear_cancellation_slot();
this->frame()->pop_frame();
this->pump();
}
};
template <typename Executor, typename... Ts>
class awaitable_handler<Executor, boost::system::error_code, Ts...>
: public awaitable_handler_base<Executor, std::tuple<Ts...>>
{
public:
using awaitable_handler_base<Executor,
std::tuple<Ts...>>::awaitable_handler_base;
template <typename... Args>
void operator()(const boost::system::error_code& ec, Args&&... args)
{
this->frame()->attach_thread(this);
if (ec)
this->frame()->set_error(ec);
else
this->frame()->return_values(std::forward<Args>(args)...);
this->frame()->clear_cancellation_slot();
this->frame()->pop_frame();
this->pump();
}
};
template <typename Executor, typename... Ts>
class awaitable_handler<Executor, std::exception_ptr, Ts...>
: public awaitable_handler_base<Executor, std::tuple<Ts...>>
{
public:
using awaitable_handler_base<Executor,
std::tuple<Ts...>>::awaitable_handler_base;
template <typename... Args>
void operator()(std::exception_ptr ex, Args&&... args)
{
this->frame()->attach_thread(this);
if (ex)
this->frame()->set_except(ex);
else
this->frame()->return_values(std::forward<Args>(args)...);
this->frame()->clear_cancellation_slot();
this->frame()->pop_frame();
this->pump();
}
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
#if defined(_MSC_VER)
template <typename T>
T dummy_return()
{
return std::move(*static_cast<T*>(nullptr));
}
template <>
inline void dummy_return()
{
}
#endif // defined(_MSC_VER)
template <typename Executor, typename R, typename... Args>
class async_result<use_awaitable_t<Executor>, R(Args...)>
{
public:
typedef typename detail::awaitable_handler<
Executor, decay_t<Args>...> handler_type;
typedef typename handler_type::awaitable_type return_type;
template <typename Initiation, typename... InitArgs>
#if defined(__APPLE_CC__) && (__clang_major__ == 13)
__attribute__((noinline))
#endif // defined(__APPLE_CC__) && (__clang_major__ == 13)
static handler_type* do_init(
detail::awaitable_frame_base<Executor>* frame, Initiation& initiation,
use_awaitable_t<Executor> u, InitArgs&... args)
{
(void)u;
BOOST_ASIO_HANDLER_LOCATION((u.file_name_, u.line_, u.function_name_));
handler_type handler(frame->detach_thread());
std::move(initiation)(std::move(handler), std::move(args)...);
return nullptr;
}
template <typename Initiation, typename... InitArgs>
static return_type initiate(Initiation initiation,
use_awaitable_t<Executor> u, InitArgs... args)
{
co_await [&] (auto* frame)
{
return do_init(frame, initiation, u, args...);
};
for (;;) {} // Never reached.
#if defined(_MSC_VER)
co_return dummy_return<typename return_type::value_type>();
#endif // defined(_MSC_VER)
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_USE_AWAITABLE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/thread_pool.hpp | //
// impl/thread_pool.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_THREAD_POOL_HPP
#define BOOST_ASIO_IMPL_THREAD_POOL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/blocking_executor_op.hpp>
#include <boost/asio/detail/executor_op.hpp>
#include <boost/asio/detail/fenced_block.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution_context.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
inline thread_pool::executor_type
thread_pool::get_executor() noexcept
{
return executor_type(*this);
}
inline thread_pool::executor_type
thread_pool::executor() noexcept
{
return executor_type(*this);
}
template <typename Allocator, unsigned int Bits>
thread_pool::basic_executor_type<Allocator, Bits>&
thread_pool::basic_executor_type<Allocator, Bits>::operator=(
const basic_executor_type& other) noexcept
{
if (this != &other)
{
thread_pool* old_thread_pool = pool_;
pool_ = other.pool_;
allocator_ = other.allocator_;
bits_ = other.bits_;
if (Bits & outstanding_work_tracked)
{
if (pool_)
pool_->scheduler_.work_started();
if (old_thread_pool)
old_thread_pool->scheduler_.work_finished();
}
}
return *this;
}
template <typename Allocator, unsigned int Bits>
thread_pool::basic_executor_type<Allocator, Bits>&
thread_pool::basic_executor_type<Allocator, Bits>::operator=(
basic_executor_type&& other) noexcept
{
if (this != &other)
{
thread_pool* old_thread_pool = pool_;
pool_ = other.pool_;
allocator_ = std::move(other.allocator_);
bits_ = other.bits_;
if (Bits & outstanding_work_tracked)
{
other.pool_ = 0;
if (old_thread_pool)
old_thread_pool->scheduler_.work_finished();
}
}
return *this;
}
template <typename Allocator, unsigned int Bits>
inline bool thread_pool::basic_executor_type<Allocator,
Bits>::running_in_this_thread() const noexcept
{
return pool_->scheduler_.can_dispatch();
}
template <typename Allocator, unsigned int Bits>
template <typename Function>
void thread_pool::basic_executor_type<Allocator,
Bits>::do_execute(Function&& f, false_type) const
{
typedef decay_t<Function> function_type;
// Invoke immediately if the blocking.possibly property is enabled and we are
// already inside the thread pool.
if ((bits_ & blocking_never) == 0 && pool_->scheduler_.can_dispatch())
{
// Make a local, non-const copy of the function.
function_type tmp(static_cast<Function&&>(f));
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
{
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
detail::fenced_block b(detail::fenced_block::full);
static_cast<function_type&&>(tmp)();
return;
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
catch (...)
{
pool_->scheduler_.capture_current_exception();
return;
}
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
// Allocate and construct an operation to wrap the function.
typedef detail::executor_op<function_type, Allocator> op;
typename op::ptr p = { detail::addressof(allocator_),
op::ptr::allocate(allocator_), 0 };
p.p = new (p.v) op(static_cast<Function&&>(f), allocator_);
if ((bits_ & relationship_continuation) != 0)
{
BOOST_ASIO_HANDLER_CREATION((*pool_, *p.p,
"thread_pool", pool_, 0, "execute(blk=never,rel=cont)"));
}
else
{
BOOST_ASIO_HANDLER_CREATION((*pool_, *p.p,
"thread_pool", pool_, 0, "execute(blk=never,rel=fork)"));
}
pool_->scheduler_.post_immediate_completion(p.p,
(bits_ & relationship_continuation) != 0);
p.v = p.p = 0;
}
template <typename Allocator, unsigned int Bits>
template <typename Function>
void thread_pool::basic_executor_type<Allocator,
Bits>::do_execute(Function&& f, true_type) const
{
// Obtain a non-const instance of the function.
detail::non_const_lvalue<Function> f2(f);
// Invoke immediately if we are already inside the thread pool.
if (pool_->scheduler_.can_dispatch())
{
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
{
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
detail::fenced_block b(detail::fenced_block::full);
static_cast<decay_t<Function>&&>(f2.value)();
return;
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
catch (...)
{
std::terminate();
}
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
// Construct an operation to wrap the function.
typedef decay_t<Function> function_type;
detail::blocking_executor_op<function_type> op(f2.value);
BOOST_ASIO_HANDLER_CREATION((*pool_, op,
"thread_pool", pool_, 0, "execute(blk=always)"));
pool_->scheduler_.post_immediate_completion(&op, false);
op.wait();
}
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Allocator, unsigned int Bits>
inline thread_pool& thread_pool::basic_executor_type<
Allocator, Bits>::context() const noexcept
{
return *pool_;
}
template <typename Allocator, unsigned int Bits>
inline void thread_pool::basic_executor_type<Allocator,
Bits>::on_work_started() const noexcept
{
pool_->scheduler_.work_started();
}
template <typename Allocator, unsigned int Bits>
inline void thread_pool::basic_executor_type<Allocator,
Bits>::on_work_finished() const noexcept
{
pool_->scheduler_.work_finished();
}
template <typename Allocator, unsigned int Bits>
template <typename Function, typename OtherAllocator>
void thread_pool::basic_executor_type<Allocator, Bits>::dispatch(
Function&& f, const OtherAllocator& a) const
{
typedef decay_t<Function> function_type;
// Invoke immediately if we are already inside the thread pool.
if (pool_->scheduler_.can_dispatch())
{
// Make a local, non-const copy of the function.
function_type tmp(static_cast<Function&&>(f));
detail::fenced_block b(detail::fenced_block::full);
static_cast<function_type&&>(tmp)();
return;
}
// Allocate and construct an operation to wrap the function.
typedef detail::executor_op<function_type, OtherAllocator> op;
typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 };
p.p = new (p.v) op(static_cast<Function&&>(f), a);
BOOST_ASIO_HANDLER_CREATION((*pool_, *p.p,
"thread_pool", pool_, 0, "dispatch"));
pool_->scheduler_.post_immediate_completion(p.p, false);
p.v = p.p = 0;
}
template <typename Allocator, unsigned int Bits>
template <typename Function, typename OtherAllocator>
void thread_pool::basic_executor_type<Allocator, Bits>::post(
Function&& f, const OtherAllocator& a) const
{
typedef decay_t<Function> function_type;
// Allocate and construct an operation to wrap the function.
typedef detail::executor_op<function_type, OtherAllocator> op;
typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 };
p.p = new (p.v) op(static_cast<Function&&>(f), a);
BOOST_ASIO_HANDLER_CREATION((*pool_, *p.p,
"thread_pool", pool_, 0, "post"));
pool_->scheduler_.post_immediate_completion(p.p, false);
p.v = p.p = 0;
}
template <typename Allocator, unsigned int Bits>
template <typename Function, typename OtherAllocator>
void thread_pool::basic_executor_type<Allocator, Bits>::defer(
Function&& f, const OtherAllocator& a) const
{
typedef decay_t<Function> function_type;
// Allocate and construct an operation to wrap the function.
typedef detail::executor_op<function_type, OtherAllocator> op;
typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 };
p.p = new (p.v) op(static_cast<Function&&>(f), a);
BOOST_ASIO_HANDLER_CREATION((*pool_, *p.p,
"thread_pool", pool_, 0, "defer"));
pool_->scheduler_.post_immediate_completion(p.p, true);
p.v = p.p = 0;
}
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_THREAD_POOL_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/append.hpp | //
// impl/append.hpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_APPEND_HPP
#define BOOST_ASIO_IMPL_APPEND_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/associator.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/utility.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
// Class to adapt an append_t as a completion handler.
template <typename Handler, typename... Values>
class append_handler
{
public:
typedef void result_type;
template <typename H>
append_handler(H&& handler, std::tuple<Values...> values)
: handler_(static_cast<H&&>(handler)),
values_(static_cast<std::tuple<Values...>&&>(values))
{
}
template <typename... Args>
void operator()(Args&&... args)
{
this->invoke(
index_sequence_for<Values...>{},
static_cast<Args&&>(args)...);
}
template <std::size_t... I, typename... Args>
void invoke(index_sequence<I...>, Args&&... args)
{
static_cast<Handler&&>(handler_)(
static_cast<Args&&>(args)...,
static_cast<Values&&>(std::get<I>(values_))...);
}
//private:
Handler handler_;
std::tuple<Values...> values_;
};
template <typename Handler>
inline bool asio_handler_is_continuation(
append_handler<Handler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Signature, typename... Values>
struct append_signature;
template <typename R, typename... Args, typename... Values>
struct append_signature<R(Args...), Values...>
{
typedef R type(decay_t<Args>..., Values...);
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <typename CompletionToken, typename... Values, typename Signature>
struct async_result<append_t<CompletionToken, Values...>, Signature>
: async_result<CompletionToken,
typename detail::append_signature<
Signature, Values...>::type>
{
typedef typename detail::append_signature<
Signature, Values...>::type signature;
template <typename Initiation>
struct init_wrapper
{
init_wrapper(Initiation init)
: initiation_(static_cast<Initiation&&>(init))
{
}
template <typename Handler, typename... Args>
void operator()(Handler&& handler,
std::tuple<Values...> values, Args&&... args)
{
static_cast<Initiation&&>(initiation_)(
detail::append_handler<decay_t<Handler>, Values...>(
static_cast<Handler&&>(handler),
static_cast<std::tuple<Values...>&&>(values)),
static_cast<Args&&>(args)...);
}
Initiation initiation_;
};
template <typename Initiation, typename RawCompletionToken, typename... Args>
static auto initiate(Initiation&& initiation,
RawCompletionToken&& token, Args&&... args)
-> decltype(
async_initiate<CompletionToken, signature>(
declval<init_wrapper<decay_t<Initiation>>>(),
token.token_,
static_cast<std::tuple<Values...>&&>(token.values_),
static_cast<Args&&>(args)...))
{
return async_initiate<CompletionToken, signature>(
init_wrapper<decay_t<Initiation>>(
static_cast<Initiation&&>(initiation)),
token.token_,
static_cast<std::tuple<Values...>&&>(token.values_),
static_cast<Args&&>(args)...);
}
};
template <template <typename, typename> class Associator,
typename Handler, typename... Values, typename DefaultCandidate>
struct associator<Associator,
detail::append_handler<Handler, Values...>, DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::append_handler<Handler, Values...>& h) noexcept
{
return Associator<Handler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::append_handler<Handler, Values...>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_APPEND_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/read_at.hpp | //
// impl/read_at.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_READ_AT_HPP
#define BOOST_ASIO_IMPL_READ_AT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <algorithm>
#include <boost/asio/associator.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/detail/array_fwd.hpp>
#include <boost/asio/detail/base_from_cancellation_state.hpp>
#include <boost/asio/detail/base_from_completion_cond.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/consuming_buffers.hpp>
#include <boost/asio/detail/dependent_type.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_tracking.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail
{
template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence,
typename MutableBufferIterator, typename CompletionCondition>
std::size_t read_at_buffer_sequence(SyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
const MutableBufferIterator&, CompletionCondition completion_condition,
boost::system::error_code& ec)
{
ec = boost::system::error_code();
boost::asio::detail::consuming_buffers<mutable_buffer,
MutableBufferSequence, MutableBufferIterator> tmp(buffers);
while (!tmp.empty())
{
if (std::size_t max_size = detail::adapt_completion_condition_result(
completion_condition(ec, tmp.total_consumed())))
{
tmp.consume(d.read_some_at(offset + tmp.total_consumed(),
tmp.prepare(max_size), ec));
}
else
break;
}
return tmp.total_consumed();
}
} // namespace detail
template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence,
typename CompletionCondition>
std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
return detail::read_at_buffer_sequence(d, offset, buffers,
boost::asio::buffer_sequence_begin(buffers),
static_cast<CompletionCondition&&>(completion_condition), ec);
}
template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_at(
d, offset, buffers, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "read_at");
return bytes_transferred;
}
template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
boost::system::error_code& ec)
{
return read_at(d, offset, buffers, transfer_all(), ec);
}
template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence,
typename CompletionCondition>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_at(d, offset, buffers,
static_cast<CompletionCondition&&>(completion_condition), ec);
boost::asio::detail::throw_error(ec, "read_at");
return bytes_transferred;
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
template <typename SyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition>
std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, boost::system::error_code& ec)
{
ec = boost::system::error_code();
std::size_t total_transferred = 0;
std::size_t max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
std::size_t bytes_available = read_size_helper(b, max_size);
while (bytes_available > 0)
{
std::size_t bytes_transferred = d.read_some_at(
offset + total_transferred, b.prepare(bytes_available), ec);
b.commit(bytes_transferred);
total_transferred += bytes_transferred;
max_size = detail::adapt_completion_condition_result(
completion_condition(ec, total_transferred));
bytes_available = read_size_helper(b, max_size);
}
return total_transferred;
}
template <typename SyncRandomAccessReadDevice, typename Allocator>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_at(
d, offset, b, transfer_all(), ec);
boost::asio::detail::throw_error(ec, "read_at");
return bytes_transferred;
}
template <typename SyncRandomAccessReadDevice, typename Allocator>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
boost::system::error_code& ec)
{
return read_at(d, offset, b, transfer_all(), ec);
}
template <typename SyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition>
inline std::size_t read_at(SyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition)
{
boost::system::error_code ec;
std::size_t bytes_transferred = read_at(d, offset, b,
static_cast<CompletionCondition&&>(completion_condition), ec);
boost::asio::detail::throw_error(ec, "read_at");
return bytes_transferred;
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
namespace detail
{
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename MutableBufferIterator,
typename CompletionCondition, typename ReadHandler>
class read_at_op
: public base_from_cancellation_state<ReadHandler>,
base_from_completion_cond<CompletionCondition>
{
public:
read_at_op(AsyncRandomAccessReadDevice& device,
uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition& completion_condition, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
base_from_completion_cond<CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
buffers_(buffers),
start_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_at_op(const read_at_op& other)
: base_from_cancellation_state<ReadHandler>(other),
base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
buffers_(other.buffers_),
start_(other.start_),
handler_(other.handler_)
{
}
read_at_op(read_at_op&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
base_from_completion_cond<CompletionCondition>(
static_cast<base_from_completion_cond<CompletionCondition>&&>(other)),
device_(other.device_),
offset_(other.offset_),
buffers_(static_cast<buffers_type&&>(other.buffers_)),
start_(other.start_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t max_size;
switch (start_ = start)
{
case 1:
max_size = this->check_for_completion(ec, buffers_.total_consumed());
for (;;)
{
{
BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_read_at"));
device_.async_read_some_at(
offset_ + buffers_.total_consumed(), buffers_.prepare(max_size),
static_cast<read_at_op&&>(*this));
}
return; default:
buffers_.consume(bytes_transferred);
if ((!ec && bytes_transferred == 0) || buffers_.empty())
break;
max_size = this->check_for_completion(ec, buffers_.total_consumed());
if (max_size == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = boost::asio::error::operation_aborted;
break;
}
}
static_cast<ReadHandler&&>(handler_)(
static_cast<const boost::system::error_code&>(ec),
static_cast<const std::size_t&>(buffers_.total_consumed()));
}
}
//private:
typedef boost::asio::detail::consuming_buffers<mutable_buffer,
MutableBufferSequence, MutableBufferIterator> buffers_type;
AsyncRandomAccessReadDevice& device_;
uint64_t offset_;
buffers_type buffers_;
int start_;
ReadHandler handler_;
};
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename MutableBufferIterator,
typename CompletionCondition, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
MutableBufferIterator, CompletionCondition, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename MutableBufferIterator,
typename CompletionCondition, typename ReadHandler>
inline void start_read_at_op(AsyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
const MutableBufferIterator&, CompletionCondition& completion_condition,
ReadHandler& handler)
{
detail::read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
MutableBufferIterator, CompletionCondition, ReadHandler>(
d, offset, buffers, completion_condition, handler)(
boost::system::error_code(), 0, 1);
}
template <typename AsyncRandomAccessReadDevice>
class initiate_async_read_at
{
public:
typedef typename AsyncRandomAccessReadDevice::executor_type executor_type;
explicit initiate_async_read_at(AsyncRandomAccessReadDevice& device)
: device_(device)
{
}
executor_type get_executor() const noexcept
{
return device_.get_executor();
}
template <typename ReadHandler, typename MutableBufferSequence,
typename CompletionCondition>
void operator()(ReadHandler&& handler,
uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition&& completion_cond) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
start_read_at_op(device_, offset, buffers,
boost::asio::buffer_sequence_begin(buffers),
completion_cond2.value, handler2.value);
}
private:
AsyncRandomAccessReadDevice& device_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
typename MutableBufferIterator, typename CompletionCondition,
typename ReadHandler, typename DefaultCandidate>
struct associator<Associator,
detail::read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
MutableBufferIterator, CompletionCondition, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_at_op<AsyncRandomAccessReadDevice,
MutableBufferSequence, MutableBufferIterator,
CompletionCondition, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_at_op<AsyncRandomAccessReadDevice,
MutableBufferSequence, MutableBufferIterator,
CompletionCondition, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition, ReadToken&& token)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_at<AsyncRandomAccessReadDevice>>(),
token, offset, buffers,
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_at<AsyncRandomAccessReadDevice>(d),
token, offset, buffers,
static_cast<CompletionCondition&&>(completion_condition));
}
template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers, ReadToken&& token)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_at<AsyncRandomAccessReadDevice>>(),
token, offset, buffers, transfer_all()))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_at<AsyncRandomAccessReadDevice>(d),
token, offset, buffers, transfer_all());
}
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
#if !defined(BOOST_ASIO_NO_IOSTREAM)
namespace detail
{
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition, typename ReadHandler>
class read_at_streambuf_op
: public base_from_cancellation_state<ReadHandler>,
base_from_completion_cond<CompletionCondition>
{
public:
read_at_streambuf_op(AsyncRandomAccessReadDevice& device,
uint64_t offset, basic_streambuf<Allocator>& streambuf,
CompletionCondition& completion_condition, ReadHandler& handler)
: base_from_cancellation_state<ReadHandler>(
handler, enable_partial_cancellation()),
base_from_completion_cond<CompletionCondition>(completion_condition),
device_(device),
offset_(offset),
streambuf_(streambuf),
start_(0),
total_transferred_(0),
handler_(static_cast<ReadHandler&&>(handler))
{
}
read_at_streambuf_op(const read_at_streambuf_op& other)
: base_from_cancellation_state<ReadHandler>(other),
base_from_completion_cond<CompletionCondition>(other),
device_(other.device_),
offset_(other.offset_),
streambuf_(other.streambuf_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(other.handler_)
{
}
read_at_streambuf_op(read_at_streambuf_op&& other)
: base_from_cancellation_state<ReadHandler>(
static_cast<base_from_cancellation_state<ReadHandler>&&>(other)),
base_from_completion_cond<CompletionCondition>(
static_cast<base_from_completion_cond<CompletionCondition>&&>(other)),
device_(other.device_),
offset_(other.offset_),
streambuf_(other.streambuf_),
start_(other.start_),
total_transferred_(other.total_transferred_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(boost::system::error_code ec,
std::size_t bytes_transferred, int start = 0)
{
std::size_t max_size, bytes_available;
switch (start_ = start)
{
case 1:
max_size = this->check_for_completion(ec, total_transferred_);
bytes_available = read_size_helper(streambuf_, max_size);
for (;;)
{
{
BOOST_ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_read_at"));
device_.async_read_some_at(offset_ + total_transferred_,
streambuf_.prepare(bytes_available),
static_cast<read_at_streambuf_op&&>(*this));
}
return; default:
total_transferred_ += bytes_transferred;
streambuf_.commit(bytes_transferred);
max_size = this->check_for_completion(ec, total_transferred_);
bytes_available = read_size_helper(streambuf_, max_size);
if ((!ec && bytes_transferred == 0) || bytes_available == 0)
break;
if (this->cancelled() != cancellation_type::none)
{
ec = boost::asio::error::operation_aborted;
break;
}
}
static_cast<ReadHandler&&>(handler_)(
static_cast<const boost::system::error_code&>(ec),
static_cast<const std::size_t&>(total_transferred_));
}
}
//private:
AsyncRandomAccessReadDevice& device_;
uint64_t offset_;
boost::asio::basic_streambuf<Allocator>& streambuf_;
int start_;
std::size_t total_transferred_;
ReadHandler handler_;
};
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline bool asio_handler_is_continuation(
read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
return this_handler->start_ == 0 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename AsyncRandomAccessReadDevice>
class initiate_async_read_at_streambuf
{
public:
typedef typename AsyncRandomAccessReadDevice::executor_type executor_type;
explicit initiate_async_read_at_streambuf(
AsyncRandomAccessReadDevice& device)
: device_(device)
{
}
executor_type get_executor() const noexcept
{
return device_.get_executor();
}
template <typename ReadHandler,
typename Allocator, typename CompletionCondition>
void operator()(ReadHandler&& handler,
uint64_t offset, basic_streambuf<Allocator>* b,
CompletionCondition&& completion_cond) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
non_const_lvalue<CompletionCondition> completion_cond2(completion_cond);
read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, decay_t<ReadHandler>>(
device_, offset, *b, completion_cond2.value, handler2.value)(
boost::system::error_code(), 0, 1);
}
private:
AsyncRandomAccessReadDevice& device_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename AsyncRandomAccessReadDevice, typename Executor,
typename CompletionCondition, typename ReadHandler,
typename DefaultCandidate>
struct associator<Associator,
detail::read_at_streambuf_op<AsyncRandomAccessReadDevice,
Executor, CompletionCondition, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::read_at_streambuf_op<AsyncRandomAccessReadDevice,
Executor, CompletionCondition, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::read_at_streambuf_op<AsyncRandomAccessReadDevice,
Executor, CompletionCondition, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename AsyncRandomAccessReadDevice,
typename Allocator, typename CompletionCondition,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition, ReadToken&& token)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_at_streambuf<
AsyncRandomAccessReadDevice>>(),
token, offset, &b,
static_cast<CompletionCondition&&>(completion_condition)))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_at_streambuf<AsyncRandomAccessReadDevice>(d),
token, offset, &b,
static_cast<CompletionCondition&&>(completion_condition));
}
template <typename AsyncRandomAccessReadDevice, typename Allocator,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline auto async_read_at(AsyncRandomAccessReadDevice& d, uint64_t offset,
boost::asio::basic_streambuf<Allocator>& b, ReadToken&& token)
-> decltype(
async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_read_at_streambuf<
AsyncRandomAccessReadDevice>>(),
token, offset, &b, transfer_all()))
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_at_streambuf<AsyncRandomAccessReadDevice>(d),
token, offset, &b, transfer_all());
}
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_READ_AT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/io_context.hpp | //
// impl/io_context.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_IO_CONTEXT_HPP
#define BOOST_ASIO_IMPL_IO_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/completion_handler.hpp>
#include <boost/asio/detail/executor_op.hpp>
#include <boost/asio/detail/fenced_block.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/service_registry.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if !defined(GENERATING_DOCUMENTATION)
template <typename Service>
inline Service& use_service(io_context& ioc)
{
// Check that Service meets the necessary type requirements.
(void)static_cast<execution_context::service*>(static_cast<Service*>(0));
(void)static_cast<const execution_context::id*>(&Service::id);
return ioc.service_registry_->template use_service<Service>(ioc);
}
template <>
inline detail::io_context_impl& use_service<detail::io_context_impl>(
io_context& ioc)
{
return ioc.impl_;
}
#endif // !defined(GENERATING_DOCUMENTATION)
inline io_context::executor_type
io_context::get_executor() noexcept
{
return executor_type(*this);
}
template <typename Rep, typename Period>
std::size_t io_context::run_for(
const chrono::duration<Rep, Period>& rel_time)
{
return this->run_until(chrono::steady_clock::now() + rel_time);
}
template <typename Clock, typename Duration>
std::size_t io_context::run_until(
const chrono::time_point<Clock, Duration>& abs_time)
{
std::size_t n = 0;
while (this->run_one_until(abs_time))
if (n != (std::numeric_limits<std::size_t>::max)())
++n;
return n;
}
template <typename Rep, typename Period>
std::size_t io_context::run_one_for(
const chrono::duration<Rep, Period>& rel_time)
{
return this->run_one_until(chrono::steady_clock::now() + rel_time);
}
template <typename Clock, typename Duration>
std::size_t io_context::run_one_until(
const chrono::time_point<Clock, Duration>& abs_time)
{
typename Clock::time_point now = Clock::now();
while (now < abs_time)
{
typename Clock::duration rel_time = abs_time - now;
if (rel_time > chrono::seconds(1))
rel_time = chrono::seconds(1);
boost::system::error_code ec;
std::size_t s = impl_.wait_one(
static_cast<long>(chrono::duration_cast<
chrono::microseconds>(rel_time).count()), ec);
boost::asio::detail::throw_error(ec);
if (s || impl_.stopped())
return s;
now = Clock::now();
}
return 0;
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
inline void io_context::reset()
{
restart();
}
struct io_context::initiate_dispatch
{
template <typename LegacyCompletionHandler>
void operator()(LegacyCompletionHandler&& handler,
io_context* self) const
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a LegacyCompletionHandler.
BOOST_ASIO_LEGACY_COMPLETION_HANDLER_CHECK(
LegacyCompletionHandler, handler) type_check;
detail::non_const_lvalue<LegacyCompletionHandler> handler2(handler);
if (self->impl_.can_dispatch())
{
detail::fenced_block b(detail::fenced_block::full);
static_cast<decay_t<LegacyCompletionHandler>&&>(handler2.value)();
}
else
{
// Allocate and construct an operation to wrap the handler.
typedef detail::completion_handler<
decay_t<LegacyCompletionHandler>, executor_type> op;
typename op::ptr p = { detail::addressof(handler2.value),
op::ptr::allocate(handler2.value), 0 };
p.p = new (p.v) op(handler2.value, self->get_executor());
BOOST_ASIO_HANDLER_CREATION((*self, *p.p,
"io_context", self, 0, "dispatch"));
self->impl_.do_dispatch(p.p);
p.v = p.p = 0;
}
}
};
template <typename LegacyCompletionHandler>
auto io_context::dispatch(LegacyCompletionHandler&& handler)
-> decltype(
async_initiate<LegacyCompletionHandler, void ()>(
declval<initiate_dispatch>(), handler, this))
{
return async_initiate<LegacyCompletionHandler, void ()>(
initiate_dispatch(), handler, this);
}
struct io_context::initiate_post
{
template <typename LegacyCompletionHandler>
void operator()(LegacyCompletionHandler&& handler,
io_context* self) const
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a LegacyCompletionHandler.
BOOST_ASIO_LEGACY_COMPLETION_HANDLER_CHECK(
LegacyCompletionHandler, handler) type_check;
detail::non_const_lvalue<LegacyCompletionHandler> handler2(handler);
bool is_continuation =
boost_asio_handler_cont_helpers::is_continuation(handler2.value);
// Allocate and construct an operation to wrap the handler.
typedef detail::completion_handler<
decay_t<LegacyCompletionHandler>, executor_type> op;
typename op::ptr p = { detail::addressof(handler2.value),
op::ptr::allocate(handler2.value), 0 };
p.p = new (p.v) op(handler2.value, self->get_executor());
BOOST_ASIO_HANDLER_CREATION((*self, *p.p,
"io_context", self, 0, "post"));
self->impl_.post_immediate_completion(p.p, is_continuation);
p.v = p.p = 0;
}
};
template <typename LegacyCompletionHandler>
auto io_context::post(LegacyCompletionHandler&& handler)
-> decltype(
async_initiate<LegacyCompletionHandler, void ()>(
declval<initiate_post>(), handler, this))
{
return async_initiate<LegacyCompletionHandler, void ()>(
initiate_post(), handler, this);
}
template <typename Handler>
#if defined(GENERATING_DOCUMENTATION)
unspecified
#else
inline detail::wrapped_handler<io_context&, Handler>
#endif
io_context::wrap(Handler handler)
{
return detail::wrapped_handler<io_context&, Handler>(*this, handler);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Allocator, uintptr_t Bits>
io_context::basic_executor_type<Allocator, Bits>&
io_context::basic_executor_type<Allocator, Bits>::operator=(
const basic_executor_type& other) noexcept
{
if (this != &other)
{
static_cast<Allocator&>(*this) = static_cast<const Allocator&>(other);
io_context* old_io_context = context_ptr();
target_ = other.target_;
if (Bits & outstanding_work_tracked)
{
if (context_ptr())
context_ptr()->impl_.work_started();
if (old_io_context)
old_io_context->impl_.work_finished();
}
}
return *this;
}
template <typename Allocator, uintptr_t Bits>
io_context::basic_executor_type<Allocator, Bits>&
io_context::basic_executor_type<Allocator, Bits>::operator=(
basic_executor_type&& other) noexcept
{
if (this != &other)
{
static_cast<Allocator&>(*this) = static_cast<Allocator&&>(other);
io_context* old_io_context = context_ptr();
target_ = other.target_;
if (Bits & outstanding_work_tracked)
{
other.target_ = 0;
if (old_io_context)
old_io_context->impl_.work_finished();
}
}
return *this;
}
template <typename Allocator, uintptr_t Bits>
inline bool io_context::basic_executor_type<Allocator,
Bits>::running_in_this_thread() const noexcept
{
return context_ptr()->impl_.can_dispatch();
}
template <typename Allocator, uintptr_t Bits>
template <typename Function>
void io_context::basic_executor_type<Allocator, Bits>::execute(
Function&& f) const
{
typedef decay_t<Function> function_type;
// Invoke immediately if the blocking.possibly property is enabled and we are
// already inside the thread pool.
if ((bits() & blocking_never) == 0 && context_ptr()->impl_.can_dispatch())
{
// Make a local, non-const copy of the function.
function_type tmp(static_cast<Function&&>(f));
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
{
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
detail::fenced_block b(detail::fenced_block::full);
static_cast<function_type&&>(tmp)();
return;
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
catch (...)
{
context_ptr()->impl_.capture_current_exception();
return;
}
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
// Allocate and construct an operation to wrap the function.
typedef detail::executor_op<function_type, Allocator, detail::operation> op;
typename op::ptr p = {
detail::addressof(static_cast<const Allocator&>(*this)),
op::ptr::allocate(static_cast<const Allocator&>(*this)), 0 };
p.p = new (p.v) op(static_cast<Function&&>(f),
static_cast<const Allocator&>(*this));
BOOST_ASIO_HANDLER_CREATION((*context_ptr(), *p.p,
"io_context", context_ptr(), 0, "execute"));
context_ptr()->impl_.post_immediate_completion(p.p,
(bits() & relationship_continuation) != 0);
p.v = p.p = 0;
}
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Allocator, uintptr_t Bits>
inline io_context& io_context::basic_executor_type<
Allocator, Bits>::context() const noexcept
{
return *context_ptr();
}
template <typename Allocator, uintptr_t Bits>
inline void io_context::basic_executor_type<Allocator,
Bits>::on_work_started() const noexcept
{
context_ptr()->impl_.work_started();
}
template <typename Allocator, uintptr_t Bits>
inline void io_context::basic_executor_type<Allocator,
Bits>::on_work_finished() const noexcept
{
context_ptr()->impl_.work_finished();
}
template <typename Allocator, uintptr_t Bits>
template <typename Function, typename OtherAllocator>
void io_context::basic_executor_type<Allocator, Bits>::dispatch(
Function&& f, const OtherAllocator& a) const
{
typedef decay_t<Function> function_type;
// Invoke immediately if we are already inside the thread pool.
if (context_ptr()->impl_.can_dispatch())
{
// Make a local, non-const copy of the function.
function_type tmp(static_cast<Function&&>(f));
detail::fenced_block b(detail::fenced_block::full);
static_cast<function_type&&>(tmp)();
return;
}
// Allocate and construct an operation to wrap the function.
typedef detail::executor_op<function_type,
OtherAllocator, detail::operation> op;
typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 };
p.p = new (p.v) op(static_cast<Function&&>(f), a);
BOOST_ASIO_HANDLER_CREATION((*context_ptr(), *p.p,
"io_context", context_ptr(), 0, "dispatch"));
context_ptr()->impl_.post_immediate_completion(p.p, false);
p.v = p.p = 0;
}
template <typename Allocator, uintptr_t Bits>
template <typename Function, typename OtherAllocator>
void io_context::basic_executor_type<Allocator, Bits>::post(
Function&& f, const OtherAllocator& a) const
{
// Allocate and construct an operation to wrap the function.
typedef detail::executor_op<decay_t<Function>,
OtherAllocator, detail::operation> op;
typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 };
p.p = new (p.v) op(static_cast<Function&&>(f), a);
BOOST_ASIO_HANDLER_CREATION((*context_ptr(), *p.p,
"io_context", context_ptr(), 0, "post"));
context_ptr()->impl_.post_immediate_completion(p.p, false);
p.v = p.p = 0;
}
template <typename Allocator, uintptr_t Bits>
template <typename Function, typename OtherAllocator>
void io_context::basic_executor_type<Allocator, Bits>::defer(
Function&& f, const OtherAllocator& a) const
{
// Allocate and construct an operation to wrap the function.
typedef detail::executor_op<decay_t<Function>,
OtherAllocator, detail::operation> op;
typename op::ptr p = { detail::addressof(a), op::ptr::allocate(a), 0 };
p.p = new (p.v) op(static_cast<Function&&>(f), a);
BOOST_ASIO_HANDLER_CREATION((*context_ptr(), *p.p,
"io_context", context_ptr(), 0, "defer"));
context_ptr()->impl_.post_immediate_completion(p.p, true);
p.v = p.p = 0;
}
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
#if !defined(BOOST_ASIO_NO_DEPRECATED)
inline io_context::work::work(boost::asio::io_context& io_context)
: io_context_impl_(io_context.impl_)
{
io_context_impl_.work_started();
}
inline io_context::work::work(const work& other)
: io_context_impl_(other.io_context_impl_)
{
io_context_impl_.work_started();
}
inline io_context::work::~work()
{
io_context_impl_.work_finished();
}
inline boost::asio::io_context& io_context::work::get_io_context()
{
return static_cast<boost::asio::io_context&>(io_context_impl_.context());
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
inline boost::asio::io_context& io_context::service::get_io_context()
{
return static_cast<boost::asio::io_context&>(context());
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_IO_CONTEXT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/awaitable.hpp | //
// impl/awaitable.hpp
// ~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_AWAITABLE_HPP
#define BOOST_ASIO_IMPL_AWAITABLE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <exception>
#include <new>
#include <tuple>
#include <boost/asio/cancellation_signal.hpp>
#include <boost/asio/cancellation_state.hpp>
#include <boost/asio/detail/thread_context.hpp>
#include <boost/asio/detail/thread_info_base.hpp>
#include <boost/asio/detail/throw_error.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/post.hpp>
#include <boost/system/system_error.hpp>
#include <boost/asio/this_coro.hpp>
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
# if defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
# include <boost/asio/detail/source_location.hpp>
# endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
#endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
struct awaitable_thread_has_context_switched {};
template <typename, typename> class awaitable_async_op_handler;
template <typename, typename, typename> class awaitable_async_op;
// An awaitable_thread represents a thread-of-execution that is composed of one
// or more "stack frames", with each frame represented by an awaitable_frame.
// All execution occurs in the context of the awaitable_thread's executor. An
// awaitable_thread continues to "pump" the stack frames by repeatedly resuming
// the top stack frame until the stack is empty, or until ownership of the
// stack is transferred to another awaitable_thread object.
//
// +------------------------------------+
// | top_of_stack_ |
// | V
// +--------------+---+ +-----------------+
// | | | |
// | awaitable_thread |<---------------------------+ awaitable_frame |
// | | attached_thread_ | |
// +--------------+---+ (Set only when +---+-------------+
// | frames are being |
// | actively pumped | caller_
// | by a thread, and |
// | then only for V
// | the top frame.) +-----------------+
// | | |
// | | awaitable_frame |
// | | |
// | +---+-------------+
// | |
// | | caller_
// | :
// | :
// | |
// | V
// | +-----------------+
// | bottom_of_stack_ | |
// +------------------------------->| awaitable_frame |
// | |
// +-----------------+
template <typename Executor>
class awaitable_frame_base
{
public:
#if !defined(BOOST_ASIO_DISABLE_AWAITABLE_FRAME_RECYCLING)
void* operator new(std::size_t size)
{
return boost::asio::detail::thread_info_base::allocate(
boost::asio::detail::thread_info_base::awaitable_frame_tag(),
boost::asio::detail::thread_context::top_of_thread_call_stack(),
size);
}
void operator delete(void* pointer, std::size_t size)
{
boost::asio::detail::thread_info_base::deallocate(
boost::asio::detail::thread_info_base::awaitable_frame_tag(),
boost::asio::detail::thread_context::top_of_thread_call_stack(),
pointer, size);
}
#endif // !defined(BOOST_ASIO_DISABLE_AWAITABLE_FRAME_RECYCLING)
// The frame starts in a suspended state until the awaitable_thread object
// pumps the stack.
auto initial_suspend() noexcept
{
return suspend_always();
}
// On final suspension the frame is popped from the top of the stack.
auto final_suspend() noexcept
{
struct result
{
awaitable_frame_base* this_;
bool await_ready() const noexcept
{
return false;
}
void await_suspend(coroutine_handle<void>) noexcept
{
this->this_->pop_frame();
}
void await_resume() const noexcept
{
}
};
return result{this};
}
void set_except(std::exception_ptr e) noexcept
{
pending_exception_ = e;
}
void set_error(const boost::system::error_code& ec)
{
this->set_except(std::make_exception_ptr(boost::system::system_error(ec)));
}
void unhandled_exception()
{
set_except(std::current_exception());
}
void rethrow_exception()
{
if (pending_exception_)
{
std::exception_ptr ex = std::exchange(pending_exception_, nullptr);
std::rethrow_exception(ex);
}
}
void clear_cancellation_slot()
{
this->attached_thread_->entry_point()->cancellation_state_.slot().clear();
}
template <typename T>
auto await_transform(awaitable<T, Executor> a) const
{
if (attached_thread_->entry_point()->throw_if_cancelled_)
if (!!attached_thread_->get_cancellation_state().cancelled())
throw_error(boost::asio::error::operation_aborted, "co_await");
return a;
}
template <typename Op>
auto await_transform(Op&& op,
constraint_t<is_async_operation<Op>::value> = 0
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
# if defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
, detail::source_location location = detail::source_location::current()
# endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
#endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
)
{
if (attached_thread_->entry_point()->throw_if_cancelled_)
if (!!attached_thread_->get_cancellation_state().cancelled())
throw_error(boost::asio::error::operation_aborted, "co_await");
return awaitable_async_op<
completion_signature_of_t<Op>, decay_t<Op>, Executor>{
std::forward<Op>(op), this
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
# if defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
, location
# endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
#endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
};
}
// This await transformation obtains the associated executor of the thread of
// execution.
auto await_transform(this_coro::executor_t) noexcept
{
struct result
{
awaitable_frame_base* this_;
bool await_ready() const noexcept
{
return true;
}
void await_suspend(coroutine_handle<void>) noexcept
{
}
auto await_resume() const noexcept
{
return this_->attached_thread_->get_executor();
}
};
return result{this};
}
// This await transformation obtains the associated cancellation state of the
// thread of execution.
auto await_transform(this_coro::cancellation_state_t) noexcept
{
struct result
{
awaitable_frame_base* this_;
bool await_ready() const noexcept
{
return true;
}
void await_suspend(coroutine_handle<void>) noexcept
{
}
auto await_resume() const noexcept
{
return this_->attached_thread_->get_cancellation_state();
}
};
return result{this};
}
// This await transformation resets the associated cancellation state.
auto await_transform(this_coro::reset_cancellation_state_0_t) noexcept
{
struct result
{
awaitable_frame_base* this_;
bool await_ready() const noexcept
{
return true;
}
void await_suspend(coroutine_handle<void>) noexcept
{
}
auto await_resume() const
{
return this_->attached_thread_->reset_cancellation_state();
}
};
return result{this};
}
// This await transformation resets the associated cancellation state.
template <typename Filter>
auto await_transform(
this_coro::reset_cancellation_state_1_t<Filter> reset) noexcept
{
struct result
{
awaitable_frame_base* this_;
Filter filter_;
bool await_ready() const noexcept
{
return true;
}
void await_suspend(coroutine_handle<void>) noexcept
{
}
auto await_resume()
{
return this_->attached_thread_->reset_cancellation_state(
static_cast<Filter&&>(filter_));
}
};
return result{this, static_cast<Filter&&>(reset.filter)};
}
// This await transformation resets the associated cancellation state.
template <typename InFilter, typename OutFilter>
auto await_transform(
this_coro::reset_cancellation_state_2_t<InFilter, OutFilter> reset)
noexcept
{
struct result
{
awaitable_frame_base* this_;
InFilter in_filter_;
OutFilter out_filter_;
bool await_ready() const noexcept
{
return true;
}
void await_suspend(coroutine_handle<void>) noexcept
{
}
auto await_resume()
{
return this_->attached_thread_->reset_cancellation_state(
static_cast<InFilter&&>(in_filter_),
static_cast<OutFilter&&>(out_filter_));
}
};
return result{this,
static_cast<InFilter&&>(reset.in_filter),
static_cast<OutFilter&&>(reset.out_filter)};
}
// This await transformation determines whether cancellation is propagated as
// an exception.
auto await_transform(this_coro::throw_if_cancelled_0_t)
noexcept
{
struct result
{
awaitable_frame_base* this_;
bool await_ready() const noexcept
{
return true;
}
void await_suspend(coroutine_handle<void>) noexcept
{
}
auto await_resume()
{
return this_->attached_thread_->throw_if_cancelled();
}
};
return result{this};
}
// This await transformation sets whether cancellation is propagated as an
// exception.
auto await_transform(this_coro::throw_if_cancelled_1_t throw_if_cancelled)
noexcept
{
struct result
{
awaitable_frame_base* this_;
bool value_;
bool await_ready() const noexcept
{
return true;
}
void await_suspend(coroutine_handle<void>) noexcept
{
}
auto await_resume()
{
this_->attached_thread_->throw_if_cancelled(value_);
}
};
return result{this, throw_if_cancelled.value};
}
// This await transformation is used to run an async operation's initiation
// function object after the coroutine has been suspended. This ensures that
// immediate resumption of the coroutine in another thread does not cause a
// race condition.
template <typename Function>
auto await_transform(Function f,
enable_if_t<
is_convertible<
result_of_t<Function(awaitable_frame_base*)>,
awaitable_thread<Executor>*
>::value
>* = nullptr)
{
struct result
{
Function function_;
awaitable_frame_base* this_;
bool await_ready() const noexcept
{
return false;
}
void await_suspend(coroutine_handle<void>) noexcept
{
this_->after_suspend(
[](void* arg)
{
result* r = static_cast<result*>(arg);
r->function_(r->this_);
}, this);
}
void await_resume() const noexcept
{
}
};
return result{std::move(f), this};
}
// Access the awaitable thread's has_context_switched_ flag.
auto await_transform(detail::awaitable_thread_has_context_switched) noexcept
{
struct result
{
awaitable_frame_base* this_;
bool await_ready() const noexcept
{
return true;
}
void await_suspend(coroutine_handle<void>) noexcept
{
}
bool& await_resume() const noexcept
{
return this_->attached_thread_->entry_point()->has_context_switched_;
}
};
return result{this};
}
void attach_thread(awaitable_thread<Executor>* handler) noexcept
{
attached_thread_ = handler;
}
awaitable_thread<Executor>* detach_thread() noexcept
{
attached_thread_->entry_point()->has_context_switched_ = true;
return std::exchange(attached_thread_, nullptr);
}
void push_frame(awaitable_frame_base<Executor>* caller) noexcept
{
caller_ = caller;
attached_thread_ = caller_->attached_thread_;
attached_thread_->entry_point()->top_of_stack_ = this;
caller_->attached_thread_ = nullptr;
}
void pop_frame() noexcept
{
if (caller_)
caller_->attached_thread_ = attached_thread_;
attached_thread_->entry_point()->top_of_stack_ = caller_;
attached_thread_ = nullptr;
caller_ = nullptr;
}
struct resume_context
{
void (*after_suspend_fn_)(void*) = nullptr;
void *after_suspend_arg_ = nullptr;
};
void resume()
{
resume_context context;
resume_context_ = &context;
coro_.resume();
if (context.after_suspend_fn_)
context.after_suspend_fn_(context.after_suspend_arg_);
}
void after_suspend(void (*fn)(void*), void* arg)
{
resume_context_->after_suspend_fn_ = fn;
resume_context_->after_suspend_arg_ = arg;
}
void destroy()
{
coro_.destroy();
}
protected:
coroutine_handle<void> coro_ = nullptr;
awaitable_thread<Executor>* attached_thread_ = nullptr;
awaitable_frame_base<Executor>* caller_ = nullptr;
std::exception_ptr pending_exception_ = nullptr;
resume_context* resume_context_ = nullptr;
};
template <typename T, typename Executor>
class awaitable_frame
: public awaitable_frame_base<Executor>
{
public:
awaitable_frame() noexcept
{
}
awaitable_frame(awaitable_frame&& other) noexcept
: awaitable_frame_base<Executor>(std::move(other))
{
}
~awaitable_frame()
{
if (has_result_)
static_cast<T*>(static_cast<void*>(result_))->~T();
}
awaitable<T, Executor> get_return_object() noexcept
{
this->coro_ = coroutine_handle<awaitable_frame>::from_promise(*this);
return awaitable<T, Executor>(this);
};
template <typename U>
void return_value(U&& u)
{
new (&result_) T(std::forward<U>(u));
has_result_ = true;
}
template <typename... Us>
void return_values(Us&&... us)
{
this->return_value(std::forward_as_tuple(std::forward<Us>(us)...));
}
T get()
{
this->caller_ = nullptr;
this->rethrow_exception();
return std::move(*static_cast<T*>(static_cast<void*>(result_)));
}
private:
alignas(T) unsigned char result_[sizeof(T)];
bool has_result_ = false;
};
template <typename Executor>
class awaitable_frame<void, Executor>
: public awaitable_frame_base<Executor>
{
public:
awaitable<void, Executor> get_return_object()
{
this->coro_ = coroutine_handle<awaitable_frame>::from_promise(*this);
return awaitable<void, Executor>(this);
};
void return_void()
{
}
void get()
{
this->caller_ = nullptr;
this->rethrow_exception();
}
};
struct awaitable_thread_entry_point {};
template <typename Executor>
class awaitable_frame<awaitable_thread_entry_point, Executor>
: public awaitable_frame_base<Executor>
{
public:
awaitable_frame()
: top_of_stack_(0),
has_executor_(false),
has_context_switched_(false),
throw_if_cancelled_(true)
{
}
~awaitable_frame()
{
if (has_executor_)
u_.executor_.~Executor();
}
awaitable<awaitable_thread_entry_point, Executor> get_return_object()
{
this->coro_ = coroutine_handle<awaitable_frame>::from_promise(*this);
return awaitable<awaitable_thread_entry_point, Executor>(this);
};
void return_void()
{
}
void get()
{
this->caller_ = nullptr;
this->rethrow_exception();
}
private:
template <typename> friend class awaitable_frame_base;
template <typename, typename> friend class awaitable_async_op_handler;
template <typename, typename> friend class awaitable_handler_base;
template <typename> friend class awaitable_thread;
union u
{
u() {}
~u() {}
char c_;
Executor executor_;
} u_;
awaitable_frame_base<Executor>* top_of_stack_;
boost::asio::cancellation_slot parent_cancellation_slot_;
boost::asio::cancellation_state cancellation_state_;
bool has_executor_;
bool has_context_switched_;
bool throw_if_cancelled_;
};
template <typename Executor>
class awaitable_thread
{
public:
typedef Executor executor_type;
typedef cancellation_slot cancellation_slot_type;
// Construct from the entry point of a new thread of execution.
awaitable_thread(awaitable<awaitable_thread_entry_point, Executor> p,
const Executor& ex, cancellation_slot parent_cancel_slot,
cancellation_state cancel_state)
: bottom_of_stack_(std::move(p))
{
bottom_of_stack_.frame_->top_of_stack_ = bottom_of_stack_.frame_;
new (&bottom_of_stack_.frame_->u_.executor_) Executor(ex);
bottom_of_stack_.frame_->has_executor_ = true;
bottom_of_stack_.frame_->parent_cancellation_slot_ = parent_cancel_slot;
bottom_of_stack_.frame_->cancellation_state_ = cancel_state;
}
// Transfer ownership from another awaitable_thread.
awaitable_thread(awaitable_thread&& other) noexcept
: bottom_of_stack_(std::move(other.bottom_of_stack_))
{
}
// Clean up with a last ditch effort to ensure the thread is unwound within
// the context of the executor.
~awaitable_thread()
{
if (bottom_of_stack_.valid())
{
// Coroutine "stack unwinding" must be performed through the executor.
auto* bottom_frame = bottom_of_stack_.frame_;
(post)(bottom_frame->u_.executor_,
[a = std::move(bottom_of_stack_)]() mutable
{
(void)awaitable<awaitable_thread_entry_point, Executor>(
std::move(a));
});
}
}
awaitable_frame<awaitable_thread_entry_point, Executor>* entry_point()
{
return bottom_of_stack_.frame_;
}
executor_type get_executor() const noexcept
{
return bottom_of_stack_.frame_->u_.executor_;
}
cancellation_state get_cancellation_state() const noexcept
{
return bottom_of_stack_.frame_->cancellation_state_;
}
void reset_cancellation_state()
{
bottom_of_stack_.frame_->cancellation_state_ =
cancellation_state(bottom_of_stack_.frame_->parent_cancellation_slot_);
}
template <typename Filter>
void reset_cancellation_state(Filter&& filter)
{
bottom_of_stack_.frame_->cancellation_state_ =
cancellation_state(bottom_of_stack_.frame_->parent_cancellation_slot_,
static_cast<Filter&&>(filter));
}
template <typename InFilter, typename OutFilter>
void reset_cancellation_state(InFilter&& in_filter,
OutFilter&& out_filter)
{
bottom_of_stack_.frame_->cancellation_state_ =
cancellation_state(bottom_of_stack_.frame_->parent_cancellation_slot_,
static_cast<InFilter&&>(in_filter),
static_cast<OutFilter&&>(out_filter));
}
bool throw_if_cancelled() const
{
return bottom_of_stack_.frame_->throw_if_cancelled_;
}
void throw_if_cancelled(bool value)
{
bottom_of_stack_.frame_->throw_if_cancelled_ = value;
}
cancellation_slot_type get_cancellation_slot() const noexcept
{
return bottom_of_stack_.frame_->cancellation_state_.slot();
}
// Launch a new thread of execution.
void launch()
{
bottom_of_stack_.frame_->top_of_stack_->attach_thread(this);
pump();
}
protected:
template <typename> friend class awaitable_frame_base;
// Repeatedly resume the top stack frame until the stack is empty or until it
// has been transferred to another resumable_thread object.
void pump()
{
do
bottom_of_stack_.frame_->top_of_stack_->resume();
while (bottom_of_stack_.frame_ && bottom_of_stack_.frame_->top_of_stack_);
if (bottom_of_stack_.frame_)
{
awaitable<awaitable_thread_entry_point, Executor> a(
std::move(bottom_of_stack_));
a.frame_->rethrow_exception();
}
}
awaitable<awaitable_thread_entry_point, Executor> bottom_of_stack_;
};
template <typename Signature, typename Executor>
class awaitable_async_op_handler;
template <typename R, typename Executor>
class awaitable_async_op_handler<R(), Executor>
: public awaitable_thread<Executor>
{
public:
struct result_type {};
awaitable_async_op_handler(
awaitable_thread<Executor>* h, result_type&)
: awaitable_thread<Executor>(std::move(*h))
{
}
void operator()()
{
this->entry_point()->top_of_stack_->attach_thread(this);
this->entry_point()->top_of_stack_->clear_cancellation_slot();
this->pump();
}
static void resume(result_type&)
{
}
};
template <typename R, typename Executor>
class awaitable_async_op_handler<R(boost::system::error_code), Executor>
: public awaitable_thread<Executor>
{
public:
typedef boost::system::error_code* result_type;
awaitable_async_op_handler(
awaitable_thread<Executor>* h, result_type& result)
: awaitable_thread<Executor>(std::move(*h)),
result_(result)
{
}
void operator()(boost::system::error_code ec)
{
result_ = &ec;
this->entry_point()->top_of_stack_->attach_thread(this);
this->entry_point()->top_of_stack_->clear_cancellation_slot();
this->pump();
}
static void resume(result_type& result)
{
throw_error(*result);
}
private:
result_type& result_;
};
template <typename R, typename Executor>
class awaitable_async_op_handler<R(std::exception_ptr), Executor>
: public awaitable_thread<Executor>
{
public:
typedef std::exception_ptr* result_type;
awaitable_async_op_handler(
awaitable_thread<Executor>* h, result_type& result)
: awaitable_thread<Executor>(std::move(*h)),
result_(result)
{
}
void operator()(std::exception_ptr ex)
{
result_ = &ex;
this->entry_point()->top_of_stack_->attach_thread(this);
this->entry_point()->top_of_stack_->clear_cancellation_slot();
this->pump();
}
static void resume(result_type& result)
{
if (*result)
{
std::exception_ptr ex = std::exchange(*result, nullptr);
std::rethrow_exception(ex);
}
}
private:
result_type& result_;
};
template <typename R, typename T, typename Executor>
class awaitable_async_op_handler<R(T), Executor>
: public awaitable_thread<Executor>
{
public:
typedef T* result_type;
awaitable_async_op_handler(
awaitable_thread<Executor>* h, result_type& result)
: awaitable_thread<Executor>(std::move(*h)),
result_(result)
{
}
void operator()(T result)
{
result_ = &result;
this->entry_point()->top_of_stack_->attach_thread(this);
this->entry_point()->top_of_stack_->clear_cancellation_slot();
this->pump();
}
static T resume(result_type& result)
{
return std::move(*result);
}
private:
result_type& result_;
};
template <typename R, typename T, typename Executor>
class awaitable_async_op_handler<R(boost::system::error_code, T), Executor>
: public awaitable_thread<Executor>
{
public:
struct result_type
{
boost::system::error_code* ec_;
T* value_;
};
awaitable_async_op_handler(
awaitable_thread<Executor>* h, result_type& result)
: awaitable_thread<Executor>(std::move(*h)),
result_(result)
{
}
void operator()(boost::system::error_code ec, T value)
{
result_.ec_ = &ec;
result_.value_ = &value;
this->entry_point()->top_of_stack_->attach_thread(this);
this->entry_point()->top_of_stack_->clear_cancellation_slot();
this->pump();
}
static T resume(result_type& result)
{
throw_error(*result.ec_);
return std::move(*result.value_);
}
private:
result_type& result_;
};
template <typename R, typename T, typename Executor>
class awaitable_async_op_handler<R(std::exception_ptr, T), Executor>
: public awaitable_thread<Executor>
{
public:
struct result_type
{
std::exception_ptr* ex_;
T* value_;
};
awaitable_async_op_handler(
awaitable_thread<Executor>* h, result_type& result)
: awaitable_thread<Executor>(std::move(*h)),
result_(result)
{
}
void operator()(std::exception_ptr ex, T value)
{
result_.ex_ = &ex;
result_.value_ = &value;
this->entry_point()->top_of_stack_->attach_thread(this);
this->entry_point()->top_of_stack_->clear_cancellation_slot();
this->pump();
}
static T resume(result_type& result)
{
if (*result.ex_)
{
std::exception_ptr ex = std::exchange(*result.ex_, nullptr);
std::rethrow_exception(ex);
}
return std::move(*result.value_);
}
private:
result_type& result_;
};
template <typename R, typename... Ts, typename Executor>
class awaitable_async_op_handler<R(Ts...), Executor>
: public awaitable_thread<Executor>
{
public:
typedef std::tuple<Ts...>* result_type;
awaitable_async_op_handler(
awaitable_thread<Executor>* h, result_type& result)
: awaitable_thread<Executor>(std::move(*h)),
result_(result)
{
}
template <typename... Args>
void operator()(Args&&... args)
{
std::tuple<Ts...> result(std::forward<Args>(args)...);
result_ = &result;
this->entry_point()->top_of_stack_->attach_thread(this);
this->entry_point()->top_of_stack_->clear_cancellation_slot();
this->pump();
}
static std::tuple<Ts...> resume(result_type& result)
{
return std::move(*result);
}
private:
result_type& result_;
};
template <typename R, typename... Ts, typename Executor>
class awaitable_async_op_handler<R(boost::system::error_code, Ts...), Executor>
: public awaitable_thread<Executor>
{
public:
struct result_type
{
boost::system::error_code* ec_;
std::tuple<Ts...>* value_;
};
awaitable_async_op_handler(
awaitable_thread<Executor>* h, result_type& result)
: awaitable_thread<Executor>(std::move(*h)),
result_(result)
{
}
template <typename... Args>
void operator()(boost::system::error_code ec, Args&&... args)
{
result_.ec_ = &ec;
std::tuple<Ts...> value(std::forward<Args>(args)...);
result_.value_ = &value;
this->entry_point()->top_of_stack_->attach_thread(this);
this->entry_point()->top_of_stack_->clear_cancellation_slot();
this->pump();
}
static std::tuple<Ts...> resume(result_type& result)
{
throw_error(*result.ec_);
return std::move(*result.value_);
}
private:
result_type& result_;
};
template <typename R, typename... Ts, typename Executor>
class awaitable_async_op_handler<R(std::exception_ptr, Ts...), Executor>
: public awaitable_thread<Executor>
{
public:
struct result_type
{
std::exception_ptr* ex_;
std::tuple<Ts...>* value_;
};
awaitable_async_op_handler(
awaitable_thread<Executor>* h, result_type& result)
: awaitable_thread<Executor>(std::move(*h)),
result_(result)
{
}
template <typename... Args>
void operator()(std::exception_ptr ex, Args&&... args)
{
result_.ex_ = &ex;
std::tuple<Ts...> value(std::forward<Args>(args)...);
result_.value_ = &value;
this->entry_point()->top_of_stack_->attach_thread(this);
this->entry_point()->top_of_stack_->clear_cancellation_slot();
this->pump();
}
static std::tuple<Ts...> resume(result_type& result)
{
if (*result.ex_)
{
std::exception_ptr ex = std::exchange(*result.ex_, nullptr);
std::rethrow_exception(ex);
}
return std::move(*result.value_);
}
private:
result_type& result_;
};
template <typename Signature, typename Op, typename Executor>
class awaitable_async_op
{
public:
typedef awaitable_async_op_handler<Signature, Executor> handler_type;
awaitable_async_op(Op&& o, awaitable_frame_base<Executor>* frame
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
# if defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
, const detail::source_location& location
# endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
#endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
)
: op_(std::forward<Op>(o)),
frame_(frame),
result_()
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
# if defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
, location_(location)
# endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
#endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
{
}
bool await_ready() const noexcept
{
return false;
}
void await_suspend(coroutine_handle<void>)
{
frame_->after_suspend(
[](void* arg)
{
awaitable_async_op* self = static_cast<awaitable_async_op*>(arg);
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
# if defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
BOOST_ASIO_HANDLER_LOCATION((self->location_.file_name(),
self->location_.line(), self->location_.function_name()));
# endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
#endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
std::forward<Op&&>(self->op_)(
handler_type(self->frame_->detach_thread(), self->result_));
}, this);
}
auto await_resume()
{
return handler_type::resume(result_);
}
private:
Op&& op_;
awaitable_frame_base<Executor>* frame_;
typename handler_type::result_type result_;
#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
# if defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
detail::source_location location_;
# endif // defined(BOOST_ASIO_HAS_SOURCE_LOCATION)
#endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
};
} // namespace detail
} // namespace asio
} // namespace boost
#if !defined(GENERATING_DOCUMENTATION)
# if defined(BOOST_ASIO_HAS_STD_COROUTINE)
namespace std {
template <typename T, typename Executor, typename... Args>
struct coroutine_traits<boost::asio::awaitable<T, Executor>, Args...>
{
typedef boost::asio::detail::awaitable_frame<T, Executor> promise_type;
};
} // namespace std
# else // defined(BOOST_ASIO_HAS_STD_COROUTINE)
namespace std { namespace experimental {
template <typename T, typename Executor, typename... Args>
struct coroutine_traits<boost::asio::awaitable<T, Executor>, Args...>
{
typedef boost::asio::detail::awaitable_frame<T, Executor> promise_type;
};
}} // namespace std::experimental
# endif // defined(BOOST_ASIO_HAS_STD_COROUTINE)
#endif // !defined(GENERATING_DOCUMENTATION)
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_AWAITABLE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/spawn.hpp | //
// impl/spawn.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_SPAWN_HPP
#define BOOST_ASIO_IMPL_SPAWN_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <tuple>
#include <boost/asio/associated_allocator.hpp>
#include <boost/asio/associated_cancellation_slot.hpp>
#include <boost/asio/associated_executor.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/bind_executor.hpp>
#include <boost/asio/detail/atomic_count.hpp>
#include <boost/asio/detail/bind_handler.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/memory.hpp>
#include <boost/asio/detail/noncopyable.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/utility.hpp>
#include <boost/system/system_error.hpp>
#if defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
# include <boost/context/fiber.hpp>
#endif // defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
inline void spawned_thread_rethrow(void* ex)
{
if (*static_cast<exception_ptr*>(ex))
rethrow_exception(*static_cast<exception_ptr*>(ex));
}
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
#if defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
// Spawned thread implementation using Boost.Coroutine.
class spawned_coroutine_thread : public spawned_thread_base
{
public:
#if defined(BOOST_COROUTINES_UNIDIRECT) || defined(BOOST_COROUTINES_V2)
typedef boost::coroutines::pull_coroutine<void> callee_type;
typedef boost::coroutines::push_coroutine<void> caller_type;
#else
typedef boost::coroutines::coroutine<void()> callee_type;
typedef boost::coroutines::coroutine<void()> caller_type;
#endif
spawned_coroutine_thread(caller_type& caller)
: caller_(caller),
on_suspend_fn_(0),
on_suspend_arg_(0)
{
}
template <typename F>
static spawned_thread_base* spawn(F&& f,
const boost::coroutines::attributes& attributes,
cancellation_slot parent_cancel_slot = cancellation_slot(),
cancellation_state cancel_state = cancellation_state())
{
spawned_coroutine_thread* spawned_thread = 0;
callee_type callee(entry_point<decay_t<F>>(
static_cast<F&&>(f), &spawned_thread), attributes);
spawned_thread->callee_.swap(callee);
spawned_thread->parent_cancellation_slot_ = parent_cancel_slot;
spawned_thread->cancellation_state_ = cancel_state;
return spawned_thread;
}
template <typename F>
static spawned_thread_base* spawn(F&& f,
cancellation_slot parent_cancel_slot = cancellation_slot(),
cancellation_state cancel_state = cancellation_state())
{
return spawn(static_cast<F&&>(f), boost::coroutines::attributes(),
parent_cancel_slot, cancel_state);
}
void resume()
{
callee_();
if (on_suspend_fn_)
{
void (*fn)(void*) = on_suspend_fn_;
void* arg = on_suspend_arg_;
on_suspend_fn_ = 0;
fn(arg);
}
}
void suspend_with(void (*fn)(void*), void* arg)
{
if (throw_if_cancelled_)
if (!!cancellation_state_.cancelled())
throw_error(boost::asio::error::operation_aborted, "yield");
has_context_switched_ = true;
on_suspend_fn_ = fn;
on_suspend_arg_ = arg;
caller_();
}
void destroy()
{
callee_type callee;
callee.swap(callee_);
if (terminal_)
callee();
}
private:
template <typename Function>
class entry_point
{
public:
template <typename F>
entry_point(F&& f,
spawned_coroutine_thread** spawned_thread_out)
: function_(static_cast<F&&>(f)),
spawned_thread_out_(spawned_thread_out)
{
}
void operator()(caller_type& caller)
{
Function function(static_cast<Function&&>(function_));
spawned_coroutine_thread spawned_thread(caller);
*spawned_thread_out_ = &spawned_thread;
spawned_thread_out_ = 0;
spawned_thread.suspend();
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
{
function(&spawned_thread);
spawned_thread.terminal_ = true;
spawned_thread.suspend();
}
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
catch (const boost::coroutines::detail::forced_unwind&)
{
throw;
}
catch (...)
{
exception_ptr ex = current_exception();
spawned_thread.terminal_ = true;
spawned_thread.suspend_with(spawned_thread_rethrow, &ex);
}
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
private:
Function function_;
spawned_coroutine_thread** spawned_thread_out_;
};
caller_type& caller_;
callee_type callee_;
void (*on_suspend_fn_)(void*);
void* on_suspend_arg_;
};
#endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
#if defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
// Spawned thread implementation using Boost.Context's fiber.
class spawned_fiber_thread : public spawned_thread_base
{
public:
typedef boost::context::fiber fiber_type;
spawned_fiber_thread(fiber_type&& caller)
: caller_(static_cast<fiber_type&&>(caller)),
on_suspend_fn_(0),
on_suspend_arg_(0)
{
}
template <typename StackAllocator, typename F>
static spawned_thread_base* spawn(allocator_arg_t,
StackAllocator&& stack_allocator,
F&& f,
cancellation_slot parent_cancel_slot = cancellation_slot(),
cancellation_state cancel_state = cancellation_state())
{
spawned_fiber_thread* spawned_thread = 0;
fiber_type callee(allocator_arg_t(),
static_cast<StackAllocator&&>(stack_allocator),
entry_point<decay_t<F>>(
static_cast<F&&>(f), &spawned_thread));
callee = fiber_type(static_cast<fiber_type&&>(callee)).resume();
spawned_thread->callee_ = static_cast<fiber_type&&>(callee);
spawned_thread->parent_cancellation_slot_ = parent_cancel_slot;
spawned_thread->cancellation_state_ = cancel_state;
return spawned_thread;
}
template <typename F>
static spawned_thread_base* spawn(F&& f,
cancellation_slot parent_cancel_slot = cancellation_slot(),
cancellation_state cancel_state = cancellation_state())
{
return spawn(allocator_arg_t(), boost::context::fixedsize_stack(),
static_cast<F&&>(f), parent_cancel_slot, cancel_state);
}
void resume()
{
callee_ = fiber_type(static_cast<fiber_type&&>(callee_)).resume();
if (on_suspend_fn_)
{
void (*fn)(void*) = on_suspend_fn_;
void* arg = on_suspend_arg_;
on_suspend_fn_ = 0;
fn(arg);
}
}
void suspend_with(void (*fn)(void*), void* arg)
{
if (throw_if_cancelled_)
if (!!cancellation_state_.cancelled())
throw_error(boost::asio::error::operation_aborted, "yield");
has_context_switched_ = true;
on_suspend_fn_ = fn;
on_suspend_arg_ = arg;
caller_ = fiber_type(static_cast<fiber_type&&>(caller_)).resume();
}
void destroy()
{
fiber_type callee = static_cast<fiber_type&&>(callee_);
if (terminal_)
fiber_type(static_cast<fiber_type&&>(callee)).resume();
}
private:
template <typename Function>
class entry_point
{
public:
template <typename F>
entry_point(F&& f,
spawned_fiber_thread** spawned_thread_out)
: function_(static_cast<F&&>(f)),
spawned_thread_out_(spawned_thread_out)
{
}
fiber_type operator()(fiber_type&& caller)
{
Function function(static_cast<Function&&>(function_));
spawned_fiber_thread spawned_thread(
static_cast<fiber_type&&>(caller));
*spawned_thread_out_ = &spawned_thread;
spawned_thread_out_ = 0;
spawned_thread.suspend();
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
{
function(&spawned_thread);
spawned_thread.terminal_ = true;
spawned_thread.suspend();
}
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
catch (const boost::context::detail::forced_unwind&)
{
throw;
}
catch (...)
{
exception_ptr ex = current_exception();
spawned_thread.terminal_ = true;
spawned_thread.suspend_with(spawned_thread_rethrow, &ex);
}
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
return static_cast<fiber_type&&>(spawned_thread.caller_);
}
private:
Function function_;
spawned_fiber_thread** spawned_thread_out_;
};
fiber_type caller_;
fiber_type callee_;
void (*on_suspend_fn_)(void*);
void* on_suspend_arg_;
};
#endif // defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
#if defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
typedef spawned_fiber_thread default_spawned_thread_type;
#elif defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
typedef spawned_coroutine_thread default_spawned_thread_type;
#else
# error No spawn() implementation available
#endif
// Helper class to perform the initial resume on the correct executor.
class spawned_thread_resumer
{
public:
explicit spawned_thread_resumer(spawned_thread_base* spawned_thread)
: spawned_thread_(spawned_thread)
{
}
spawned_thread_resumer(spawned_thread_resumer&& other) noexcept
: spawned_thread_(other.spawned_thread_)
{
other.spawned_thread_ = 0;
}
~spawned_thread_resumer()
{
if (spawned_thread_)
spawned_thread_->destroy();
}
void operator()()
{
spawned_thread_->attach(&spawned_thread_);
spawned_thread_->resume();
}
private:
spawned_thread_base* spawned_thread_;
};
// Helper class to ensure spawned threads are destroyed on the correct executor.
class spawned_thread_destroyer
{
public:
explicit spawned_thread_destroyer(spawned_thread_base* spawned_thread)
: spawned_thread_(spawned_thread)
{
spawned_thread->detach();
}
spawned_thread_destroyer(spawned_thread_destroyer&& other) noexcept
: spawned_thread_(other.spawned_thread_)
{
other.spawned_thread_ = 0;
}
~spawned_thread_destroyer()
{
if (spawned_thread_)
spawned_thread_->destroy();
}
void operator()()
{
if (spawned_thread_)
{
spawned_thread_->destroy();
spawned_thread_ = 0;
}
}
private:
spawned_thread_base* spawned_thread_;
};
// Base class for all completion handlers associated with a spawned thread.
template <typename Executor>
class spawn_handler_base
{
public:
typedef Executor executor_type;
typedef cancellation_slot cancellation_slot_type;
spawn_handler_base(const basic_yield_context<Executor>& yield)
: yield_(yield),
spawned_thread_(yield.spawned_thread_)
{
spawned_thread_->detach();
}
spawn_handler_base(spawn_handler_base&& other) noexcept
: yield_(other.yield_),
spawned_thread_(other.spawned_thread_)
{
other.spawned_thread_ = 0;
}
~spawn_handler_base()
{
if (spawned_thread_)
(post)(yield_.executor_, spawned_thread_destroyer(spawned_thread_));
}
executor_type get_executor() const noexcept
{
return yield_.executor_;
}
cancellation_slot_type get_cancellation_slot() const noexcept
{
return spawned_thread_->get_cancellation_slot();
}
void resume()
{
spawned_thread_resumer resumer(spawned_thread_);
spawned_thread_ = 0;
resumer();
}
protected:
const basic_yield_context<Executor>& yield_;
spawned_thread_base* spawned_thread_;
};
// Completion handlers for when basic_yield_context is used as a token.
template <typename Executor, typename Signature>
class spawn_handler;
template <typename Executor, typename R>
class spawn_handler<Executor, R()>
: public spawn_handler_base<Executor>
{
public:
typedef void return_type;
struct result_type {};
spawn_handler(const basic_yield_context<Executor>& yield, result_type&)
: spawn_handler_base<Executor>(yield)
{
}
void operator()()
{
this->resume();
}
static return_type on_resume(result_type&)
{
}
};
template <typename Executor, typename R>
class spawn_handler<Executor, R(boost::system::error_code)>
: public spawn_handler_base<Executor>
{
public:
typedef void return_type;
typedef boost::system::error_code* result_type;
spawn_handler(const basic_yield_context<Executor>& yield, result_type& result)
: spawn_handler_base<Executor>(yield),
result_(result)
{
}
void operator()(boost::system::error_code ec)
{
if (this->yield_.ec_)
{
*this->yield_.ec_ = ec;
result_ = 0;
}
else
result_ = &ec;
this->resume();
}
static return_type on_resume(result_type& result)
{
if (result)
throw_error(*result);
}
private:
result_type& result_;
};
template <typename Executor, typename R>
class spawn_handler<Executor, R(exception_ptr)>
: public spawn_handler_base<Executor>
{
public:
typedef void return_type;
typedef exception_ptr* result_type;
spawn_handler(const basic_yield_context<Executor>& yield, result_type& result)
: spawn_handler_base<Executor>(yield),
result_(result)
{
}
void operator()(exception_ptr ex)
{
result_ = &ex;
this->resume();
}
static return_type on_resume(result_type& result)
{
if (*result)
rethrow_exception(*result);
}
private:
result_type& result_;
};
template <typename Executor, typename R, typename T>
class spawn_handler<Executor, R(T)>
: public spawn_handler_base<Executor>
{
public:
typedef T return_type;
typedef return_type* result_type;
spawn_handler(const basic_yield_context<Executor>& yield, result_type& result)
: spawn_handler_base<Executor>(yield),
result_(result)
{
}
void operator()(T value)
{
result_ = &value;
this->resume();
}
static return_type on_resume(result_type& result)
{
return static_cast<return_type&&>(*result);
}
private:
result_type& result_;
};
template <typename Executor, typename R, typename T>
class spawn_handler<Executor, R(boost::system::error_code, T)>
: public spawn_handler_base<Executor>
{
public:
typedef T return_type;
struct result_type
{
boost::system::error_code* ec_;
return_type* value_;
};
spawn_handler(const basic_yield_context<Executor>& yield, result_type& result)
: spawn_handler_base<Executor>(yield),
result_(result)
{
}
void operator()(boost::system::error_code ec, T value)
{
if (this->yield_.ec_)
{
*this->yield_.ec_ = ec;
result_.ec_ = 0;
}
else
result_.ec_ = &ec;
result_.value_ = &value;
this->resume();
}
static return_type on_resume(result_type& result)
{
if (result.ec_)
throw_error(*result.ec_);
return static_cast<return_type&&>(*result.value_);
}
private:
result_type& result_;
};
template <typename Executor, typename R, typename T>
class spawn_handler<Executor, R(exception_ptr, T)>
: public spawn_handler_base<Executor>
{
public:
typedef T return_type;
struct result_type
{
exception_ptr* ex_;
return_type* value_;
};
spawn_handler(const basic_yield_context<Executor>& yield, result_type& result)
: spawn_handler_base<Executor>(yield),
result_(result)
{
}
void operator()(exception_ptr ex, T value)
{
result_.ex_ = &ex;
result_.value_ = &value;
this->resume();
}
static return_type on_resume(result_type& result)
{
if (*result.ex_)
rethrow_exception(*result.ex_);
return static_cast<return_type&&>(*result.value_);
}
private:
result_type& result_;
};
template <typename Executor, typename R, typename... Ts>
class spawn_handler<Executor, R(Ts...)>
: public spawn_handler_base<Executor>
{
public:
typedef std::tuple<Ts...> return_type;
typedef return_type* result_type;
spawn_handler(const basic_yield_context<Executor>& yield, result_type& result)
: spawn_handler_base<Executor>(yield),
result_(result)
{
}
template <typename... Args>
void operator()(Args&&... args)
{
return_type value(static_cast<Args&&>(args)...);
result_ = &value;
this->resume();
}
static return_type on_resume(result_type& result)
{
return static_cast<return_type&&>(*result);
}
private:
result_type& result_;
};
template <typename Executor, typename R, typename... Ts>
class spawn_handler<Executor, R(boost::system::error_code, Ts...)>
: public spawn_handler_base<Executor>
{
public:
typedef std::tuple<Ts...> return_type;
struct result_type
{
boost::system::error_code* ec_;
return_type* value_;
};
spawn_handler(const basic_yield_context<Executor>& yield, result_type& result)
: spawn_handler_base<Executor>(yield),
result_(result)
{
}
template <typename... Args>
void operator()(boost::system::error_code ec,
Args&&... args)
{
return_type value(static_cast<Args&&>(args)...);
if (this->yield_.ec_)
{
*this->yield_.ec_ = ec;
result_.ec_ = 0;
}
else
result_.ec_ = &ec;
result_.value_ = &value;
this->resume();
}
static return_type on_resume(result_type& result)
{
if (result.ec_)
throw_error(*result.ec_);
return static_cast<return_type&&>(*result.value_);
}
private:
result_type& result_;
};
template <typename Executor, typename R, typename... Ts>
class spawn_handler<Executor, R(exception_ptr, Ts...)>
: public spawn_handler_base<Executor>
{
public:
typedef std::tuple<Ts...> return_type;
struct result_type
{
exception_ptr* ex_;
return_type* value_;
};
spawn_handler(const basic_yield_context<Executor>& yield, result_type& result)
: spawn_handler_base<Executor>(yield),
result_(result)
{
}
template <typename... Args>
void operator()(exception_ptr ex, Args&&... args)
{
return_type value(static_cast<Args&&>(args)...);
result_.ex_ = &ex;
result_.value_ = &value;
this->resume();
}
static return_type on_resume(result_type& result)
{
if (*result.ex_)
rethrow_exception(*result.ex_);
return static_cast<return_type&&>(*result.value_);
}
private:
result_type& result_;
};
template <typename Executor, typename Signature>
inline bool asio_handler_is_continuation(spawn_handler<Executor, Signature>*)
{
return true;
}
} // namespace detail
template <typename Executor, typename Signature>
class async_result<basic_yield_context<Executor>, Signature>
{
public:
typedef typename detail::spawn_handler<Executor, Signature> handler_type;
typedef typename handler_type::return_type return_type;
#if defined(BOOST_ASIO_HAS_VARIADIC_LAMBDA_CAPTURES)
template <typename Initiation, typename... InitArgs>
static return_type initiate(Initiation&& init,
const basic_yield_context<Executor>& yield,
InitArgs&&... init_args)
{
typename handler_type::result_type result
= typename handler_type::result_type();
yield.spawned_thread_->suspend_with(
[&]()
{
static_cast<Initiation&&>(init)(
handler_type(yield, result),
static_cast<InitArgs&&>(init_args)...);
});
return handler_type::on_resume(result);
}
#else // defined(BOOST_ASIO_HAS_VARIADIC_LAMBDA_CAPTURES)
template <typename Initiation, typename... InitArgs>
struct suspend_with_helper
{
typename handler_type::result_type& result_;
Initiation&& init_;
const basic_yield_context<Executor>& yield_;
std::tuple<InitArgs&&...> init_args_;
template <std::size_t... I>
void do_invoke(detail::index_sequence<I...>)
{
static_cast<Initiation&&>(init_)(
handler_type(yield_, result_),
static_cast<InitArgs&&>(std::get<I>(init_args_))...);
}
void operator()()
{
this->do_invoke(detail::make_index_sequence<sizeof...(InitArgs)>());
}
};
template <typename Initiation, typename... InitArgs>
static return_type initiate(Initiation&& init,
const basic_yield_context<Executor>& yield,
InitArgs&&... init_args)
{
typename handler_type::result_type result
= typename handler_type::result_type();
yield.spawned_thread_->suspend_with(
suspend_with_helper<Initiation, InitArgs...>{
result, static_cast<Initiation&&>(init), yield,
std::tuple<InitArgs&&...>(
static_cast<InitArgs&&>(init_args)...)});
return handler_type::on_resume(result);
}
#endif // defined(BOOST_ASIO_HAS_VARIADIC_LAMBDA_CAPTURES)
};
namespace detail {
template <typename Executor, typename Function, typename Handler>
class spawn_entry_point
{
public:
template <typename F, typename H>
spawn_entry_point(const Executor& ex,
F&& f, H&& h)
: executor_(ex),
function_(static_cast<F&&>(f)),
handler_(static_cast<H&&>(h)),
work_(handler_, executor_)
{
}
void operator()(spawned_thread_base* spawned_thread)
{
const basic_yield_context<Executor> yield(spawned_thread, executor_);
this->call(yield,
void_type<result_of_t<Function(basic_yield_context<Executor>)>>());
}
private:
void call(const basic_yield_context<Executor>& yield, void_type<void>)
{
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
{
function_(yield);
if (!yield.spawned_thread_->has_context_switched())
(post)(yield);
detail::binder1<Handler, exception_ptr>
handler(handler_, exception_ptr());
work_.complete(handler, handler.handler_);
}
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
# if defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
catch (const boost::context::detail::forced_unwind&)
{
throw;
}
# endif // defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
# if defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
catch (const boost::coroutines::detail::forced_unwind&)
{
throw;
}
# endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
catch (...)
{
exception_ptr ex = current_exception();
if (!yield.spawned_thread_->has_context_switched())
(post)(yield);
detail::binder1<Handler, exception_ptr> handler(handler_, ex);
work_.complete(handler, handler.handler_);
}
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
template <typename T>
void call(const basic_yield_context<Executor>& yield, void_type<T>)
{
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
{
T result(function_(yield));
if (!yield.spawned_thread_->has_context_switched())
(post)(yield);
detail::binder2<Handler, exception_ptr, T>
handler(handler_, exception_ptr(), static_cast<T&&>(result));
work_.complete(handler, handler.handler_);
}
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
# if defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
catch (const boost::context::detail::forced_unwind&)
{
throw;
}
# endif // defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
# if defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
catch (const boost::coroutines::detail::forced_unwind&)
{
throw;
}
# endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
catch (...)
{
exception_ptr ex = current_exception();
if (!yield.spawned_thread_->has_context_switched())
(post)(yield);
detail::binder2<Handler, exception_ptr, T> handler(handler_, ex, T());
work_.complete(handler, handler.handler_);
}
#endif // !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
Executor executor_;
Function function_;
Handler handler_;
handler_work<Handler, Executor> work_;
};
struct spawn_cancellation_signal_emitter
{
cancellation_signal* signal_;
cancellation_type_t type_;
void operator()()
{
signal_->emit(type_);
}
};
template <typename Handler, typename Executor, typename = void>
class spawn_cancellation_handler
{
public:
spawn_cancellation_handler(const Handler&, const Executor& ex)
: ex_(ex)
{
}
cancellation_slot slot()
{
return signal_.slot();
}
void operator()(cancellation_type_t type)
{
spawn_cancellation_signal_emitter emitter = { &signal_, type };
(dispatch)(ex_, emitter);
}
private:
cancellation_signal signal_;
Executor ex_;
};
template <typename Handler, typename Executor>
class spawn_cancellation_handler<Handler, Executor,
enable_if_t<
is_same<
typename associated_executor<Handler,
Executor>::asio_associated_executor_is_unspecialised,
void
>::value
>>
{
public:
spawn_cancellation_handler(const Handler&, const Executor&)
{
}
cancellation_slot slot()
{
return signal_.slot();
}
void operator()(cancellation_type_t type)
{
signal_.emit(type);
}
private:
cancellation_signal signal_;
};
template <typename Executor>
class initiate_spawn
{
public:
typedef Executor executor_type;
explicit initiate_spawn(const executor_type& ex)
: executor_(ex)
{
}
executor_type get_executor() const noexcept
{
return executor_;
}
template <typename Handler, typename F>
void operator()(Handler&& handler,
F&& f) const
{
typedef decay_t<Handler> handler_type;
typedef decay_t<F> function_type;
typedef spawn_cancellation_handler<
handler_type, Executor> cancel_handler_type;
associated_cancellation_slot_t<handler_type> slot
= boost::asio::get_associated_cancellation_slot(handler);
cancel_handler_type* cancel_handler = slot.is_connected()
? &slot.template emplace<cancel_handler_type>(handler, executor_)
: 0;
cancellation_slot proxy_slot(
cancel_handler
? cancel_handler->slot()
: cancellation_slot());
cancellation_state cancel_state(proxy_slot);
(dispatch)(executor_,
spawned_thread_resumer(
default_spawned_thread_type::spawn(
spawn_entry_point<Executor, function_type, handler_type>(
executor_, static_cast<F&&>(f),
static_cast<Handler&&>(handler)),
proxy_slot, cancel_state)));
}
#if defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
template <typename Handler, typename StackAllocator, typename F>
void operator()(Handler&& handler, allocator_arg_t,
StackAllocator&& stack_allocator,
F&& f) const
{
typedef decay_t<Handler> handler_type;
typedef decay_t<F> function_type;
typedef spawn_cancellation_handler<
handler_type, Executor> cancel_handler_type;
associated_cancellation_slot_t<handler_type> slot
= boost::asio::get_associated_cancellation_slot(handler);
cancel_handler_type* cancel_handler = slot.is_connected()
? &slot.template emplace<cancel_handler_type>(handler, executor_)
: 0;
cancellation_slot proxy_slot(
cancel_handler
? cancel_handler->slot()
: cancellation_slot());
cancellation_state cancel_state(proxy_slot);
(dispatch)(executor_,
spawned_thread_resumer(
spawned_fiber_thread::spawn(allocator_arg_t(),
static_cast<StackAllocator&&>(stack_allocator),
spawn_entry_point<Executor, function_type, handler_type>(
executor_, static_cast<F&&>(f),
static_cast<Handler&&>(handler)),
proxy_slot, cancel_state)));
}
#endif // defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
private:
executor_type executor_;
};
} // namespace detail
template <typename Executor, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type) CompletionToken>
inline auto spawn(const Executor& ex, F&& function, CompletionToken&& token,
#if defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
!is_same<
decay_t<CompletionToken>,
boost::coroutines::attributes
>::value
>,
#endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
>)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type>(
declval<detail::initiate_spawn<Executor>>(),
token, static_cast<F&&>(function)))
{
return async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type>(
detail::initiate_spawn<Executor>(ex),
token, static_cast<F&&>(function));
}
template <typename ExecutionContext, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<
typename ExecutionContext::executor_type>)>>::type) CompletionToken>
inline auto spawn(ExecutionContext& ctx, F&& function, CompletionToken&& token,
#if defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
!is_same<
decay_t<CompletionToken>,
boost::coroutines::attributes
>::value
>,
#endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
>)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<
typename ExecutionContext::executor_type>)>>::type>(
declval<detail::initiate_spawn<
typename ExecutionContext::executor_type>>(),
token, static_cast<F&&>(function)))
{
return (spawn)(ctx.get_executor(), static_cast<F&&>(function),
static_cast<CompletionToken&&>(token));
}
template <typename Executor, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type)
CompletionToken>
inline auto spawn(const basic_yield_context<Executor>& ctx,
F&& function, CompletionToken&& token,
#if defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
!is_same<
decay_t<CompletionToken>,
boost::coroutines::attributes
>::value
>,
#endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
>)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type>(
declval<detail::initiate_spawn<Executor>>(),
token, static_cast<F&&>(function)))
{
return (spawn)(ctx.get_executor(), static_cast<F&&>(function),
static_cast<CompletionToken&&>(token));
}
#if defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
template <typename Executor, typename StackAllocator, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type)
CompletionToken>
inline auto spawn(const Executor& ex, allocator_arg_t,
StackAllocator&& stack_allocator, F&& function, CompletionToken&& token,
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
>)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type>(
declval<detail::initiate_spawn<Executor>>(),
token, allocator_arg_t(),
static_cast<StackAllocator&&>(stack_allocator),
static_cast<F&&>(function)))
{
return async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type>(
detail::initiate_spawn<Executor>(ex), token, allocator_arg_t(),
static_cast<StackAllocator&&>(stack_allocator),
static_cast<F&&>(function));
}
template <typename ExecutionContext, typename StackAllocator, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<
typename ExecutionContext::executor_type>)>>::type) CompletionToken>
inline auto spawn(ExecutionContext& ctx, allocator_arg_t,
StackAllocator&& stack_allocator, F&& function, CompletionToken&& token,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
>)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<
typename ExecutionContext::executor_type>)>>::type>(
declval<detail::initiate_spawn<
typename ExecutionContext::executor_type>>(),
token, allocator_arg_t(),
static_cast<StackAllocator&&>(stack_allocator),
static_cast<F&&>(function)))
{
return (spawn)(ctx.get_executor(), allocator_arg_t(),
static_cast<StackAllocator&&>(stack_allocator),
static_cast<F&&>(function), static_cast<CompletionToken&&>(token));
}
template <typename Executor, typename StackAllocator, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type) CompletionToken>
inline auto spawn(const basic_yield_context<Executor>& ctx, allocator_arg_t,
StackAllocator&& stack_allocator, F&& function, CompletionToken&& token,
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
>)
-> decltype(
async_initiate<CompletionToken,
typename detail::spawn_signature<
result_of_t<F(basic_yield_context<Executor>)>>::type>(
declval<detail::initiate_spawn<Executor>>(), token,
allocator_arg_t(), static_cast<StackAllocator&&>(stack_allocator),
static_cast<F&&>(function)))
{
return (spawn)(ctx.get_executor(), allocator_arg_t(),
static_cast<StackAllocator&&>(stack_allocator),
static_cast<F&&>(function), static_cast<CompletionToken&&>(token));
}
#endif // defined(BOOST_ASIO_HAS_BOOST_CONTEXT_FIBER)
#if defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
namespace detail {
template <typename Executor, typename Function, typename Handler>
class old_spawn_entry_point
{
public:
template <typename F, typename H>
old_spawn_entry_point(const Executor& ex, F&& f, H&& h)
: executor_(ex),
function_(static_cast<F&&>(f)),
handler_(static_cast<H&&>(h))
{
}
void operator()(spawned_thread_base* spawned_thread)
{
const basic_yield_context<Executor> yield(spawned_thread, executor_);
this->call(yield,
void_type<result_of_t<Function(basic_yield_context<Executor>)>>());
}
private:
void call(const basic_yield_context<Executor>& yield, void_type<void>)
{
function_(yield);
static_cast<Handler&&>(handler_)();
}
template <typename T>
void call(const basic_yield_context<Executor>& yield, void_type<T>)
{
static_cast<Handler&&>(handler_)(function_(yield));
}
Executor executor_;
Function function_;
Handler handler_;
};
inline void default_spawn_handler() {}
} // namespace detail
template <typename Function>
inline void spawn(Function&& function,
const boost::coroutines::attributes& attributes)
{
associated_executor_t<decay_t<Function>> ex(
(get_associated_executor)(function));
boost::asio::spawn(ex, static_cast<Function&&>(function), attributes);
}
template <typename Handler, typename Function>
void spawn(Handler&& handler, Function&& function,
const boost::coroutines::attributes& attributes,
constraint_t<
!is_executor<decay_t<Handler>>::value &&
!execution::is_executor<decay_t<Handler>>::value &&
!is_convertible<Handler&, execution_context&>::value>)
{
typedef associated_executor_t<decay_t<Handler>> executor_type;
executor_type ex((get_associated_executor)(handler));
(dispatch)(ex,
detail::spawned_thread_resumer(
detail::spawned_coroutine_thread::spawn(
detail::old_spawn_entry_point<executor_type,
decay_t<Function>, void (*)()>(
ex, static_cast<Function&&>(function),
&detail::default_spawn_handler), attributes)));
}
template <typename Executor, typename Function>
void spawn(basic_yield_context<Executor> ctx, Function&& function,
const boost::coroutines::attributes& attributes)
{
(dispatch)(ctx.get_executor(),
detail::spawned_thread_resumer(
detail::spawned_coroutine_thread::spawn(
detail::old_spawn_entry_point<Executor,
decay_t<Function>, void (*)()>(
ctx.get_executor(), static_cast<Function&&>(function),
&detail::default_spawn_handler), attributes)));
}
template <typename Function, typename Executor>
inline void spawn(const Executor& ex, Function&& function,
const boost::coroutines::attributes& attributes,
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
>)
{
boost::asio::spawn(boost::asio::strand<Executor>(ex),
static_cast<Function&&>(function), attributes);
}
template <typename Function, typename Executor>
inline void spawn(const strand<Executor>& ex, Function&& function,
const boost::coroutines::attributes& attributes)
{
boost::asio::spawn(boost::asio::bind_executor(
ex, &detail::default_spawn_handler),
static_cast<Function&&>(function), attributes);
}
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Function>
inline void spawn(const boost::asio::io_context::strand& s, Function&& function,
const boost::coroutines::attributes& attributes)
{
boost::asio::spawn(boost::asio::bind_executor(
s, &detail::default_spawn_handler),
static_cast<Function&&>(function), attributes);
}
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Function, typename ExecutionContext>
inline void spawn(ExecutionContext& ctx, Function&& function,
const boost::coroutines::attributes& attributes,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
>)
{
boost::asio::spawn(ctx.get_executor(),
static_cast<Function&&>(function), attributes);
}
#endif // defined(BOOST_ASIO_HAS_BOOST_COROUTINE)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_SPAWN_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/co_spawn.hpp | //
// impl/co_spawn.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_CO_SPAWN_HPP
#define BOOST_ASIO_IMPL_CO_SPAWN_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/associated_cancellation_slot.hpp>
#include <boost/asio/awaitable.hpp>
#include <boost/asio/detail/memory.hpp>
#include <boost/asio/detail/recycling_allocator.hpp>
#include <boost/asio/dispatch.hpp>
#include <boost/asio/execution/outstanding_work.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/prefer.hpp>
#include <boost/asio/use_awaitable.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
template <typename Executor, typename = void>
class co_spawn_work_guard
{
public:
typedef decay_t<
prefer_result_t<Executor,
execution::outstanding_work_t::tracked_t
>
> executor_type;
co_spawn_work_guard(const Executor& ex)
: executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked))
{
}
executor_type get_executor() const noexcept
{
return executor_;
}
private:
executor_type executor_;
};
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Executor>
struct co_spawn_work_guard<Executor,
enable_if_t<
!execution::is_executor<Executor>::value
>> : executor_work_guard<Executor>
{
co_spawn_work_guard(const Executor& ex)
: executor_work_guard<Executor>(ex)
{
}
};
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Handler, typename Executor,
typename Function, typename = void>
struct co_spawn_state
{
template <typename H, typename F>
co_spawn_state(H&& h, const Executor& ex, F&& f)
: handler(std::forward<H>(h)),
spawn_work(ex),
handler_work(boost::asio::get_associated_executor(handler, ex)),
function(std::forward<F>(f))
{
}
Handler handler;
co_spawn_work_guard<Executor> spawn_work;
co_spawn_work_guard<associated_executor_t<Handler, Executor>> handler_work;
Function function;
};
template <typename Handler, typename Executor, typename Function>
struct co_spawn_state<Handler, Executor, Function,
enable_if_t<
is_same<
typename associated_executor<Handler,
Executor>::asio_associated_executor_is_unspecialised,
void
>::value
>>
{
template <typename H, typename F>
co_spawn_state(H&& h, const Executor& ex, F&& f)
: handler(std::forward<H>(h)),
handler_work(ex),
function(std::forward<F>(f))
{
}
Handler handler;
co_spawn_work_guard<Executor> handler_work;
Function function;
};
struct co_spawn_dispatch
{
template <typename CompletionToken>
auto operator()(CompletionToken&& token) const
-> decltype(boost::asio::dispatch(std::forward<CompletionToken>(token)))
{
return boost::asio::dispatch(std::forward<CompletionToken>(token));
}
};
struct co_spawn_post
{
template <typename CompletionToken>
auto operator()(CompletionToken&& token) const
-> decltype(boost::asio::post(std::forward<CompletionToken>(token)))
{
return boost::asio::post(std::forward<CompletionToken>(token));
}
};
template <typename T, typename Handler, typename Executor, typename Function>
awaitable<awaitable_thread_entry_point, Executor> co_spawn_entry_point(
awaitable<T, Executor>*, co_spawn_state<Handler, Executor, Function> s)
{
(void) co_await co_spawn_dispatch{};
(co_await awaitable_thread_has_context_switched{}) = false;
std::exception_ptr e = nullptr;
bool done = false;
try
{
T t = co_await s.function();
done = true;
bool switched = (co_await awaitable_thread_has_context_switched{});
if (!switched)
(void) co_await co_spawn_post();
(dispatch)(s.handler_work.get_executor(),
[handler = std::move(s.handler), t = std::move(t)]() mutable
{
std::move(handler)(std::exception_ptr(), std::move(t));
});
co_return;
}
catch (...)
{
if (done)
throw;
e = std::current_exception();
}
bool switched = (co_await awaitable_thread_has_context_switched{});
if (!switched)
(void) co_await co_spawn_post();
(dispatch)(s.handler_work.get_executor(),
[handler = std::move(s.handler), e]() mutable
{
std::move(handler)(e, T());
});
}
template <typename Handler, typename Executor, typename Function>
awaitable<awaitable_thread_entry_point, Executor> co_spawn_entry_point(
awaitable<void, Executor>*, co_spawn_state<Handler, Executor, Function> s)
{
(void) co_await co_spawn_dispatch{};
(co_await awaitable_thread_has_context_switched{}) = false;
std::exception_ptr e = nullptr;
try
{
co_await s.function();
}
catch (...)
{
e = std::current_exception();
}
bool switched = (co_await awaitable_thread_has_context_switched{});
if (!switched)
(void) co_await co_spawn_post();
(dispatch)(s.handler_work.get_executor(),
[handler = std::move(s.handler), e]() mutable
{
std::move(handler)(e);
});
}
template <typename T, typename Executor>
class awaitable_as_function
{
public:
explicit awaitable_as_function(awaitable<T, Executor>&& a)
: awaitable_(std::move(a))
{
}
awaitable<T, Executor> operator()()
{
return std::move(awaitable_);
}
private:
awaitable<T, Executor> awaitable_;
};
template <typename Handler, typename Executor, typename = void>
class co_spawn_cancellation_handler
{
public:
co_spawn_cancellation_handler(const Handler&, const Executor& ex)
: signal_(detail::allocate_shared<cancellation_signal>(
detail::recycling_allocator<cancellation_signal,
detail::thread_info_base::cancellation_signal_tag>())),
ex_(ex)
{
}
cancellation_slot slot()
{
return signal_->slot();
}
void operator()(cancellation_type_t type)
{
shared_ptr<cancellation_signal> sig = signal_;
boost::asio::dispatch(ex_, [sig, type]{ sig->emit(type); });
}
private:
shared_ptr<cancellation_signal> signal_;
Executor ex_;
};
template <typename Handler, typename Executor>
class co_spawn_cancellation_handler<Handler, Executor,
enable_if_t<
is_same<
typename associated_executor<Handler,
Executor>::asio_associated_executor_is_unspecialised,
void
>::value
>>
{
public:
co_spawn_cancellation_handler(const Handler&, const Executor&)
{
}
cancellation_slot slot()
{
return signal_.slot();
}
void operator()(cancellation_type_t type)
{
signal_.emit(type);
}
private:
cancellation_signal signal_;
};
template <typename Executor>
class initiate_co_spawn
{
public:
typedef Executor executor_type;
template <typename OtherExecutor>
explicit initiate_co_spawn(const OtherExecutor& ex)
: ex_(ex)
{
}
executor_type get_executor() const noexcept
{
return ex_;
}
template <typename Handler, typename F>
void operator()(Handler&& handler, F&& f) const
{
typedef result_of_t<F()> awaitable_type;
typedef decay_t<Handler> handler_type;
typedef decay_t<F> function_type;
typedef co_spawn_cancellation_handler<
handler_type, Executor> cancel_handler_type;
auto slot = boost::asio::get_associated_cancellation_slot(handler);
cancel_handler_type* cancel_handler = slot.is_connected()
? &slot.template emplace<cancel_handler_type>(handler, ex_)
: nullptr;
cancellation_slot proxy_slot(
cancel_handler
? cancel_handler->slot()
: cancellation_slot());
cancellation_state cancel_state(proxy_slot);
auto a = (co_spawn_entry_point)(static_cast<awaitable_type*>(nullptr),
co_spawn_state<handler_type, Executor, function_type>(
std::forward<Handler>(handler), ex_, std::forward<F>(f)));
awaitable_handler<executor_type, void>(std::move(a),
ex_, proxy_slot, cancel_state).launch();
}
private:
Executor ex_;
};
} // namespace detail
template <typename Executor, typename T, typename AwaitableExecutor,
BOOST_ASIO_COMPLETION_TOKEN_FOR(
void(std::exception_ptr, T)) CompletionToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
CompletionToken, void(std::exception_ptr, T))
co_spawn(const Executor& ex,
awaitable<T, AwaitableExecutor> a, CompletionToken&& token,
constraint_t<
(is_executor<Executor>::value || execution::is_executor<Executor>::value)
&& is_convertible<Executor, AwaitableExecutor>::value
>)
{
return async_initiate<CompletionToken, void(std::exception_ptr, T)>(
detail::initiate_co_spawn<AwaitableExecutor>(AwaitableExecutor(ex)),
token, detail::awaitable_as_function<T, AwaitableExecutor>(std::move(a)));
}
template <typename Executor, typename AwaitableExecutor,
BOOST_ASIO_COMPLETION_TOKEN_FOR(
void(std::exception_ptr)) CompletionToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
CompletionToken, void(std::exception_ptr))
co_spawn(const Executor& ex,
awaitable<void, AwaitableExecutor> a, CompletionToken&& token,
constraint_t<
(is_executor<Executor>::value || execution::is_executor<Executor>::value)
&& is_convertible<Executor, AwaitableExecutor>::value
>)
{
return async_initiate<CompletionToken, void(std::exception_ptr)>(
detail::initiate_co_spawn<AwaitableExecutor>(AwaitableExecutor(ex)),
token, detail::awaitable_as_function<
void, AwaitableExecutor>(std::move(a)));
}
template <typename ExecutionContext, typename T, typename AwaitableExecutor,
BOOST_ASIO_COMPLETION_TOKEN_FOR(
void(std::exception_ptr, T)) CompletionToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
CompletionToken, void(std::exception_ptr, T))
co_spawn(ExecutionContext& ctx,
awaitable<T, AwaitableExecutor> a, CompletionToken&& token,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
&& is_convertible<typename ExecutionContext::executor_type,
AwaitableExecutor>::value
>)
{
return (co_spawn)(ctx.get_executor(), std::move(a),
std::forward<CompletionToken>(token));
}
template <typename ExecutionContext, typename AwaitableExecutor,
BOOST_ASIO_COMPLETION_TOKEN_FOR(
void(std::exception_ptr)) CompletionToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
CompletionToken, void(std::exception_ptr))
co_spawn(ExecutionContext& ctx,
awaitable<void, AwaitableExecutor> a, CompletionToken&& token,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
&& is_convertible<typename ExecutionContext::executor_type,
AwaitableExecutor>::value
>)
{
return (co_spawn)(ctx.get_executor(), std::move(a),
std::forward<CompletionToken>(token));
}
template <typename Executor, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
result_of_t<F()>>::type) CompletionToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
typename detail::awaitable_signature<result_of_t<F()>>::type)
co_spawn(const Executor& ex, F&& f, CompletionToken&& token,
constraint_t<
is_executor<Executor>::value || execution::is_executor<Executor>::value
>)
{
return async_initiate<CompletionToken,
typename detail::awaitable_signature<result_of_t<F()>>::type>(
detail::initiate_co_spawn<
typename result_of_t<F()>::executor_type>(ex),
token, std::forward<F>(f));
}
template <typename ExecutionContext, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
result_of_t<F()>>::type) CompletionToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
typename detail::awaitable_signature<result_of_t<F()>>::type)
co_spawn(ExecutionContext& ctx, F&& f, CompletionToken&& token,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value
>)
{
return (co_spawn)(ctx.get_executor(), std::forward<F>(f),
std::forward<CompletionToken>(token));
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_CO_SPAWN_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/execution_context.hpp | //
// impl/execution_context.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_EXECUTION_CONTEXT_HPP
#define BOOST_ASIO_IMPL_EXECUTION_CONTEXT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/scoped_ptr.hpp>
#include <boost/asio/detail/service_registry.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if !defined(GENERATING_DOCUMENTATION)
template <typename Service>
inline Service& use_service(execution_context& e)
{
// Check that Service meets the necessary type requirements.
(void)static_cast<execution_context::service*>(static_cast<Service*>(0));
return e.service_registry_->template use_service<Service>();
}
template <typename Service, typename... Args>
Service& make_service(execution_context& e, Args&&... args)
{
detail::scoped_ptr<Service> svc(
new Service(e, static_cast<Args&&>(args)...));
e.service_registry_->template add_service<Service>(svc.get());
Service& result = *svc;
svc.release();
return result;
}
template <typename Service>
inline void add_service(execution_context& e, Service* svc)
{
// Check that Service meets the necessary type requirements.
(void)static_cast<execution_context::service*>(static_cast<Service*>(0));
e.service_registry_->template add_service<Service>(svc);
}
template <typename Service>
inline bool has_service(execution_context& e)
{
// Check that Service meets the necessary type requirements.
(void)static_cast<execution_context::service*>(static_cast<Service*>(0));
return e.service_registry_->template has_service<Service>();
}
#endif // !defined(GENERATING_DOCUMENTATION)
inline execution_context& execution_context::service::context()
{
return owner_;
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_EXECUTION_CONTEXT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/src.hpp | //
// impl/src.hpp
// ~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_SRC_HPP
#define BOOST_ASIO_IMPL_SRC_HPP
#define BOOST_ASIO_SOURCE
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# error Do not compile Asio library source with BOOST_ASIO_HEADER_ONLY defined
#endif
#include <boost/asio/impl/any_completion_executor.ipp>
#include <boost/asio/impl/any_io_executor.ipp>
#include <boost/asio/impl/cancellation_signal.ipp>
#include <boost/asio/impl/connect_pipe.ipp>
#include <boost/asio/impl/error.ipp>
#include <boost/asio/impl/execution_context.ipp>
#include <boost/asio/impl/executor.ipp>
#include <boost/asio/impl/io_context.ipp>
#include <boost/asio/impl/multiple_exceptions.ipp>
#include <boost/asio/impl/serial_port_base.ipp>
#include <boost/asio/impl/system_context.ipp>
#include <boost/asio/impl/thread_pool.ipp>
#include <boost/asio/detail/impl/buffer_sequence_adapter.ipp>
#include <boost/asio/detail/impl/descriptor_ops.ipp>
#include <boost/asio/detail/impl/dev_poll_reactor.ipp>
#include <boost/asio/detail/impl/epoll_reactor.ipp>
#include <boost/asio/detail/impl/eventfd_select_interrupter.ipp>
#include <boost/asio/detail/impl/handler_tracking.ipp>
#include <boost/asio/detail/impl/io_uring_descriptor_service.ipp>
#include <boost/asio/detail/impl/io_uring_file_service.ipp>
#include <boost/asio/detail/impl/io_uring_socket_service_base.ipp>
#include <boost/asio/detail/impl/io_uring_service.ipp>
#include <boost/asio/detail/impl/kqueue_reactor.ipp>
#include <boost/asio/detail/impl/null_event.ipp>
#include <boost/asio/detail/impl/pipe_select_interrupter.ipp>
#include <boost/asio/detail/impl/posix_event.ipp>
#include <boost/asio/detail/impl/posix_mutex.ipp>
#include <boost/asio/detail/impl/posix_serial_port_service.ipp>
#include <boost/asio/detail/impl/posix_thread.ipp>
#include <boost/asio/detail/impl/posix_tss_ptr.ipp>
#include <boost/asio/detail/impl/reactive_descriptor_service.ipp>
#include <boost/asio/detail/impl/reactive_socket_service_base.ipp>
#include <boost/asio/detail/impl/resolver_service_base.ipp>
#include <boost/asio/detail/impl/scheduler.ipp>
#include <boost/asio/detail/impl/select_reactor.ipp>
#include <boost/asio/detail/impl/service_registry.ipp>
#include <boost/asio/detail/impl/signal_set_service.ipp>
#include <boost/asio/detail/impl/socket_ops.ipp>
#include <boost/asio/detail/impl/socket_select_interrupter.ipp>
#include <boost/asio/detail/impl/strand_executor_service.ipp>
#include <boost/asio/detail/impl/strand_service.ipp>
#include <boost/asio/detail/impl/thread_context.ipp>
#include <boost/asio/detail/impl/throw_error.ipp>
#include <boost/asio/detail/impl/timer_queue_ptime.ipp>
#include <boost/asio/detail/impl/timer_queue_set.ipp>
#include <boost/asio/detail/impl/win_iocp_file_service.ipp>
#include <boost/asio/detail/impl/win_iocp_handle_service.ipp>
#include <boost/asio/detail/impl/win_iocp_io_context.ipp>
#include <boost/asio/detail/impl/win_iocp_serial_port_service.ipp>
#include <boost/asio/detail/impl/win_iocp_socket_service_base.ipp>
#include <boost/asio/detail/impl/win_event.ipp>
#include <boost/asio/detail/impl/win_mutex.ipp>
#include <boost/asio/detail/impl/win_object_handle_service.ipp>
#include <boost/asio/detail/impl/win_static_mutex.ipp>
#include <boost/asio/detail/impl/win_thread.ipp>
#include <boost/asio/detail/impl/win_tss_ptr.ipp>
#include <boost/asio/detail/impl/winrt_ssocket_service_base.ipp>
#include <boost/asio/detail/impl/winrt_timer_scheduler.ipp>
#include <boost/asio/detail/impl/winsock_init.ipp>
#include <boost/asio/execution/impl/bad_executor.ipp>
#include <boost/asio/experimental/impl/channel_error.ipp>
#include <boost/asio/generic/detail/impl/endpoint.ipp>
#include <boost/asio/ip/impl/address.ipp>
#include <boost/asio/ip/impl/address_v4.ipp>
#include <boost/asio/ip/impl/address_v6.ipp>
#include <boost/asio/ip/impl/host_name.ipp>
#include <boost/asio/ip/impl/network_v4.ipp>
#include <boost/asio/ip/impl/network_v6.ipp>
#include <boost/asio/ip/detail/impl/endpoint.ipp>
#include <boost/asio/local/detail/impl/endpoint.ipp>
#endif // BOOST_ASIO_IMPL_SRC_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/impl/buffered_read_stream.hpp | //
// impl/buffered_read_stream.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_IMPL_BUFFERED_READ_STREAM_HPP
#define BOOST_ASIO_IMPL_BUFFERED_READ_STREAM_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/associator.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
template <typename Stream>
std::size_t buffered_read_stream<Stream>::fill()
{
detail::buffer_resize_guard<detail::buffered_stream_storage>
resize_guard(storage_);
std::size_t previous_size = storage_.size();
storage_.resize(storage_.capacity());
storage_.resize(previous_size + next_layer_.read_some(buffer(
storage_.data() + previous_size,
storage_.size() - previous_size)));
resize_guard.commit();
return storage_.size() - previous_size;
}
template <typename Stream>
std::size_t buffered_read_stream<Stream>::fill(boost::system::error_code& ec)
{
detail::buffer_resize_guard<detail::buffered_stream_storage>
resize_guard(storage_);
std::size_t previous_size = storage_.size();
storage_.resize(storage_.capacity());
storage_.resize(previous_size + next_layer_.read_some(buffer(
storage_.data() + previous_size,
storage_.size() - previous_size),
ec));
resize_guard.commit();
return storage_.size() - previous_size;
}
namespace detail
{
template <typename ReadHandler>
class buffered_fill_handler
{
public:
buffered_fill_handler(detail::buffered_stream_storage& storage,
std::size_t previous_size, ReadHandler& handler)
: storage_(storage),
previous_size_(previous_size),
handler_(static_cast<ReadHandler&&>(handler))
{
}
buffered_fill_handler(const buffered_fill_handler& other)
: storage_(other.storage_),
previous_size_(other.previous_size_),
handler_(other.handler_)
{
}
buffered_fill_handler(buffered_fill_handler&& other)
: storage_(other.storage_),
previous_size_(other.previous_size_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(const boost::system::error_code& ec,
const std::size_t bytes_transferred)
{
storage_.resize(previous_size_ + bytes_transferred);
static_cast<ReadHandler&&>(handler_)(ec, bytes_transferred);
}
//private:
detail::buffered_stream_storage& storage_;
std::size_t previous_size_;
ReadHandler handler_;
};
template <typename ReadHandler>
inline bool asio_handler_is_continuation(
buffered_fill_handler<ReadHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Stream>
class initiate_async_buffered_fill
{
public:
typedef typename remove_reference_t<
Stream>::lowest_layer_type::executor_type executor_type;
explicit initiate_async_buffered_fill(
remove_reference_t<Stream>& next_layer)
: next_layer_(next_layer)
{
}
executor_type get_executor() const noexcept
{
return next_layer_.lowest_layer().get_executor();
}
template <typename ReadHandler>
void operator()(ReadHandler&& handler,
buffered_stream_storage* storage) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
non_const_lvalue<ReadHandler> handler2(handler);
std::size_t previous_size = storage->size();
storage->resize(storage->capacity());
next_layer_.async_read_some(
buffer(
storage->data() + previous_size,
storage->size() - previous_size),
buffered_fill_handler<decay_t<ReadHandler>>(
*storage, previous_size, handler2.value));
}
private:
remove_reference_t<Stream>& next_layer_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename ReadHandler, typename DefaultCandidate>
struct associator<Associator,
detail::buffered_fill_handler<ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::buffered_fill_handler<ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(const detail::buffered_fill_handler<ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename Stream>
template <
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadHandler>
inline auto buffered_read_stream<Stream>::async_fill(ReadHandler&& handler)
-> decltype(
async_initiate<ReadHandler,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_buffered_fill<Stream>>(),
handler, declval<detail::buffered_stream_storage*>()))
{
return async_initiate<ReadHandler,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_buffered_fill<Stream>(next_layer_),
handler, &storage_);
}
template <typename Stream>
template <typename MutableBufferSequence>
std::size_t buffered_read_stream<Stream>::read_some(
const MutableBufferSequence& buffers)
{
using boost::asio::buffer_size;
if (buffer_size(buffers) == 0)
return 0;
if (storage_.empty())
this->fill();
return this->copy(buffers);
}
template <typename Stream>
template <typename MutableBufferSequence>
std::size_t buffered_read_stream<Stream>::read_some(
const MutableBufferSequence& buffers, boost::system::error_code& ec)
{
ec = boost::system::error_code();
using boost::asio::buffer_size;
if (buffer_size(buffers) == 0)
return 0;
if (storage_.empty() && !this->fill(ec))
return 0;
return this->copy(buffers);
}
namespace detail
{
template <typename MutableBufferSequence, typename ReadHandler>
class buffered_read_some_handler
{
public:
buffered_read_some_handler(detail::buffered_stream_storage& storage,
const MutableBufferSequence& buffers, ReadHandler& handler)
: storage_(storage),
buffers_(buffers),
handler_(static_cast<ReadHandler&&>(handler))
{
}
buffered_read_some_handler(const buffered_read_some_handler& other)
: storage_(other.storage_),
buffers_(other.buffers_),
handler_(other.handler_)
{
}
buffered_read_some_handler(buffered_read_some_handler&& other)
: storage_(other.storage_),
buffers_(other.buffers_),
handler_(static_cast<ReadHandler&&>(other.handler_))
{
}
void operator()(const boost::system::error_code& ec, std::size_t)
{
if (ec || storage_.empty())
{
const std::size_t length = 0;
static_cast<ReadHandler&&>(handler_)(ec, length);
}
else
{
const std::size_t bytes_copied = boost::asio::buffer_copy(
buffers_, storage_.data(), storage_.size());
storage_.consume(bytes_copied);
static_cast<ReadHandler&&>(handler_)(ec, bytes_copied);
}
}
//private:
detail::buffered_stream_storage& storage_;
MutableBufferSequence buffers_;
ReadHandler handler_;
};
template <typename MutableBufferSequence, typename ReadHandler>
inline bool asio_handler_is_continuation(
buffered_read_some_handler<
MutableBufferSequence, ReadHandler>* this_handler)
{
return boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Stream>
class initiate_async_buffered_read_some
{
public:
typedef typename remove_reference_t<
Stream>::lowest_layer_type::executor_type executor_type;
explicit initiate_async_buffered_read_some(
remove_reference_t<Stream>& next_layer)
: next_layer_(next_layer)
{
}
executor_type get_executor() const noexcept
{
return next_layer_.lowest_layer().get_executor();
}
template <typename ReadHandler, typename MutableBufferSequence>
void operator()(ReadHandler&& handler,
buffered_stream_storage* storage,
const MutableBufferSequence& buffers) const
{
// If you get an error on the following line it means that your handler
// does not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
using boost::asio::buffer_size;
non_const_lvalue<ReadHandler> handler2(handler);
if (buffer_size(buffers) == 0 || !storage->empty())
{
next_layer_.async_read_some(BOOST_ASIO_MUTABLE_BUFFER(0, 0),
buffered_read_some_handler<MutableBufferSequence,
decay_t<ReadHandler>>(
*storage, buffers, handler2.value));
}
else
{
initiate_async_buffered_fill<Stream>(this->next_layer_)(
buffered_read_some_handler<MutableBufferSequence,
decay_t<ReadHandler>>(
*storage, buffers, handler2.value),
storage);
}
}
private:
remove_reference_t<Stream>& next_layer_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename MutableBufferSequence, typename ReadHandler,
typename DefaultCandidate>
struct associator<Associator,
detail::buffered_read_some_handler<MutableBufferSequence, ReadHandler>,
DefaultCandidate>
: Associator<ReadHandler, DefaultCandidate>
{
static typename Associator<ReadHandler, DefaultCandidate>::type get(
const detail::buffered_read_some_handler<
MutableBufferSequence, ReadHandler>& h) noexcept
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_);
}
static auto get(
const detail::buffered_read_some_handler<
MutableBufferSequence, ReadHandler>& h,
const DefaultCandidate& c) noexcept
-> decltype(Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c))
{
return Associator<ReadHandler, DefaultCandidate>::get(h.handler_, c);
}
};
#endif // !defined(GENERATING_DOCUMENTATION)
template <typename Stream>
template <typename MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadHandler>
inline auto buffered_read_stream<Stream>::async_read_some(
const MutableBufferSequence& buffers, ReadHandler&& handler)
-> decltype(
async_initiate<ReadHandler,
void (boost::system::error_code, std::size_t)>(
declval<detail::initiate_async_buffered_read_some<Stream>>(),
handler, declval<detail::buffered_stream_storage*>(), buffers))
{
return async_initiate<ReadHandler,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_buffered_read_some<Stream>(next_layer_),
handler, &storage_, buffers);
}
template <typename Stream>
template <typename MutableBufferSequence>
std::size_t buffered_read_stream<Stream>::peek(
const MutableBufferSequence& buffers)
{
if (storage_.empty())
this->fill();
return this->peek_copy(buffers);
}
template <typename Stream>
template <typename MutableBufferSequence>
std::size_t buffered_read_stream<Stream>::peek(
const MutableBufferSequence& buffers, boost::system::error_code& ec)
{
ec = boost::system::error_code();
if (storage_.empty() && !this->fill(ec))
return 0;
return this->peek_copy(buffers);
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_BUFFERED_READ_STREAM_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/generic/seq_packet_protocol.hpp | //
// generic/seq_packet_protocol.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_GENERIC_SEQ_PACKET_PROTOCOL_HPP
#define BOOST_ASIO_GENERIC_SEQ_PACKET_PROTOCOL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <typeinfo>
#include <boost/asio/basic_seq_packet_socket.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/asio/generic/basic_endpoint.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace generic {
/// Encapsulates the flags needed for a generic sequenced packet socket.
/**
* The boost::asio::generic::seq_packet_protocol class contains flags necessary
* for seq_packet-oriented sockets of any address family and protocol.
*
* @par Examples
* Constructing using a native address family and socket protocol:
* @code seq_packet_protocol p(AF_INET, IPPROTO_SCTP); @endcode
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Safe.
*
* @par Concepts:
* Protocol.
*/
class seq_packet_protocol
{
public:
/// Construct a protocol object for a specific address family and protocol.
seq_packet_protocol(int address_family, int socket_protocol)
: family_(address_family),
protocol_(socket_protocol)
{
}
/// Construct a generic protocol object from a specific protocol.
/**
* @throws @c bad_cast Thrown if the source protocol is not based around
* sequenced packets.
*/
template <typename Protocol>
seq_packet_protocol(const Protocol& source_protocol)
: family_(source_protocol.family()),
protocol_(source_protocol.protocol())
{
if (source_protocol.type() != type())
{
std::bad_cast ex;
boost::asio::detail::throw_exception(ex);
}
}
/// Obtain an identifier for the type of the protocol.
int type() const noexcept
{
return BOOST_ASIO_OS_DEF(SOCK_SEQPACKET);
}
/// Obtain an identifier for the protocol.
int protocol() const noexcept
{
return protocol_;
}
/// Obtain an identifier for the protocol family.
int family() const noexcept
{
return family_;
}
/// Compare two protocols for equality.
friend bool operator==(const seq_packet_protocol& p1,
const seq_packet_protocol& p2)
{
return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_;
}
/// Compare two protocols for inequality.
friend bool operator!=(const seq_packet_protocol& p1,
const seq_packet_protocol& p2)
{
return !(p1 == p2);
}
/// The type of an endpoint.
typedef basic_endpoint<seq_packet_protocol> endpoint;
/// The generic socket type.
typedef basic_seq_packet_socket<seq_packet_protocol> socket;
private:
int family_;
int protocol_;
};
} // namespace generic
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_GENERIC_SEQ_PACKET_PROTOCOL_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/generic/stream_protocol.hpp | //
// generic/stream_protocol.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_GENERIC_STREAM_PROTOCOL_HPP
#define BOOST_ASIO_GENERIC_STREAM_PROTOCOL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <typeinfo>
#include <boost/asio/basic_socket_iostream.hpp>
#include <boost/asio/basic_stream_socket.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/asio/generic/basic_endpoint.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace generic {
/// Encapsulates the flags needed for a generic stream-oriented socket.
/**
* The boost::asio::generic::stream_protocol class contains flags necessary for
* stream-oriented sockets of any address family and protocol.
*
* @par Examples
* Constructing using a native address family and socket protocol:
* @code stream_protocol p(AF_INET, IPPROTO_TCP); @endcode
* Constructing from a specific protocol type:
* @code stream_protocol p(boost::asio::ip::tcp::v4()); @endcode
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Safe.
*
* @par Concepts:
* Protocol.
*/
class stream_protocol
{
public:
/// Construct a protocol object for a specific address family and protocol.
stream_protocol(int address_family, int socket_protocol)
: family_(address_family),
protocol_(socket_protocol)
{
}
/// Construct a generic protocol object from a specific protocol.
/**
* @throws @c bad_cast Thrown if the source protocol is not stream-oriented.
*/
template <typename Protocol>
stream_protocol(const Protocol& source_protocol)
: family_(source_protocol.family()),
protocol_(source_protocol.protocol())
{
if (source_protocol.type() != type())
{
std::bad_cast ex;
boost::asio::detail::throw_exception(ex);
}
}
/// Obtain an identifier for the type of the protocol.
int type() const noexcept
{
return BOOST_ASIO_OS_DEF(SOCK_STREAM);
}
/// Obtain an identifier for the protocol.
int protocol() const noexcept
{
return protocol_;
}
/// Obtain an identifier for the protocol family.
int family() const noexcept
{
return family_;
}
/// Compare two protocols for equality.
friend bool operator==(const stream_protocol& p1, const stream_protocol& p2)
{
return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_;
}
/// Compare two protocols for inequality.
friend bool operator!=(const stream_protocol& p1, const stream_protocol& p2)
{
return !(p1 == p2);
}
/// The type of an endpoint.
typedef basic_endpoint<stream_protocol> endpoint;
/// The generic socket type.
typedef basic_stream_socket<stream_protocol> socket;
#if !defined(BOOST_ASIO_NO_IOSTREAM)
/// The generic socket iostream type.
typedef basic_socket_iostream<stream_protocol> iostream;
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
private:
int family_;
int protocol_;
};
} // namespace generic
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_GENERIC_STREAM_PROTOCOL_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/generic/basic_endpoint.hpp | //
// generic/basic_endpoint.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_GENERIC_BASIC_ENDPOINT_HPP
#define BOOST_ASIO_GENERIC_BASIC_ENDPOINT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/generic/detail/endpoint.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace generic {
/// Describes an endpoint for any socket type.
/**
* The boost::asio::generic::basic_endpoint class template describes an endpoint
* that may be associated with any socket type.
*
* @note The socket types sockaddr type must be able to fit into a
* @c sockaddr_storage structure.
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Unsafe.
*
* @par Concepts:
* Endpoint.
*/
template <typename Protocol>
class basic_endpoint
{
public:
/// The protocol type associated with the endpoint.
typedef Protocol protocol_type;
/// The type of the endpoint structure. This type is dependent on the
/// underlying implementation of the socket layer.
#if defined(GENERATING_DOCUMENTATION)
typedef implementation_defined data_type;
#else
typedef boost::asio::detail::socket_addr_type data_type;
#endif
/// Default constructor.
basic_endpoint() noexcept
{
}
/// Construct an endpoint from the specified socket address.
basic_endpoint(const void* socket_address,
std::size_t socket_address_size, int socket_protocol = 0)
: impl_(socket_address, socket_address_size, socket_protocol)
{
}
/// Construct an endpoint from the specific endpoint type.
template <typename Endpoint>
basic_endpoint(const Endpoint& endpoint)
: impl_(endpoint.data(), endpoint.size(), endpoint.protocol().protocol())
{
}
/// Copy constructor.
basic_endpoint(const basic_endpoint& other)
: impl_(other.impl_)
{
}
/// Move constructor.
basic_endpoint(basic_endpoint&& other)
: impl_(other.impl_)
{
}
/// Assign from another endpoint.
basic_endpoint& operator=(const basic_endpoint& other)
{
impl_ = other.impl_;
return *this;
}
/// Move-assign from another endpoint.
basic_endpoint& operator=(basic_endpoint&& other)
{
impl_ = other.impl_;
return *this;
}
/// The protocol associated with the endpoint.
protocol_type protocol() const
{
return protocol_type(impl_.family(), impl_.protocol());
}
/// Get the underlying endpoint in the native type.
data_type* data()
{
return impl_.data();
}
/// Get the underlying endpoint in the native type.
const data_type* data() const
{
return impl_.data();
}
/// Get the underlying size of the endpoint in the native type.
std::size_t size() const
{
return impl_.size();
}
/// Set the underlying size of the endpoint in the native type.
void resize(std::size_t new_size)
{
impl_.resize(new_size);
}
/// Get the capacity of the endpoint in the native type.
std::size_t capacity() const
{
return impl_.capacity();
}
/// Compare two endpoints for equality.
friend bool operator==(const basic_endpoint<Protocol>& e1,
const basic_endpoint<Protocol>& e2)
{
return e1.impl_ == e2.impl_;
}
/// Compare two endpoints for inequality.
friend bool operator!=(const basic_endpoint<Protocol>& e1,
const basic_endpoint<Protocol>& e2)
{
return !(e1.impl_ == e2.impl_);
}
/// Compare endpoints for ordering.
friend bool operator<(const basic_endpoint<Protocol>& e1,
const basic_endpoint<Protocol>& e2)
{
return e1.impl_ < e2.impl_;
}
/// Compare endpoints for ordering.
friend bool operator>(const basic_endpoint<Protocol>& e1,
const basic_endpoint<Protocol>& e2)
{
return e2.impl_ < e1.impl_;
}
/// Compare endpoints for ordering.
friend bool operator<=(const basic_endpoint<Protocol>& e1,
const basic_endpoint<Protocol>& e2)
{
return !(e2 < e1);
}
/// Compare endpoints for ordering.
friend bool operator>=(const basic_endpoint<Protocol>& e1,
const basic_endpoint<Protocol>& e2)
{
return !(e1 < e2);
}
private:
// The underlying generic endpoint.
boost::asio::generic::detail::endpoint impl_;
};
} // namespace generic
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_GENERIC_BASIC_ENDPOINT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/generic/datagram_protocol.hpp | //
// generic/datagram_protocol.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_GENERIC_DATAGRAM_PROTOCOL_HPP
#define BOOST_ASIO_GENERIC_DATAGRAM_PROTOCOL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <typeinfo>
#include <boost/asio/basic_datagram_socket.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/asio/generic/basic_endpoint.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace generic {
/// Encapsulates the flags needed for a generic datagram-oriented socket.
/**
* The boost::asio::generic::datagram_protocol class contains flags necessary
* for datagram-oriented sockets of any address family and protocol.
*
* @par Examples
* Constructing using a native address family and socket protocol:
* @code datagram_protocol p(AF_INET, IPPROTO_UDP); @endcode
* Constructing from a specific protocol type:
* @code datagram_protocol p(boost::asio::ip::udp::v4()); @endcode
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Safe.
*
* @par Concepts:
* Protocol.
*/
class datagram_protocol
{
public:
/// Construct a protocol object for a specific address family and protocol.
datagram_protocol(int address_family, int socket_protocol)
: family_(address_family),
protocol_(socket_protocol)
{
}
/// Construct a generic protocol object from a specific protocol.
/**
* @throws @c bad_cast Thrown if the source protocol is not datagram-oriented.
*/
template <typename Protocol>
datagram_protocol(const Protocol& source_protocol)
: family_(source_protocol.family()),
protocol_(source_protocol.protocol())
{
if (source_protocol.type() != type())
{
std::bad_cast ex;
boost::asio::detail::throw_exception(ex);
}
}
/// Obtain an identifier for the type of the protocol.
int type() const noexcept
{
return BOOST_ASIO_OS_DEF(SOCK_DGRAM);
}
/// Obtain an identifier for the protocol.
int protocol() const noexcept
{
return protocol_;
}
/// Obtain an identifier for the protocol family.
int family() const noexcept
{
return family_;
}
/// Compare two protocols for equality.
friend bool operator==(const datagram_protocol& p1,
const datagram_protocol& p2)
{
return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_;
}
/// Compare two protocols for inequality.
friend bool operator!=(const datagram_protocol& p1,
const datagram_protocol& p2)
{
return !(p1 == p2);
}
/// The type of an endpoint.
typedef basic_endpoint<datagram_protocol> endpoint;
/// The generic socket type.
typedef basic_datagram_socket<datagram_protocol> socket;
private:
int family_;
int protocol_;
};
} // namespace generic
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_GENERIC_DATAGRAM_PROTOCOL_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/generic/raw_protocol.hpp | //
// generic/raw_protocol.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_GENERIC_RAW_PROTOCOL_HPP
#define BOOST_ASIO_GENERIC_RAW_PROTOCOL_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <typeinfo>
#include <boost/asio/basic_raw_socket.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/asio/generic/basic_endpoint.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace generic {
/// Encapsulates the flags needed for a generic raw socket.
/**
* The boost::asio::generic::raw_protocol class contains flags necessary for
* raw sockets of any address family and protocol.
*
* @par Examples
* Constructing using a native address family and socket protocol:
* @code raw_protocol p(AF_INET, IPPROTO_ICMP); @endcode
* Constructing from a specific protocol type:
* @code raw_protocol p(boost::asio::ip::icmp::v4()); @endcode
*
* @par Thread Safety
* @e Distinct @e objects: Safe.@n
* @e Shared @e objects: Safe.
*
* @par Concepts:
* Protocol.
*/
class raw_protocol
{
public:
/// Construct a protocol object for a specific address family and protocol.
raw_protocol(int address_family, int socket_protocol)
: family_(address_family),
protocol_(socket_protocol)
{
}
/// Construct a generic protocol object from a specific protocol.
/**
* @throws @c bad_cast Thrown if the source protocol is not raw-oriented.
*/
template <typename Protocol>
raw_protocol(const Protocol& source_protocol)
: family_(source_protocol.family()),
protocol_(source_protocol.protocol())
{
if (source_protocol.type() != type())
{
std::bad_cast ex;
boost::asio::detail::throw_exception(ex);
}
}
/// Obtain an identifier for the type of the protocol.
int type() const noexcept
{
return BOOST_ASIO_OS_DEF(SOCK_RAW);
}
/// Obtain an identifier for the protocol.
int protocol() const noexcept
{
return protocol_;
}
/// Obtain an identifier for the protocol family.
int family() const noexcept
{
return family_;
}
/// Compare two protocols for equality.
friend bool operator==(const raw_protocol& p1, const raw_protocol& p2)
{
return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_;
}
/// Compare two protocols for inequality.
friend bool operator!=(const raw_protocol& p1, const raw_protocol& p2)
{
return !(p1 == p2);
}
/// The type of an endpoint.
typedef basic_endpoint<raw_protocol> endpoint;
/// The generic socket type.
typedef basic_raw_socket<raw_protocol> socket;
private:
int family_;
int protocol_;
};
} // namespace generic
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_GENERIC_RAW_PROTOCOL_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/generic/detail/endpoint.hpp | //
// generic/detail/endpoint.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_GENERIC_DETAIL_ENDPOINT_HPP
#define BOOST_ASIO_GENERIC_DETAIL_ENDPOINT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <cstddef>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace generic {
namespace detail {
// Helper class for implementing a generic socket endpoint.
class endpoint
{
public:
// Default constructor.
BOOST_ASIO_DECL endpoint();
// Construct an endpoint from the specified raw bytes.
BOOST_ASIO_DECL endpoint(const void* sock_addr,
std::size_t sock_addr_size, int sock_protocol);
// Copy constructor.
endpoint(const endpoint& other)
: data_(other.data_),
size_(other.size_),
protocol_(other.protocol_)
{
}
// Assign from another endpoint.
endpoint& operator=(const endpoint& other)
{
data_ = other.data_;
size_ = other.size_;
protocol_ = other.protocol_;
return *this;
}
// Get the address family associated with the endpoint.
int family() const
{
return data_.base.sa_family;
}
// Get the socket protocol associated with the endpoint.
int protocol() const
{
return protocol_;
}
// Get the underlying endpoint in the native type.
boost::asio::detail::socket_addr_type* data()
{
return &data_.base;
}
// Get the underlying endpoint in the native type.
const boost::asio::detail::socket_addr_type* data() const
{
return &data_.base;
}
// Get the underlying size of the endpoint in the native type.
std::size_t size() const
{
return size_;
}
// Set the underlying size of the endpoint in the native type.
BOOST_ASIO_DECL void resize(std::size_t size);
// Get the capacity of the endpoint in the native type.
std::size_t capacity() const
{
return sizeof(boost::asio::detail::sockaddr_storage_type);
}
// Compare two endpoints for equality.
BOOST_ASIO_DECL friend bool operator==(
const endpoint& e1, const endpoint& e2);
// Compare endpoints for ordering.
BOOST_ASIO_DECL friend bool operator<(
const endpoint& e1, const endpoint& e2);
private:
// The underlying socket address.
union data_union
{
boost::asio::detail::socket_addr_type base;
boost::asio::detail::sockaddr_storage_type generic;
} data_;
// The length of the socket address stored in the endpoint.
std::size_t size_;
// The socket protocol associated with the endpoint.
int protocol_;
// Initialise with a specified memory.
BOOST_ASIO_DECL void init(const void* sock_addr,
std::size_t sock_addr_size, int sock_protocol);
};
} // namespace detail
} // namespace generic
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/generic/detail/impl/endpoint.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // BOOST_ASIO_GENERIC_DETAIL_ENDPOINT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/outstanding_work.hpp | //
// execution/outstanding_work.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_OUTSTANDING_WORK_HPP
#define BOOST_ASIO_EXECUTION_OUTSTANDING_WORK_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/is_applicable_property.hpp>
#include <boost/asio/query.hpp>
#include <boost/asio/traits/query_free.hpp>
#include <boost/asio/traits/query_member.hpp>
#include <boost/asio/traits/query_static_constexpr_member.hpp>
#include <boost/asio/traits/static_query.hpp>
#include <boost/asio/traits/static_require.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// A property to describe whether task submission is likely in the future.
struct outstanding_work_t
{
/// The outstanding_work_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The top-level outstanding_work_t property cannot be required.
static constexpr bool is_requirable = false;
/// The top-level outstanding_work_t property cannot be preferred.
static constexpr bool is_preferable = false;
/// The type returned by queries against an @c any_executor.
typedef outstanding_work_t polymorphic_query_result_type;
/// A sub-property that indicates that the executor does not represent likely
/// future submission of a function object.
struct untracked_t
{
/// The outstanding_work_t::untracked_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The outstanding_work_t::untracked_t property can be required.
static constexpr bool is_requirable = true;
/// The outstanding_work_t::untracked_t property can be preferred.
static constexpr bool is_preferable = true;
/// The type returned by queries against an @c any_executor.
typedef outstanding_work_t polymorphic_query_result_type;
/// Default constructor.
constexpr untracked_t();
/// Get the value associated with a property object.
/**
* @returns untracked_t();
*/
static constexpr outstanding_work_t value();
};
/// A sub-property that indicates that the executor represents likely
/// future submission of a function object.
struct tracked_t
{
/// The outstanding_work_t::untracked_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The outstanding_work_t::tracked_t property can be required.
static constexpr bool is_requirable = true;
/// The outstanding_work_t::tracked_t property can be preferred.
static constexpr bool is_preferable = true;
/// The type returned by queries against an @c any_executor.
typedef outstanding_work_t polymorphic_query_result_type;
/// Default constructor.
constexpr tracked_t();
/// Get the value associated with a property object.
/**
* @returns tracked_t();
*/
static constexpr outstanding_work_t value();
};
/// A special value used for accessing the outstanding_work_t::untracked_t
/// property.
static constexpr untracked_t untracked;
/// A special value used for accessing the outstanding_work_t::tracked_t
/// property.
static constexpr tracked_t tracked;
/// Default constructor.
constexpr outstanding_work_t();
/// Construct from a sub-property value.
constexpr outstanding_work_t(untracked_t);
/// Construct from a sub-property value.
constexpr outstanding_work_t(tracked_t);
/// Compare property values for equality.
friend constexpr bool operator==(
const outstanding_work_t& a, const outstanding_work_t& b) noexcept;
/// Compare property values for inequality.
friend constexpr bool operator!=(
const outstanding_work_t& a, const outstanding_work_t& b) noexcept;
};
/// A special value used for accessing the outstanding_work_t property.
constexpr outstanding_work_t outstanding_work;
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
namespace detail {
namespace outstanding_work {
template <int I> struct untracked_t;
template <int I> struct tracked_t;
} // namespace outstanding_work
template <int I = 0>
struct outstanding_work_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = false;
static constexpr bool is_preferable = false;
typedef outstanding_work_t polymorphic_query_result_type;
typedef detail::outstanding_work::untracked_t<I> untracked_t;
typedef detail::outstanding_work::tracked_t<I> tracked_t;
constexpr outstanding_work_t()
: value_(-1)
{
}
constexpr outstanding_work_t(untracked_t)
: value_(0)
{
}
constexpr outstanding_work_t(tracked_t)
: value_(1)
{
}
template <typename T>
struct proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
struct type
{
template <typename P>
auto query(P&& p) const
noexcept(
noexcept(
declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
)
)
-> decltype(
declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
);
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
};
template <typename T>
struct static_proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
struct type
{
template <typename P>
static constexpr auto query(P&& p)
noexcept(
noexcept(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
)
-> decltype(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
{
return T::query(static_cast<P&&>(p));
}
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
};
template <typename T>
struct query_member :
traits::query_member<typename proxy<T>::type, outstanding_work_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename static_proxy<T>::type, outstanding_work_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, untracked_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, untracked_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, untracked_t>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, tracked_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::static_query<T, untracked_t>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, tracked_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, tracked_t>::value();
}
template <typename E,
typename T = decltype(outstanding_work_t::static_query<E>())>
static constexpr const T static_query_v
= outstanding_work_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
friend constexpr bool operator==(
const outstanding_work_t& a, const outstanding_work_t& b)
{
return a.value_ == b.value_;
}
friend constexpr bool operator!=(
const outstanding_work_t& a, const outstanding_work_t& b)
{
return a.value_ != b.value_;
}
struct convertible_from_outstanding_work_t
{
constexpr convertible_from_outstanding_work_t(outstanding_work_t)
{
}
};
template <typename Executor>
friend constexpr outstanding_work_t query(
const Executor& ex, convertible_from_outstanding_work_t,
enable_if_t<
can_query<const Executor&, untracked_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&,
outstanding_work_t<>::untracked_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, untracked_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, untracked_t());
}
template <typename Executor>
friend constexpr outstanding_work_t query(
const Executor& ex, convertible_from_outstanding_work_t,
enable_if_t<
!can_query<const Executor&, untracked_t>::value
>* = 0,
enable_if_t<
can_query<const Executor&, tracked_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&,
outstanding_work_t<>::tracked_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, tracked_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, tracked_t());
}
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(untracked_t, untracked);
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(tracked_t, tracked);
private:
int value_;
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T outstanding_work_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I>
const typename outstanding_work_t<I>::untracked_t
outstanding_work_t<I>::untracked;
template <int I>
const typename outstanding_work_t<I>::tracked_t
outstanding_work_t<I>::tracked;
namespace outstanding_work {
template <int I = 0>
struct untracked_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
typedef outstanding_work_t<I> polymorphic_query_result_type;
constexpr untracked_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename outstanding_work_t<I>::template proxy<T>::type, untracked_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename outstanding_work_t<I>::template static_proxy<T>::type,
untracked_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename T>
static constexpr untracked_t static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::query_free<T, untracked_t>::is_valid
>* = 0,
enable_if_t<
!can_query<T, tracked_t<I>>::value
>* = 0) noexcept
{
return untracked_t();
}
template <typename E, typename T = decltype(untracked_t::static_query<E>())>
static constexpr const T static_query_v = untracked_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr outstanding_work_t<I> value()
{
return untracked_t();
}
friend constexpr bool operator==(const untracked_t&, const untracked_t&)
{
return true;
}
friend constexpr bool operator!=(const untracked_t&, const untracked_t&)
{
return false;
}
friend constexpr bool operator==(const untracked_t&, const tracked_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const untracked_t&, const tracked_t<I>&)
{
return true;
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T untracked_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I = 0>
struct tracked_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
typedef outstanding_work_t<I> polymorphic_query_result_type;
constexpr tracked_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename outstanding_work_t<I>::template proxy<T>::type, tracked_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename outstanding_work_t<I>::template static_proxy<T>::type,
tracked_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename E, typename T = decltype(tracked_t::static_query<E>())>
static constexpr const T static_query_v = tracked_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr outstanding_work_t<I> value()
{
return tracked_t();
}
friend constexpr bool operator==(const tracked_t&, const tracked_t&)
{
return true;
}
friend constexpr bool operator!=(const tracked_t&, const tracked_t&)
{
return false;
}
friend constexpr bool operator==(const tracked_t&, const untracked_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const tracked_t&, const untracked_t<I>&)
{
return true;
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T tracked_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace outstanding_work
} // namespace detail
typedef detail::outstanding_work_t<> outstanding_work_t;
constexpr outstanding_work_t outstanding_work;
} // namespace execution
#if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
struct is_applicable_property<T, execution::outstanding_work_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::outstanding_work_t::untracked_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::outstanding_work_t::tracked_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
#endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
template <typename T>
struct query_free_default<T, execution::outstanding_work_t,
enable_if_t<
can_query<T, execution::outstanding_work_t::untracked_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::outstanding_work_t::untracked_t>::value;
typedef execution::outstanding_work_t result_type;
};
template <typename T>
struct query_free_default<T, execution::outstanding_work_t,
enable_if_t<
!can_query<T, execution::outstanding_work_t::untracked_t>::value
&& can_query<T, execution::outstanding_work_t::tracked_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::outstanding_work_t::tracked_t>::value;
typedef execution::outstanding_work_t result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
|| !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
struct static_query<T, execution::outstanding_work_t,
enable_if_t<
execution::detail::outstanding_work_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::outstanding_work_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::outstanding_work_t<0>::
query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::outstanding_work_t,
enable_if_t<
!execution::detail::outstanding_work_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::outstanding_work_t<0>::
query_member<T>::is_valid
&& traits::static_query<T,
execution::outstanding_work_t::untracked_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::outstanding_work_t::untracked_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T,
execution::outstanding_work_t::untracked_t>::value();
}
};
template <typename T>
struct static_query<T, execution::outstanding_work_t,
enable_if_t<
!execution::detail::outstanding_work_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::outstanding_work_t<0>::
query_member<T>::is_valid
&& !traits::static_query<T,
execution::outstanding_work_t::untracked_t>::is_valid
&& traits::static_query<T,
execution::outstanding_work_t::tracked_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::outstanding_work_t::tracked_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T,
execution::outstanding_work_t::tracked_t>::value();
}
};
template <typename T>
struct static_query<T, execution::outstanding_work_t::untracked_t,
enable_if_t<
execution::detail::outstanding_work::untracked_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::outstanding_work::untracked_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::outstanding_work::untracked_t<0>::
query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::outstanding_work_t::untracked_t,
enable_if_t<
!execution::detail::outstanding_work::untracked_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::outstanding_work::untracked_t<0>::
query_member<T>::is_valid
&& !traits::query_free<T,
execution::outstanding_work_t::untracked_t>::is_valid
&& !can_query<T, execution::outstanding_work_t::tracked_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::outstanding_work_t::untracked_t result_type;
static constexpr result_type value()
{
return result_type();
}
};
template <typename T>
struct static_query<T, execution::outstanding_work_t::tracked_t,
enable_if_t<
execution::detail::outstanding_work::tracked_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::outstanding_work::tracked_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::outstanding_work::tracked_t<0>::
query_static_constexpr_member<T>::value();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_OUTSTANDING_WORK_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/mapping.hpp | //
// execution/mapping.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_MAPPING_HPP
#define BOOST_ASIO_EXECUTION_MAPPING_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/is_applicable_property.hpp>
#include <boost/asio/query.hpp>
#include <boost/asio/traits/query_free.hpp>
#include <boost/asio/traits/query_member.hpp>
#include <boost/asio/traits/query_static_constexpr_member.hpp>
#include <boost/asio/traits/static_query.hpp>
#include <boost/asio/traits/static_require.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// A property to describe what guarantees an executor makes about the mapping
/// of execution agents on to threads of execution.
struct mapping_t
{
/// The mapping_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The top-level mapping_t property cannot be required.
static constexpr bool is_requirable = false;
/// The top-level mapping_t property cannot be preferred.
static constexpr bool is_preferable = false;
/// The type returned by queries against an @c any_executor.
typedef mapping_t polymorphic_query_result_type;
/// A sub-property that indicates that execution agents are mapped on to
/// threads of execution.
struct thread_t
{
/// The mapping_t::thread_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The mapping_t::thread_t property can be required.
static constexpr bool is_requirable = true;
/// The mapping_t::thread_t property can be preferred.
static constexpr bool is_preferable = true;
/// The type returned by queries against an @c any_executor.
typedef mapping_t polymorphic_query_result_type;
/// Default constructor.
constexpr thread_t();
/// Get the value associated with a property object.
/**
* @returns thread_t();
*/
static constexpr mapping_t value();
};
/// A sub-property that indicates that execution agents are mapped on to
/// new threads of execution.
struct new_thread_t
{
/// The mapping_t::new_thread_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The mapping_t::new_thread_t property can be required.
static constexpr bool is_requirable = true;
/// The mapping_t::new_thread_t property can be preferred.
static constexpr bool is_preferable = true;
/// The type returned by queries against an @c any_executor.
typedef mapping_t polymorphic_query_result_type;
/// Default constructor.
constexpr new_thread_t();
/// Get the value associated with a property object.
/**
* @returns new_thread_t();
*/
static constexpr mapping_t value();
};
/// A sub-property that indicates that the mapping of execution agents is
/// implementation-defined.
struct other_t
{
/// The mapping_t::other_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The mapping_t::other_t property can be required.
static constexpr bool is_requirable = true;
/// The mapping_t::other_t property can be preferred.
static constexpr bool is_preferable = true;
/// The type returned by queries against an @c any_executor.
typedef mapping_t polymorphic_query_result_type;
/// Default constructor.
constexpr other_t();
/// Get the value associated with a property object.
/**
* @returns other_t();
*/
static constexpr mapping_t value();
};
/// A special value used for accessing the mapping_t::thread_t property.
static constexpr thread_t thread;
/// A special value used for accessing the mapping_t::new_thread_t property.
static constexpr new_thread_t new_thread;
/// A special value used for accessing the mapping_t::other_t property.
static constexpr other_t other;
/// Default constructor.
constexpr mapping_t();
/// Construct from a sub-property value.
constexpr mapping_t(thread_t);
/// Construct from a sub-property value.
constexpr mapping_t(new_thread_t);
/// Construct from a sub-property value.
constexpr mapping_t(other_t);
/// Compare property values for equality.
friend constexpr bool operator==(
const mapping_t& a, const mapping_t& b) noexcept;
/// Compare property values for inequality.
friend constexpr bool operator!=(
const mapping_t& a, const mapping_t& b) noexcept;
};
/// A special value used for accessing the mapping_t property.
constexpr mapping_t mapping;
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
namespace detail {
namespace mapping {
template <int I> struct thread_t;
template <int I> struct new_thread_t;
template <int I> struct other_t;
} // namespace mapping
template <int I = 0>
struct mapping_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = false;
static constexpr bool is_preferable = false;
typedef mapping_t polymorphic_query_result_type;
typedef detail::mapping::thread_t<I> thread_t;
typedef detail::mapping::new_thread_t<I> new_thread_t;
typedef detail::mapping::other_t<I> other_t;
constexpr mapping_t()
: value_(-1)
{
}
constexpr mapping_t(thread_t)
: value_(0)
{
}
constexpr mapping_t(new_thread_t)
: value_(1)
{
}
constexpr mapping_t(other_t)
: value_(2)
{
}
template <typename T>
struct proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
struct type
{
template <typename P>
auto query(P&& p) const
noexcept(
noexcept(
declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
)
)
-> decltype(
declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
);
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
};
template <typename T>
struct static_proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
struct type
{
template <typename P>
static constexpr auto query(P&& p)
noexcept(
noexcept(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
)
-> decltype(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
{
return T::query(static_cast<P&&>(p));
}
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
};
template <typename T>
struct query_member :
traits::query_member<typename proxy<T>::type, mapping_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename static_proxy<T>::type, mapping_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, thread_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, thread_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, thread_t>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, new_thread_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::static_query<T, thread_t>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, new_thread_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, new_thread_t>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, other_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::static_query<T, thread_t>::is_valid
>* = 0,
enable_if_t<
!traits::static_query<T, new_thread_t>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, other_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, other_t>::value();
}
template <typename E, typename T = decltype(mapping_t::static_query<E>())>
static constexpr const T static_query_v
= mapping_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
friend constexpr bool operator==(
const mapping_t& a, const mapping_t& b)
{
return a.value_ == b.value_;
}
friend constexpr bool operator!=(
const mapping_t& a, const mapping_t& b)
{
return a.value_ != b.value_;
}
struct convertible_from_mapping_t
{
constexpr convertible_from_mapping_t(mapping_t) {}
};
template <typename Executor>
friend constexpr mapping_t query(
const Executor& ex, convertible_from_mapping_t,
enable_if_t<
can_query<const Executor&, thread_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&, mapping_t<>::thread_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, thread_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, thread_t());
}
template <typename Executor>
friend constexpr mapping_t query(
const Executor& ex, convertible_from_mapping_t,
enable_if_t<
!can_query<const Executor&, thread_t>::value
>* = 0,
enable_if_t<
can_query<const Executor&, new_thread_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(
is_nothrow_query<const Executor&, mapping_t<>::new_thread_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, new_thread_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, new_thread_t());
}
template <typename Executor>
friend constexpr mapping_t query(
const Executor& ex, convertible_from_mapping_t,
enable_if_t<
!can_query<const Executor&, thread_t>::value
>* = 0,
enable_if_t<
!can_query<const Executor&, new_thread_t>::value
>* = 0,
enable_if_t<
can_query<const Executor&, other_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&, mapping_t<>::other_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, other_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, other_t());
}
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(thread_t, thread);
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(new_thread_t, new_thread);
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(other_t, other);
private:
int value_;
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T mapping_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I>
const typename mapping_t<I>::thread_t mapping_t<I>::thread;
template <int I>
const typename mapping_t<I>::new_thread_t mapping_t<I>::new_thread;
template <int I>
const typename mapping_t<I>::other_t mapping_t<I>::other;
namespace mapping {
template <int I = 0>
struct thread_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
typedef mapping_t<I> polymorphic_query_result_type;
constexpr thread_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename mapping_t<I>::template proxy<T>::type, thread_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename mapping_t<I>::template static_proxy<T>::type, thread_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename T>
static constexpr thread_t static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::query_free<T, thread_t>::is_valid
>* = 0,
enable_if_t<
!can_query<T, new_thread_t<I>>::value
>* = 0,
enable_if_t<
!can_query<T, other_t<I>>::value
>* = 0) noexcept
{
return thread_t();
}
template <typename E, typename T = decltype(thread_t::static_query<E>())>
static constexpr const T static_query_v
= thread_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr mapping_t<I> value()
{
return thread_t();
}
friend constexpr bool operator==(const thread_t&, const thread_t&)
{
return true;
}
friend constexpr bool operator!=(const thread_t&, const thread_t&)
{
return false;
}
friend constexpr bool operator==(const thread_t&, const new_thread_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const thread_t&, const new_thread_t<I>&)
{
return true;
}
friend constexpr bool operator==(const thread_t&, const other_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const thread_t&, const other_t<I>&)
{
return true;
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T thread_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I = 0>
struct new_thread_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
typedef mapping_t<I> polymorphic_query_result_type;
constexpr new_thread_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename mapping_t<I>::template proxy<T>::type, new_thread_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename mapping_t<I>::template static_proxy<T>::type, new_thread_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename E, typename T = decltype(new_thread_t::static_query<E>())>
static constexpr const T static_query_v = new_thread_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr mapping_t<I> value()
{
return new_thread_t();
}
friend constexpr bool operator==(const new_thread_t&, const new_thread_t&)
{
return true;
}
friend constexpr bool operator!=(const new_thread_t&, const new_thread_t&)
{
return false;
}
friend constexpr bool operator==(const new_thread_t&, const thread_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const new_thread_t&, const thread_t<I>&)
{
return true;
}
friend constexpr bool operator==(const new_thread_t&, const other_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const new_thread_t&, const other_t<I>&)
{
return true;
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T new_thread_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I>
struct other_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
typedef mapping_t<I> polymorphic_query_result_type;
constexpr other_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename mapping_t<I>::template proxy<T>::type, other_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename mapping_t<I>::template static_proxy<T>::type, other_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename E, typename T = decltype(other_t::static_query<E>())>
static constexpr const T static_query_v = other_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr mapping_t<I> value()
{
return other_t();
}
friend constexpr bool operator==(const other_t&, const other_t&)
{
return true;
}
friend constexpr bool operator!=(const other_t&, const other_t&)
{
return false;
}
friend constexpr bool operator==(const other_t&, const thread_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const other_t&, const thread_t<I>&)
{
return true;
}
friend constexpr bool operator==(const other_t&, const new_thread_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const other_t&, const new_thread_t<I>&)
{
return true;
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T other_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace mapping
} // namespace detail
typedef detail::mapping_t<> mapping_t;
constexpr mapping_t mapping;
} // namespace execution
#if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
struct is_applicable_property<T, execution::mapping_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::mapping_t::thread_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::mapping_t::new_thread_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::mapping_t::other_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
#endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
template <typename T>
struct query_free_default<T, execution::mapping_t,
enable_if_t<
can_query<T, execution::mapping_t::thread_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::mapping_t::thread_t>::value;
typedef execution::mapping_t result_type;
};
template <typename T>
struct query_free_default<T, execution::mapping_t,
enable_if_t<
!can_query<T, execution::mapping_t::thread_t>::value
&& can_query<T, execution::mapping_t::new_thread_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::mapping_t::new_thread_t>::value;
typedef execution::mapping_t result_type;
};
template <typename T>
struct query_free_default<T, execution::mapping_t,
enable_if_t<
!can_query<T, execution::mapping_t::thread_t>::value
&& !can_query<T, execution::mapping_t::new_thread_t>::value
&& can_query<T, execution::mapping_t::other_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::mapping_t::other_t>::value;
typedef execution::mapping_t result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
|| !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
struct static_query<T, execution::mapping_t,
enable_if_t<
execution::detail::mapping_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::mapping_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::mapping_t<0>::
query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::mapping_t,
enable_if_t<
!execution::detail::mapping_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::mapping_t<0>::
query_member<T>::is_valid
&& traits::static_query<T, execution::mapping_t::thread_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::mapping_t::thread_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T, execution::mapping_t::thread_t>::value();
}
};
template <typename T>
struct static_query<T, execution::mapping_t,
enable_if_t<
!execution::detail::mapping_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::mapping_t<0>::
query_member<T>::is_valid
&& !traits::static_query<T, execution::mapping_t::thread_t>::is_valid
&& traits::static_query<T, execution::mapping_t::new_thread_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::mapping_t::new_thread_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T, execution::mapping_t::new_thread_t>::value();
}
};
template <typename T>
struct static_query<T, execution::mapping_t,
enable_if_t<
!execution::detail::mapping_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::mapping_t<0>::
query_member<T>::is_valid
&& !traits::static_query<T, execution::mapping_t::thread_t>::is_valid
&& !traits::static_query<T, execution::mapping_t::new_thread_t>::is_valid
&& traits::static_query<T, execution::mapping_t::other_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::mapping_t::other_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T, execution::mapping_t::other_t>::value();
}
};
template <typename T>
struct static_query<T, execution::mapping_t::thread_t,
enable_if_t<
execution::detail::mapping::thread_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::mapping::thread_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::mapping::thread_t<0>::
query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::mapping_t::thread_t,
enable_if_t<
!execution::detail::mapping::thread_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::mapping::thread_t<0>::
query_member<T>::is_valid
&& !traits::query_free<T, execution::mapping_t::thread_t>::is_valid
&& !can_query<T, execution::mapping_t::new_thread_t>::value
&& !can_query<T, execution::mapping_t::other_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::mapping_t::thread_t result_type;
static constexpr result_type value()
{
return result_type();
}
};
template <typename T>
struct static_query<T, execution::mapping_t::new_thread_t,
enable_if_t<
execution::detail::mapping::new_thread_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::mapping::new_thread_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::mapping::new_thread_t<0>::
query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::mapping_t::other_t,
enable_if_t<
execution::detail::mapping::other_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::mapping::other_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::mapping::other_t<0>::
query_static_constexpr_member<T>::value();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_MAPPING_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/executor.hpp | //
// execution/executor.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_EXECUTOR_HPP
#define BOOST_ASIO_EXECUTION_EXECUTOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/invocable_archetype.hpp>
#include <boost/asio/traits/equality_comparable.hpp>
#include <boost/asio/traits/execute_member.hpp>
#if defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) \
&& defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
# define BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_EXECUTOR_TRAIT 1
#endif // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
// && defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace execution {
namespace detail {
template <typename T, typename F,
typename = void, typename = void, typename = void, typename = void,
typename = void, typename = void, typename = void, typename = void>
struct is_executor_of_impl : false_type
{
};
template <typename T, typename F>
struct is_executor_of_impl<T, F,
enable_if_t<
traits::execute_member<add_const_t<T>, F>::is_valid
>,
void_t<
result_of_t<decay_t<F>&()>
>,
enable_if_t<
is_constructible<decay_t<F>, F>::value
>,
enable_if_t<
is_move_constructible<decay_t<F>>::value
>,
enable_if_t<
is_nothrow_copy_constructible<T>::value
>,
enable_if_t<
is_nothrow_destructible<T>::value
>,
enable_if_t<
traits::equality_comparable<T>::is_valid
>,
enable_if_t<
traits::equality_comparable<T>::is_noexcept
>> : true_type
{
};
} // namespace detail
/// The is_executor trait detects whether a type T satisfies the
/// execution::executor concept.
/**
* Class template @c is_executor is a UnaryTypeTrait that is derived from @c
* true_type if the type @c T meets the concept definition for an executor,
* otherwise @c false_type.
*/
template <typename T>
struct is_executor :
#if defined(GENERATING_DOCUMENTATION)
integral_constant<bool, automatically_determined>
#else // defined(GENERATING_DOCUMENTATION)
detail::is_executor_of_impl<T, invocable_archetype>
#endif // defined(GENERATING_DOCUMENTATION)
{
};
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
constexpr const bool is_executor_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
#if defined(BOOST_ASIO_HAS_CONCEPTS)
template <typename T>
BOOST_ASIO_CONCEPT executor = is_executor<T>::value;
#define BOOST_ASIO_EXECUTION_EXECUTOR ::boost::asio::execution::executor
#else // defined(BOOST_ASIO_HAS_CONCEPTS)
#define BOOST_ASIO_EXECUTION_EXECUTOR typename
#endif // defined(BOOST_ASIO_HAS_CONCEPTS)
} // namespace execution
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_EXECUTOR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/context.hpp | //
// execution/context.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_CONTEXT2_HPP
#define BOOST_ASIO_EXECUTION_CONTEXT2_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/is_applicable_property.hpp>
#include <boost/asio/traits/query_static_constexpr_member.hpp>
#include <boost/asio/traits/static_query.hpp>
#if defined(BOOST_ASIO_HAS_STD_ANY)
# include <any>
#endif // defined(BOOST_ASIO_HAS_STD_ANY)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// A property that is used to obtain the execution context that is associated
/// with an executor.
struct context_t
{
/// The context_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The context_t property cannot be required.
static constexpr bool is_requirable = false;
/// The context_t property cannot be preferred.
static constexpr bool is_preferable = false;
/// The type returned by queries against an @c any_executor.
typedef std::any polymorphic_query_result_type;
};
/// A special value used for accessing the context_t property.
constexpr context_t context;
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
namespace detail {
template <int I = 0>
struct context_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = false;
static constexpr bool is_preferable = false;
#if defined(BOOST_ASIO_HAS_STD_ANY)
typedef std::any polymorphic_query_result_type;
#endif // defined(BOOST_ASIO_HAS_STD_ANY)
constexpr context_t()
{
}
template <typename T>
struct static_proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
struct type
{
template <typename P>
static constexpr auto query(P&& p)
noexcept(
noexcept(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
)
-> decltype(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
{
return T::query(static_cast<P&&>(p));
}
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename static_proxy<T>::type, context_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename E, typename T = decltype(context_t::static_query<E>())>
static constexpr const T static_query_v = context_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T context_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace detail
typedef detail::context_t<> context_t;
constexpr context_t context;
} // namespace execution
#if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
struct is_applicable_property<T, execution::context_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
#endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
|| !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
struct static_query<T, execution::context_t,
enable_if_t<
execution::detail::context_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::context_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::context_t<0>::
query_static_constexpr_member<T>::value();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_CONTEXT2_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/invocable_archetype.hpp | //
// execution/invocable_archetype.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_INVOCABLE_ARCHETYPE_HPP
#define BOOST_ASIO_EXECUTION_INVOCABLE_ARCHETYPE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace execution {
/// An archetypal function object used for determining adherence to the
/// execution::executor concept.
struct invocable_archetype
{
/// Function call operator.
template <typename... Args>
void operator()(Args&&...)
{
}
};
} // namespace execution
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_INVOCABLE_ARCHETYPE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/relationship.hpp | //
// execution/relationship.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_RELATIONSHIP_HPP
#define BOOST_ASIO_EXECUTION_RELATIONSHIP_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/is_applicable_property.hpp>
#include <boost/asio/query.hpp>
#include <boost/asio/traits/query_free.hpp>
#include <boost/asio/traits/query_member.hpp>
#include <boost/asio/traits/query_static_constexpr_member.hpp>
#include <boost/asio/traits/static_query.hpp>
#include <boost/asio/traits/static_require.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// A property to describe whether submitted tasks represent continuations of
/// the calling context.
struct relationship_t
{
/// The relationship_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The top-level relationship_t property cannot be required.
static constexpr bool is_requirable = false;
/// The top-level relationship_t property cannot be preferred.
static constexpr bool is_preferable = false;
/// The type returned by queries against an @c any_executor.
typedef relationship_t polymorphic_query_result_type;
/// A sub-property that indicates that the executor does not represent a
/// continuation of the calling context.
struct fork_t
{
/// The relationship_t::fork_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The relationship_t::fork_t property can be required.
static constexpr bool is_requirable = true;
/// The relationship_t::fork_t property can be preferred.
static constexpr bool is_preferable = true;
/// The type returned by queries against an @c any_executor.
typedef relationship_t polymorphic_query_result_type;
/// Default constructor.
constexpr fork_t();
/// Get the value associated with a property object.
/**
* @returns fork_t();
*/
static constexpr relationship_t value();
};
/// A sub-property that indicates that the executor represents a continuation
/// of the calling context.
struct continuation_t
{
/// The relationship_t::continuation_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The relationship_t::continuation_t property can be required.
static constexpr bool is_requirable = true;
/// The relationship_t::continuation_t property can be preferred.
static constexpr bool is_preferable = true;
/// The type returned by queries against an @c any_executor.
typedef relationship_t polymorphic_query_result_type;
/// Default constructor.
constexpr continuation_t();
/// Get the value associated with a property object.
/**
* @returns continuation_t();
*/
static constexpr relationship_t value();
};
/// A special value used for accessing the relationship_t::fork_t property.
static constexpr fork_t fork;
/// A special value used for accessing the relationship_t::continuation_t
/// property.
static constexpr continuation_t continuation;
/// Default constructor.
constexpr relationship_t();
/// Construct from a sub-property value.
constexpr relationship_t(fork_t);
/// Construct from a sub-property value.
constexpr relationship_t(continuation_t);
/// Compare property values for equality.
friend constexpr bool operator==(
const relationship_t& a, const relationship_t& b) noexcept;
/// Compare property values for inequality.
friend constexpr bool operator!=(
const relationship_t& a, const relationship_t& b) noexcept;
};
/// A special value used for accessing the relationship_t property.
constexpr relationship_t relationship;
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
namespace detail {
namespace relationship {
template <int I> struct fork_t;
template <int I> struct continuation_t;
} // namespace relationship
template <int I = 0>
struct relationship_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = false;
static constexpr bool is_preferable = false;
typedef relationship_t polymorphic_query_result_type;
typedef detail::relationship::fork_t<I> fork_t;
typedef detail::relationship::continuation_t<I> continuation_t;
constexpr relationship_t()
: value_(-1)
{
}
constexpr relationship_t(fork_t)
: value_(0)
{
}
constexpr relationship_t(continuation_t)
: value_(1)
{
}
template <typename T>
struct proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
struct type
{
template <typename P>
auto query(P&& p) const
noexcept(
noexcept(
declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
)
)
-> decltype(
declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
);
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
};
template <typename T>
struct static_proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
struct type
{
template <typename P>
static constexpr auto query(P&& p)
noexcept(
noexcept(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
)
-> decltype(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
{
return T::query(static_cast<P&&>(p));
}
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
};
template <typename T>
struct query_member :
traits::query_member<typename proxy<T>::type, relationship_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename static_proxy<T>::type, relationship_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, fork_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, fork_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, fork_t>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, continuation_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::static_query<T, fork_t>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, continuation_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, continuation_t>::value();
}
template <typename E,
typename T = decltype(relationship_t::static_query<E>())>
static constexpr const T static_query_v
= relationship_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
friend constexpr bool operator==(
const relationship_t& a, const relationship_t& b)
{
return a.value_ == b.value_;
}
friend constexpr bool operator!=(
const relationship_t& a, const relationship_t& b)
{
return a.value_ != b.value_;
}
struct convertible_from_relationship_t
{
constexpr convertible_from_relationship_t(relationship_t)
{
}
};
template <typename Executor>
friend constexpr relationship_t query(
const Executor& ex, convertible_from_relationship_t,
enable_if_t<
can_query<const Executor&, fork_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&, relationship_t<>::fork_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, fork_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, fork_t());
}
template <typename Executor>
friend constexpr relationship_t query(
const Executor& ex, convertible_from_relationship_t,
enable_if_t<
!can_query<const Executor&, fork_t>::value
>* = 0,
enable_if_t<
can_query<const Executor&, continuation_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&,
relationship_t<>::continuation_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, continuation_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, continuation_t());
}
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(fork_t, fork);
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(continuation_t, continuation);
private:
int value_;
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T relationship_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I>
const typename relationship_t<I>::fork_t relationship_t<I>::fork;
template <int I>
const typename relationship_t<I>::continuation_t
relationship_t<I>::continuation;
namespace relationship {
template <int I = 0>
struct fork_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
typedef relationship_t<I> polymorphic_query_result_type;
constexpr fork_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename relationship_t<I>::template proxy<T>::type, fork_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename relationship_t<I>::template static_proxy<T>::type, fork_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename T>
static constexpr fork_t static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::query_free<T, fork_t>::is_valid
>* = 0,
enable_if_t<
!can_query<T, continuation_t<I>>::value
>* = 0) noexcept
{
return fork_t();
}
template <typename E, typename T = decltype(fork_t::static_query<E>())>
static constexpr const T static_query_v
= fork_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr relationship_t<I> value()
{
return fork_t();
}
friend constexpr bool operator==(const fork_t&, const fork_t&)
{
return true;
}
friend constexpr bool operator!=(const fork_t&, const fork_t&)
{
return false;
}
friend constexpr bool operator==(const fork_t&, const continuation_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const fork_t&, const continuation_t<I>&)
{
return true;
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T fork_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I = 0>
struct continuation_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
typedef relationship_t<I> polymorphic_query_result_type;
constexpr continuation_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename relationship_t<I>::template proxy<T>::type, continuation_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename relationship_t<I>::template static_proxy<T>::type,
continuation_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename E,
typename T = decltype(continuation_t::static_query<E>())>
static constexpr const T static_query_v
= continuation_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr relationship_t<I> value()
{
return continuation_t();
}
friend constexpr bool operator==(const continuation_t&, const continuation_t&)
{
return true;
}
friend constexpr bool operator!=(const continuation_t&, const continuation_t&)
{
return false;
}
friend constexpr bool operator==(const continuation_t&, const fork_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const continuation_t&, const fork_t<I>&)
{
return true;
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T continuation_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace relationship
} // namespace detail
typedef detail::relationship_t<> relationship_t;
constexpr relationship_t relationship;
} // namespace execution
#if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
struct is_applicable_property<T, execution::relationship_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::relationship_t::fork_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::relationship_t::continuation_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
#endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
template <typename T>
struct query_free_default<T, execution::relationship_t,
enable_if_t<
can_query<T, execution::relationship_t::fork_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::relationship_t::fork_t>::value;
typedef execution::relationship_t result_type;
};
template <typename T>
struct query_free_default<T, execution::relationship_t,
enable_if_t<
!can_query<T, execution::relationship_t::fork_t>::value
&& can_query<T, execution::relationship_t::continuation_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::relationship_t::continuation_t>::value;
typedef execution::relationship_t result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
|| !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
struct static_query<T, execution::relationship_t,
enable_if_t<
execution::detail::relationship_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::relationship_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::relationship_t<0>::
query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::relationship_t,
enable_if_t<
!execution::detail::relationship_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::relationship_t<0>::
query_member<T>::is_valid
&& traits::static_query<T,
execution::relationship_t::fork_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::relationship_t::fork_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T,
execution::relationship_t::fork_t>::value();
}
};
template <typename T>
struct static_query<T, execution::relationship_t,
enable_if_t<
!execution::detail::relationship_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::relationship_t<0>::
query_member<T>::is_valid
&& !traits::static_query<T,
execution::relationship_t::fork_t>::is_valid
&& traits::static_query<T,
execution::relationship_t::continuation_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::relationship_t::continuation_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T,
execution::relationship_t::continuation_t>::value();
}
};
template <typename T>
struct static_query<T, execution::relationship_t::fork_t,
enable_if_t<
execution::detail::relationship::fork_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::relationship::fork_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::relationship::fork_t<0>::
query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::relationship_t::fork_t,
enable_if_t<
!execution::detail::relationship::fork_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::relationship::fork_t<0>::
query_member<T>::is_valid
&& !traits::query_free<T,
execution::relationship_t::fork_t>::is_valid
&& !can_query<T, execution::relationship_t::continuation_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::relationship_t::fork_t result_type;
static constexpr result_type value()
{
return result_type();
}
};
template <typename T>
struct static_query<T, execution::relationship_t::continuation_t,
enable_if_t<
execution::detail::relationship::continuation_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::relationship::continuation_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::relationship::continuation_t<0>::
query_static_constexpr_member<T>::value();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_RELATIONSHIP_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/blocking.hpp | //
// execution/blocking.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_BLOCKING_HPP
#define BOOST_ASIO_EXECUTION_BLOCKING_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/is_applicable_property.hpp>
#include <boost/asio/prefer.hpp>
#include <boost/asio/query.hpp>
#include <boost/asio/require.hpp>
#include <boost/asio/traits/execute_member.hpp>
#include <boost/asio/traits/query_free.hpp>
#include <boost/asio/traits/query_member.hpp>
#include <boost/asio/traits/query_static_constexpr_member.hpp>
#include <boost/asio/traits/static_query.hpp>
#include <boost/asio/traits/static_require.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// A property to describe what guarantees an executor makes about the blocking
/// behaviour of their execution functions.
struct blocking_t
{
/// The blocking_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The top-level blocking_t property cannot be required.
static constexpr bool is_requirable = false;
/// The top-level blocking_t property cannot be preferred.
static constexpr bool is_preferable = false;
/// The type returned by queries against an @c any_executor.
typedef blocking_t polymorphic_query_result_type;
/// A sub-property that indicates that invocation of an executor's execution
/// function may block pending completion of one or more invocations of the
/// submitted function object.
struct possibly_t
{
/// The blocking_t::possibly_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The blocking_t::possibly_t property can be required.
static constexpr bool is_requirable = true;
/// The blocking_t::possibly_t property can be preferred.
static constexpr bool is_preferable = true;
/// The type returned by queries against an @c any_executor.
typedef blocking_t polymorphic_query_result_type;
/// Default constructor.
constexpr possibly_t();
/// Get the value associated with a property object.
/**
* @returns possibly_t();
*/
static constexpr blocking_t value();
};
/// A sub-property that indicates that invocation of an executor's execution
/// function shall block until completion of all invocations of the submitted
/// function object.
struct always_t
{
/// The blocking_t::always_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The blocking_t::always_t property can be required.
static constexpr bool is_requirable = true;
/// The blocking_t::always_t property can be preferred.
static constexpr bool is_preferable = false;
/// The type returned by queries against an @c any_executor.
typedef blocking_t polymorphic_query_result_type;
/// Default constructor.
constexpr always_t();
/// Get the value associated with a property object.
/**
* @returns always_t();
*/
static constexpr blocking_t value();
};
/// A sub-property that indicates that invocation of an executor's execution
/// function shall not block pending completion of the invocations of the
/// submitted function object.
struct never_t
{
/// The blocking_t::never_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The blocking_t::never_t property can be required.
static constexpr bool is_requirable = true;
/// The blocking_t::never_t property can be preferred.
static constexpr bool is_preferable = true;
/// The type returned by queries against an @c any_executor.
typedef blocking_t polymorphic_query_result_type;
/// Default constructor.
constexpr never_t();
/// Get the value associated with a property object.
/**
* @returns never_t();
*/
static constexpr blocking_t value();
};
/// A special value used for accessing the blocking_t::possibly_t property.
static constexpr possibly_t possibly;
/// A special value used for accessing the blocking_t::always_t property.
static constexpr always_t always;
/// A special value used for accessing the blocking_t::never_t property.
static constexpr never_t never;
/// Default constructor.
constexpr blocking_t();
/// Construct from a sub-property value.
constexpr blocking_t(possibly_t);
/// Construct from a sub-property value.
constexpr blocking_t(always_t);
/// Construct from a sub-property value.
constexpr blocking_t(never_t);
/// Compare property values for equality.
friend constexpr bool operator==(
const blocking_t& a, const blocking_t& b) noexcept;
/// Compare property values for inequality.
friend constexpr bool operator!=(
const blocking_t& a, const blocking_t& b) noexcept;
};
/// A special value used for accessing the blocking_t property.
constexpr blocking_t blocking;
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
namespace detail {
namespace blocking {
template <int I> struct possibly_t;
template <int I> struct always_t;
template <int I> struct never_t;
} // namespace blocking
namespace blocking_adaptation {
template <int I> struct allowed_t;
template <typename Executor, typename Function>
void blocking_execute(
Executor&& ex,
Function&& func);
} // namespace blocking_adaptation
template <int I = 0>
struct blocking_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = false;
static constexpr bool is_preferable = false;
typedef blocking_t polymorphic_query_result_type;
typedef detail::blocking::possibly_t<I> possibly_t;
typedef detail::blocking::always_t<I> always_t;
typedef detail::blocking::never_t<I> never_t;
constexpr blocking_t()
: value_(-1)
{
}
constexpr blocking_t(possibly_t)
: value_(0)
{
}
constexpr blocking_t(always_t)
: value_(1)
{
}
constexpr blocking_t(never_t)
: value_(2)
{
}
template <typename T>
struct proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
struct type
{
template <typename P>
auto query(P&& p) const
noexcept(
noexcept(
declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
)
)
-> decltype(
declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
);
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
};
template <typename T>
struct static_proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
struct type
{
template <typename P>
static constexpr auto query(P&& p)
noexcept(
noexcept(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
)
-> decltype(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
{
return T::query(static_cast<P&&>(p));
}
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
};
template <typename T>
struct query_member :
traits::query_member<typename proxy<T>::type, blocking_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename static_proxy<T>::type, blocking_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, possibly_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, possibly_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, possibly_t>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, always_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::static_query<T, possibly_t>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, always_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, always_t>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, never_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::static_query<T, possibly_t>::is_valid
>* = 0,
enable_if_t<
!traits::static_query<T, always_t>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, never_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, never_t>::value();
}
template <typename E, typename T = decltype(blocking_t::static_query<E>())>
static constexpr const T static_query_v
= blocking_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
friend constexpr bool operator==(
const blocking_t& a, const blocking_t& b)
{
return a.value_ == b.value_;
}
friend constexpr bool operator!=(
const blocking_t& a, const blocking_t& b)
{
return a.value_ != b.value_;
}
struct convertible_from_blocking_t
{
constexpr convertible_from_blocking_t(blocking_t) {}
};
template <typename Executor>
friend constexpr blocking_t query(
const Executor& ex, convertible_from_blocking_t,
enable_if_t<
can_query<const Executor&, possibly_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&, blocking_t<>::possibly_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, possibly_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, possibly_t());
}
template <typename Executor>
friend constexpr blocking_t query(
const Executor& ex, convertible_from_blocking_t,
enable_if_t<
!can_query<const Executor&, possibly_t>::value
>* = 0,
enable_if_t<
can_query<const Executor&, always_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&, blocking_t<>::always_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, always_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, always_t());
}
template <typename Executor>
friend constexpr blocking_t query(
const Executor& ex, convertible_from_blocking_t,
enable_if_t<
!can_query<const Executor&, possibly_t>::value
>* = 0,
enable_if_t<
!can_query<const Executor&, always_t>::value
>* = 0,
enable_if_t<
can_query<const Executor&, never_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&, blocking_t<>::never_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, never_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, never_t());
}
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(possibly_t, possibly);
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(always_t, always);
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(never_t, never);
private:
int value_;
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T blocking_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I>
const typename blocking_t<I>::possibly_t blocking_t<I>::possibly;
template <int I>
const typename blocking_t<I>::always_t blocking_t<I>::always;
template <int I>
const typename blocking_t<I>::never_t blocking_t<I>::never;
namespace blocking {
template <int I = 0>
struct possibly_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
typedef blocking_t<I> polymorphic_query_result_type;
constexpr possibly_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename blocking_t<I>::template proxy<T>::type, possibly_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename blocking_t<I>::template static_proxy<T>::type, possibly_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename T>
static constexpr possibly_t static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::query_free<T, possibly_t>::is_valid
>* = 0,
enable_if_t<
!can_query<T, always_t<I>>::value
>* = 0,
enable_if_t<
!can_query<T, never_t<I>>::value
>* = 0) noexcept
{
return possibly_t();
}
template <typename E, typename T = decltype(possibly_t::static_query<E>())>
static constexpr const T static_query_v
= possibly_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr blocking_t<I> value()
{
return possibly_t();
}
friend constexpr bool operator==(
const possibly_t&, const possibly_t&)
{
return true;
}
friend constexpr bool operator!=(
const possibly_t&, const possibly_t&)
{
return false;
}
friend constexpr bool operator==(
const possibly_t&, const always_t<I>&)
{
return false;
}
friend constexpr bool operator!=(
const possibly_t&, const always_t<I>&)
{
return true;
}
friend constexpr bool operator==(
const possibly_t&, const never_t<I>&)
{
return false;
}
friend constexpr bool operator!=(
const possibly_t&, const never_t<I>&)
{
return true;
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T possibly_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename Executor>
class adapter
{
public:
adapter(int, const Executor& e) noexcept
: executor_(e)
{
}
adapter(const adapter& other) noexcept
: executor_(other.executor_)
{
}
adapter(adapter&& other) noexcept
: executor_(static_cast<Executor&&>(other.executor_))
{
}
template <int I>
static constexpr always_t<I> query(blocking_t<I>) noexcept
{
return always_t<I>();
}
template <int I>
static constexpr always_t<I> query(possibly_t<I>) noexcept
{
return always_t<I>();
}
template <int I>
static constexpr always_t<I> query(always_t<I>) noexcept
{
return always_t<I>();
}
template <int I>
static constexpr always_t<I> query(never_t<I>) noexcept
{
return always_t<I>();
}
template <typename Property>
enable_if_t<
can_query<const Executor&, Property>::value,
query_result_t<const Executor&, Property>
> query(const Property& p) const
noexcept(is_nothrow_query<const Executor&, Property>::value)
{
return boost::asio::query(executor_, p);
}
template <int I>
enable_if_t<
can_require<const Executor&, possibly_t<I>>::value,
require_result_t<const Executor&, possibly_t<I>>
> require(possibly_t<I>) const noexcept
{
return boost::asio::require(executor_, possibly_t<I>());
}
template <int I>
enable_if_t<
can_require<const Executor&, never_t<I>>::value,
require_result_t<const Executor&, never_t<I>>
> require(never_t<I>) const noexcept
{
return boost::asio::require(executor_, never_t<I>());
}
template <typename Property>
enable_if_t<
can_require<const Executor&, Property>::value,
adapter<decay_t<require_result_t<const Executor&, Property>>>
> require(const Property& p) const
noexcept(is_nothrow_require<const Executor&, Property>::value)
{
return adapter<decay_t<require_result_t<const Executor&, Property>>>(
0, boost::asio::require(executor_, p));
}
template <typename Property>
enable_if_t<
can_prefer<const Executor&, Property>::value,
adapter<decay_t<prefer_result_t<const Executor&, Property>>>
> prefer(const Property& p) const
noexcept(is_nothrow_prefer<const Executor&, Property>::value)
{
return adapter<decay_t<prefer_result_t<const Executor&, Property>>>(
0, boost::asio::prefer(executor_, p));
}
template <typename Function>
enable_if_t<
traits::execute_member<const Executor&, Function>::is_valid
> execute(Function&& f) const
{
blocking_adaptation::blocking_execute(
executor_, static_cast<Function&&>(f));
}
friend bool operator==(const adapter& a, const adapter& b) noexcept
{
return a.executor_ == b.executor_;
}
friend bool operator!=(const adapter& a, const adapter& b) noexcept
{
return a.executor_ != b.executor_;
}
private:
Executor executor_;
};
template <int I = 0>
struct always_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = false;
typedef blocking_t<I> polymorphic_query_result_type;
constexpr always_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename blocking_t<I>::template proxy<T>::type, always_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename blocking_t<I>::template static_proxy<T>::type, always_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename E, typename T = decltype(always_t::static_query<E>())>
static constexpr const T static_query_v = always_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr blocking_t<I> value()
{
return always_t();
}
friend constexpr bool operator==(
const always_t&, const always_t&)
{
return true;
}
friend constexpr bool operator!=(
const always_t&, const always_t&)
{
return false;
}
friend constexpr bool operator==(
const always_t&, const possibly_t<I>&)
{
return false;
}
friend constexpr bool operator!=(
const always_t&, const possibly_t<I>&)
{
return true;
}
friend constexpr bool operator==(
const always_t&, const never_t<I>&)
{
return false;
}
friend constexpr bool operator!=(
const always_t&, const never_t<I>&)
{
return true;
}
template <typename Executor>
friend adapter<Executor> require(
const Executor& e, const always_t&,
enable_if_t<
is_executor<Executor>::value
>* = 0,
enable_if_t<
traits::static_require<
const Executor&,
blocking_adaptation::allowed_t<0>
>::is_valid
>* = 0)
{
return adapter<Executor>(0, e);
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T always_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I>
struct never_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
typedef blocking_t<I> polymorphic_query_result_type;
constexpr never_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename blocking_t<I>::template proxy<T>::type, never_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename blocking_t<I>::template static_proxy<T>::type, never_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename E, typename T = decltype(never_t::static_query<E>())>
static constexpr const T static_query_v
= never_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr blocking_t<I> value()
{
return never_t();
}
friend constexpr bool operator==(const never_t&, const never_t&)
{
return true;
}
friend constexpr bool operator!=(const never_t&, const never_t&)
{
return false;
}
friend constexpr bool operator==(const never_t&, const possibly_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const never_t&, const possibly_t<I>&)
{
return true;
}
friend constexpr bool operator==(const never_t&, const always_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const never_t&, const always_t<I>&)
{
return true;
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T never_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace blocking
} // namespace detail
typedef detail::blocking_t<> blocking_t;
constexpr blocking_t blocking;
} // namespace execution
#if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
struct is_applicable_property<T, execution::blocking_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::blocking_t::possibly_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::blocking_t::always_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::blocking_t::never_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
#endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
template <typename T>
struct query_free_default<T, execution::blocking_t,
enable_if_t<
can_query<T, execution::blocking_t::possibly_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::blocking_t::possibly_t>::value;
typedef execution::blocking_t result_type;
};
template <typename T>
struct query_free_default<T, execution::blocking_t,
enable_if_t<
!can_query<T, execution::blocking_t::possibly_t>::value
&& can_query<T, execution::blocking_t::always_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::blocking_t::always_t>::value;
typedef execution::blocking_t result_type;
};
template <typename T>
struct query_free_default<T, execution::blocking_t,
enable_if_t<
!can_query<T, execution::blocking_t::possibly_t>::value
&& !can_query<T, execution::blocking_t::always_t>::value
&& can_query<T, execution::blocking_t::never_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::blocking_t::never_t>::value;
typedef execution::blocking_t result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
|| !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
struct static_query<T, execution::blocking_t,
enable_if_t<
execution::detail::blocking_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::blocking_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::blocking_t::query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::blocking_t,
enable_if_t<
!execution::detail::blocking_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::blocking_t<0>::
query_member<T>::is_valid
&& traits::static_query<T, execution::blocking_t::possibly_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::blocking_t::possibly_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T, execution::blocking_t::possibly_t>::value();
}
};
template <typename T>
struct static_query<T, execution::blocking_t,
enable_if_t<
!execution::detail::blocking_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::blocking_t<0>::
query_member<T>::is_valid
&& !traits::static_query<T, execution::blocking_t::possibly_t>::is_valid
&& traits::static_query<T, execution::blocking_t::always_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::blocking_t::always_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T, execution::blocking_t::always_t>::value();
}
};
template <typename T>
struct static_query<T, execution::blocking_t,
enable_if_t<
!execution::detail::blocking_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::blocking_t<0>::
query_member<T>::is_valid
&& !traits::static_query<T, execution::blocking_t::possibly_t>::is_valid
&& !traits::static_query<T, execution::blocking_t::always_t>::is_valid
&& traits::static_query<T, execution::blocking_t::never_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::blocking_t::never_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T, execution::blocking_t::never_t>::value();
}
};
template <typename T>
struct static_query<T, execution::blocking_t::possibly_t,
enable_if_t<
execution::detail::blocking::possibly_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::blocking::possibly_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::blocking::possibly_t<0>::
query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::blocking_t::possibly_t,
enable_if_t<
!execution::detail::blocking::possibly_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::blocking::possibly_t<0>::
query_member<T>::is_valid
&& !traits::query_free<T, execution::blocking_t::possibly_t>::is_valid
&& !can_query<T, execution::blocking_t::always_t>::value
&& !can_query<T, execution::blocking_t::never_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::blocking_t::possibly_t result_type;
static constexpr result_type value()
{
return result_type();
}
};
template <typename T>
struct static_query<T, execution::blocking_t::always_t,
enable_if_t<
execution::detail::blocking::always_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::blocking::always_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::blocking::always_t<0>::
query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::blocking_t::never_t,
enable_if_t<
execution::detail::blocking::never_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::blocking::never_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::blocking::never_t<0>::
query_static_constexpr_member<T>::value();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
#if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_FREE_TRAIT)
template <typename T>
struct require_free_default<T, execution::blocking_t::always_t,
enable_if_t<
is_same<T, decay_t<T>>::value
&& execution::is_executor<T>::value
&& traits::static_require<
const T&,
execution::detail::blocking_adaptation::allowed_t<0>
>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef execution::detail::blocking::adapter<T> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_FREE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <typename Executor>
struct equality_comparable<
execution::detail::blocking::adapter<Executor>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename Executor, typename Function>
struct execute_member<
execution::detail::blocking::adapter<Executor>, Function>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
template <typename Executor, int I>
struct query_static_constexpr_member<
execution::detail::blocking::adapter<Executor>,
execution::detail::blocking_t<I>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::blocking_t::always_t result_type;
static constexpr result_type value() noexcept
{
return result_type();
}
};
template <typename Executor, int I>
struct query_static_constexpr_member<
execution::detail::blocking::adapter<Executor>,
execution::detail::blocking::always_t<I>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::blocking_t::always_t result_type;
static constexpr result_type value() noexcept
{
return result_type();
}
};
template <typename Executor, int I>
struct query_static_constexpr_member<
execution::detail::blocking::adapter<Executor>,
execution::detail::blocking::possibly_t<I>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::blocking_t::always_t result_type;
static constexpr result_type value() noexcept
{
return result_type();
}
};
template <typename Executor, int I>
struct query_static_constexpr_member<
execution::detail::blocking::adapter<Executor>,
execution::detail::blocking::never_t<I>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::blocking_t::always_t result_type;
static constexpr result_type value() noexcept
{
return result_type();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
template <typename Executor, typename Property>
struct query_member<
execution::detail::blocking::adapter<Executor>, Property,
enable_if_t<
can_query<const Executor&, Property>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<Executor, Property>::value;
typedef query_result_t<Executor, Property> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
template <typename Executor, int I>
struct require_member<
execution::detail::blocking::adapter<Executor>,
execution::detail::blocking::possibly_t<I>,
enable_if_t<
can_require<
const Executor&,
execution::detail::blocking::possibly_t<I>
>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_require<const Executor&,
execution::detail::blocking::possibly_t<I>>::value;
typedef require_result_t<const Executor&,
execution::detail::blocking::possibly_t<I>> result_type;
};
template <typename Executor, int I>
struct require_member<
execution::detail::blocking::adapter<Executor>,
execution::detail::blocking::never_t<I>,
enable_if_t<
can_require<
const Executor&,
execution::detail::blocking::never_t<I>
>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_require<const Executor&,
execution::detail::blocking::never_t<I>>::value;
typedef require_result_t<const Executor&,
execution::detail::blocking::never_t<I>> result_type;
};
template <typename Executor, typename Property>
struct require_member<
execution::detail::blocking::adapter<Executor>, Property,
enable_if_t<
can_require<const Executor&, Property>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_require<Executor, Property>::value;
typedef execution::detail::blocking::adapter<
decay_t<require_result_t<Executor, Property>>> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT)
template <typename Executor, typename Property>
struct prefer_member<
execution::detail::blocking::adapter<Executor>, Property,
enable_if_t<
can_prefer<const Executor&, Property>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_prefer<Executor, Property>::value;
typedef execution::detail::blocking::adapter<
decay_t<prefer_result_t<Executor, Property>>> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_BLOCKING_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/blocking_adaptation.hpp | //
// execution/blocking_adaptation.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_BLOCKING_ADAPTATION_HPP
#define BOOST_ASIO_EXECUTION_BLOCKING_ADAPTATION_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/event.hpp>
#include <boost/asio/detail/mutex.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/is_applicable_property.hpp>
#include <boost/asio/prefer.hpp>
#include <boost/asio/query.hpp>
#include <boost/asio/require.hpp>
#include <boost/asio/traits/prefer_member.hpp>
#include <boost/asio/traits/query_free.hpp>
#include <boost/asio/traits/query_member.hpp>
#include <boost/asio/traits/query_static_constexpr_member.hpp>
#include <boost/asio/traits/require_member.hpp>
#include <boost/asio/traits/static_query.hpp>
#include <boost/asio/traits/static_require.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// A property to describe whether automatic adaptation of an executor is
/// allowed in order to apply the blocking_adaptation_t::allowed_t property.
struct blocking_adaptation_t
{
/// The blocking_adaptation_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The top-level blocking_adaptation_t property cannot be required.
static constexpr bool is_requirable = false;
/// The top-level blocking_adaptation_t property cannot be preferred.
static constexpr bool is_preferable = false;
/// The type returned by queries against an @c any_executor.
typedef blocking_adaptation_t polymorphic_query_result_type;
/// A sub-property that indicates that automatic adaptation is not allowed.
struct disallowed_t
{
/// The blocking_adaptation_t::disallowed_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The blocking_adaptation_t::disallowed_t property can be required.
static constexpr bool is_requirable = true;
/// The blocking_adaptation_t::disallowed_t property can be preferred.
static constexpr bool is_preferable = true;
/// The type returned by queries against an @c any_executor.
typedef blocking_adaptation_t polymorphic_query_result_type;
/// Default constructor.
constexpr disallowed_t();
/// Get the value associated with a property object.
/**
* @returns disallowed_t();
*/
static constexpr blocking_adaptation_t value();
};
/// A sub-property that indicates that automatic adaptation is allowed.
struct allowed_t
{
/// The blocking_adaptation_t::allowed_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The blocking_adaptation_t::allowed_t property can be required.
static constexpr bool is_requirable = true;
/// The blocking_adaptation_t::allowed_t property can be preferred.
static constexpr bool is_preferable = false;
/// The type returned by queries against an @c any_executor.
typedef blocking_adaptation_t polymorphic_query_result_type;
/// Default constructor.
constexpr allowed_t();
/// Get the value associated with a property object.
/**
* @returns allowed_t();
*/
static constexpr blocking_adaptation_t value();
};
/// A special value used for accessing the blocking_adaptation_t::disallowed_t
/// property.
static constexpr disallowed_t disallowed;
/// A special value used for accessing the blocking_adaptation_t::allowed_t
/// property.
static constexpr allowed_t allowed;
/// Default constructor.
constexpr blocking_adaptation_t();
/// Construct from a sub-property value.
constexpr blocking_adaptation_t(disallowed_t);
/// Construct from a sub-property value.
constexpr blocking_adaptation_t(allowed_t);
/// Compare property values for equality.
friend constexpr bool operator==(
const blocking_adaptation_t& a, const blocking_adaptation_t& b) noexcept;
/// Compare property values for inequality.
friend constexpr bool operator!=(
const blocking_adaptation_t& a, const blocking_adaptation_t& b) noexcept;
};
/// A special value used for accessing the blocking_adaptation_t property.
constexpr blocking_adaptation_t blocking_adaptation;
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
namespace detail {
namespace blocking_adaptation {
template <int I> struct disallowed_t;
template <int I> struct allowed_t;
} // namespace blocking_adaptation
template <int I = 0>
struct blocking_adaptation_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = false;
static constexpr bool is_preferable = false;
typedef blocking_adaptation_t polymorphic_query_result_type;
typedef detail::blocking_adaptation::disallowed_t<I> disallowed_t;
typedef detail::blocking_adaptation::allowed_t<I> allowed_t;
constexpr blocking_adaptation_t()
: value_(-1)
{
}
constexpr blocking_adaptation_t(disallowed_t)
: value_(0)
{
}
constexpr blocking_adaptation_t(allowed_t)
: value_(1)
{
}
template <typename T>
struct proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
struct type
{
template <typename P>
auto query(P&& p) const
noexcept(
noexcept(
declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
)
)
-> decltype(
declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
);
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
};
template <typename T>
struct static_proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
struct type
{
template <typename P>
static constexpr auto query(P&& p)
noexcept(
noexcept(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
)
-> decltype(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
{
return T::query(static_cast<P&&>(p));
}
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
};
template <typename T>
struct query_member :
traits::query_member<typename proxy<T>::type, blocking_adaptation_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename static_proxy<T>::type, blocking_adaptation_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, disallowed_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, disallowed_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, disallowed_t>::value();
}
template <typename T>
static constexpr
typename traits::static_query<T, allowed_t>::result_type
static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::static_query<T, disallowed_t>::is_valid
>* = 0,
enable_if_t<
traits::static_query<T, allowed_t>::is_valid
>* = 0) noexcept
{
return traits::static_query<T, allowed_t>::value();
}
template <typename E,
typename T = decltype(blocking_adaptation_t::static_query<E>())>
static constexpr const T static_query_v
= blocking_adaptation_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
friend constexpr bool operator==(
const blocking_adaptation_t& a, const blocking_adaptation_t& b)
{
return a.value_ == b.value_;
}
friend constexpr bool operator!=(
const blocking_adaptation_t& a, const blocking_adaptation_t& b)
{
return a.value_ != b.value_;
}
struct convertible_from_blocking_adaptation_t
{
constexpr convertible_from_blocking_adaptation_t(
blocking_adaptation_t)
{
}
};
template <typename Executor>
friend constexpr blocking_adaptation_t query(
const Executor& ex, convertible_from_blocking_adaptation_t,
enable_if_t<
can_query<const Executor&, disallowed_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&,
blocking_adaptation_t<>::disallowed_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, disallowed_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, disallowed_t());
}
template <typename Executor>
friend constexpr blocking_adaptation_t query(
const Executor& ex, convertible_from_blocking_adaptation_t,
enable_if_t<
!can_query<const Executor&, disallowed_t>::value
>* = 0,
enable_if_t<
can_query<const Executor&, allowed_t>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&,
blocking_adaptation_t<>::allowed_t>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, allowed_t>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, allowed_t());
}
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(disallowed_t, disallowed);
BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(allowed_t, allowed);
private:
int value_;
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T blocking_adaptation_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I>
const typename blocking_adaptation_t<I>::disallowed_t
blocking_adaptation_t<I>::disallowed;
template <int I>
const typename blocking_adaptation_t<I>::allowed_t
blocking_adaptation_t<I>::allowed;
namespace blocking_adaptation {
template <int I = 0>
struct disallowed_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
typedef blocking_adaptation_t<I> polymorphic_query_result_type;
constexpr disallowed_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename blocking_adaptation_t<I>::template proxy<T>::type,
disallowed_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename blocking_adaptation_t<I>::template static_proxy<T>::type,
disallowed_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename T>
static constexpr disallowed_t static_query(
enable_if_t<
!query_static_constexpr_member<T>::is_valid
>* = 0,
enable_if_t<
!query_member<T>::is_valid
>* = 0,
enable_if_t<
!traits::query_free<T, disallowed_t>::is_valid
>* = 0,
enable_if_t<
!can_query<T, allowed_t<I>>::value
>* = 0) noexcept
{
return disallowed_t();
}
template <typename E, typename T = decltype(disallowed_t::static_query<E>())>
static constexpr const T static_query_v
= disallowed_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr blocking_adaptation_t<I> value()
{
return disallowed_t();
}
friend constexpr bool operator==(const disallowed_t&, const disallowed_t&)
{
return true;
}
friend constexpr bool operator!=(const disallowed_t&, const disallowed_t&)
{
return false;
}
friend constexpr bool operator==(const disallowed_t&, const allowed_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const disallowed_t&, const allowed_t<I>&)
{
return true;
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T disallowed_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename Executor>
class adapter
{
public:
adapter(int, const Executor& e) noexcept
: executor_(e)
{
}
adapter(const adapter& other) noexcept
: executor_(other.executor_)
{
}
adapter(adapter&& other) noexcept
: executor_(static_cast<Executor&&>(other.executor_))
{
}
template <int I>
static constexpr allowed_t<I> query(blocking_adaptation_t<I>) noexcept
{
return allowed_t<I>();
}
template <int I>
static constexpr allowed_t<I> query(allowed_t<I>) noexcept
{
return allowed_t<I>();
}
template <int I>
static constexpr allowed_t<I> query(disallowed_t<I>) noexcept
{
return allowed_t<I>();
}
template <typename Property>
enable_if_t<
can_query<const Executor&, Property>::value,
query_result_t<const Executor&, Property>
> query(const Property& p) const
noexcept(is_nothrow_query<const Executor&, Property>::value)
{
return boost::asio::query(executor_, p);
}
template <int I>
Executor require(disallowed_t<I>) const noexcept
{
return executor_;
}
template <typename Property>
enable_if_t<
can_require<const Executor&, Property>::value,
adapter<decay_t<require_result_t<const Executor&, Property>>>
> require(const Property& p) const
noexcept(is_nothrow_require<const Executor&, Property>::value)
{
return adapter<decay_t<require_result_t<const Executor&, Property>>>(
0, boost::asio::require(executor_, p));
}
template <typename Property>
enable_if_t<
can_prefer<const Executor&, Property>::value,
adapter<decay_t<prefer_result_t<const Executor&, Property>>>
> prefer(const Property& p) const
noexcept(is_nothrow_prefer<const Executor&, Property>::value)
{
return adapter<decay_t<prefer_result_t<const Executor&, Property>>>(
0, boost::asio::prefer(executor_, p));
}
template <typename Function>
enable_if_t<
traits::execute_member<const Executor&, Function>::is_valid
> execute(Function&& f) const
{
executor_.execute(static_cast<Function&&>(f));
}
friend bool operator==(const adapter& a, const adapter& b) noexcept
{
return a.executor_ == b.executor_;
}
friend bool operator!=(const adapter& a, const adapter& b) noexcept
{
return a.executor_ != b.executor_;
}
private:
Executor executor_;
};
template <int I = 0>
struct allowed_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = false;
typedef blocking_adaptation_t<I> polymorphic_query_result_type;
constexpr allowed_t()
{
}
template <typename T>
struct query_member :
traits::query_member<
typename blocking_adaptation_t<I>::template proxy<T>::type,
allowed_t> {};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename blocking_adaptation_t<I>::template static_proxy<T>::type,
allowed_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename E, typename T = decltype(allowed_t::static_query<E>())>
static constexpr const T static_query_v = allowed_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
static constexpr blocking_adaptation_t<I> value()
{
return allowed_t();
}
friend constexpr bool operator==(const allowed_t&, const allowed_t&)
{
return true;
}
friend constexpr bool operator!=(const allowed_t&, const allowed_t&)
{
return false;
}
friend constexpr bool operator==(const allowed_t&, const disallowed_t<I>&)
{
return false;
}
friend constexpr bool operator!=(const allowed_t&, const disallowed_t<I>&)
{
return true;
}
template <typename Executor>
friend adapter<Executor> require(
const Executor& e, const allowed_t&,
enable_if_t<
is_executor<Executor>::value
>* = 0)
{
return adapter<Executor>(0, e);
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T allowed_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename Function>
class blocking_execute_state
{
public:
template <typename F>
blocking_execute_state(F&& f)
: func_(static_cast<F&&>(f)),
is_complete_(false)
{
}
template <typename Executor>
void execute_and_wait(Executor&& ex)
{
handler h = { this };
ex.execute(h);
boost::asio::detail::mutex::scoped_lock lock(mutex_);
while (!is_complete_)
event_.wait(lock);
}
struct cleanup
{
~cleanup()
{
boost::asio::detail::mutex::scoped_lock lock(state_->mutex_);
state_->is_complete_ = true;
state_->event_.unlock_and_signal_one_for_destruction(lock);
}
blocking_execute_state* state_;
};
struct handler
{
void operator()()
{
cleanup c = { state_ };
state_->func_();
}
blocking_execute_state* state_;
};
Function func_;
boost::asio::detail::mutex mutex_;
boost::asio::detail::event event_;
bool is_complete_;
};
template <typename Executor, typename Function>
void blocking_execute(
Executor&& ex,
Function&& func)
{
typedef decay_t<Function> func_t;
blocking_execute_state<func_t> state(static_cast<Function&&>(func));
state.execute_and_wait(ex);
}
} // namespace blocking_adaptation
} // namespace detail
typedef detail::blocking_adaptation_t<> blocking_adaptation_t;
constexpr blocking_adaptation_t blocking_adaptation;
} // namespace execution
#if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
struct is_applicable_property<T, execution::blocking_adaptation_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::blocking_adaptation_t::disallowed_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
template <typename T>
struct is_applicable_property<T, execution::blocking_adaptation_t::allowed_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
#endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
template <typename T>
struct query_free_default<T, execution::blocking_adaptation_t,
enable_if_t<
can_query<T, execution::blocking_adaptation_t::disallowed_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::blocking_adaptation_t::disallowed_t>::value;
typedef execution::blocking_adaptation_t result_type;
};
template <typename T>
struct query_free_default<T, execution::blocking_adaptation_t,
enable_if_t<
!can_query<T, execution::blocking_adaptation_t::disallowed_t>::value
&& can_query<T, execution::blocking_adaptation_t::allowed_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<T, execution::blocking_adaptation_t::allowed_t>::value;
typedef execution::blocking_adaptation_t result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
|| !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
struct static_query<T, execution::blocking_adaptation_t,
enable_if_t<
execution::detail::blocking_adaptation_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::blocking_adaptation_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::blocking_adaptation_t<0>::
query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::blocking_adaptation_t,
enable_if_t<
!execution::detail::blocking_adaptation_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::blocking_adaptation_t<0>::
query_member<T>::is_valid
&& traits::static_query<T,
execution::blocking_adaptation_t::disallowed_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::blocking_adaptation_t::disallowed_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T,
execution::blocking_adaptation_t::disallowed_t>::value();
}
};
template <typename T>
struct static_query<T, execution::blocking_adaptation_t,
enable_if_t<
!execution::detail::blocking_adaptation_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::blocking_adaptation_t<0>::
query_member<T>::is_valid
&& !traits::static_query<T,
execution::blocking_adaptation_t::disallowed_t>::is_valid
&& traits::static_query<T,
execution::blocking_adaptation_t::allowed_t>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename traits::static_query<T,
execution::blocking_adaptation_t::allowed_t>::result_type result_type;
static constexpr result_type value()
{
return traits::static_query<T,
execution::blocking_adaptation_t::allowed_t>::value();
}
};
template <typename T>
struct static_query<T, execution::blocking_adaptation_t::disallowed_t,
enable_if_t<
execution::detail::blocking_adaptation::disallowed_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::blocking_adaptation::disallowed_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::blocking_adaptation::disallowed_t<0>::
query_static_constexpr_member<T>::value();
}
};
template <typename T>
struct static_query<T, execution::blocking_adaptation_t::disallowed_t,
enable_if_t<
!execution::detail::blocking_adaptation::disallowed_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::blocking_adaptation::disallowed_t<0>::
query_member<T>::is_valid
&& !traits::query_free<T,
execution::blocking_adaptation_t::disallowed_t>::is_valid
&& !can_query<T, execution::blocking_adaptation_t::allowed_t>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::blocking_adaptation_t::disallowed_t result_type;
static constexpr result_type value()
{
return result_type();
}
};
template <typename T>
struct static_query<T, execution::blocking_adaptation_t::allowed_t,
enable_if_t<
execution::detail::blocking_adaptation::allowed_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::blocking_adaptation::allowed_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::blocking_adaptation::allowed_t<0>::
query_static_constexpr_member<T>::value();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
#if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_FREE_TRAIT)
template <typename T>
struct require_free_default<T, execution::blocking_adaptation_t::allowed_t,
enable_if_t<
is_same<T, decay_t<T>>::value
&& execution::is_executor<T>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef execution::detail::blocking_adaptation::adapter<T> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_FREE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <typename Executor>
struct equality_comparable<
execution::detail::blocking_adaptation::adapter<Executor>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename Executor, typename Function>
struct execute_member<
execution::detail::blocking_adaptation::adapter<Executor>, Function>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
template <typename Executor, int I>
struct query_static_constexpr_member<
execution::detail::blocking_adaptation::adapter<Executor>,
execution::detail::blocking_adaptation_t<I>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::blocking_adaptation_t::allowed_t result_type;
static constexpr result_type value() noexcept
{
return result_type();
}
};
template <typename Executor, int I>
struct query_static_constexpr_member<
execution::detail::blocking_adaptation::adapter<Executor>,
execution::detail::blocking_adaptation::allowed_t<I>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::blocking_adaptation_t::allowed_t result_type;
static constexpr result_type value() noexcept
{
return result_type();
}
};
template <typename Executor, int I>
struct query_static_constexpr_member<
execution::detail::blocking_adaptation::adapter<Executor>,
execution::detail::blocking_adaptation::disallowed_t<I>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef execution::blocking_adaptation_t::allowed_t result_type;
static constexpr result_type value() noexcept
{
return result_type();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
template <typename Executor, typename Property>
struct query_member<
execution::detail::blocking_adaptation::adapter<Executor>, Property,
enable_if_t<
can_query<const Executor&, Property>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<Executor, Property>::value;
typedef query_result_t<Executor, Property> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
template <typename Executor, int I>
struct require_member<
execution::detail::blocking_adaptation::adapter<Executor>,
execution::detail::blocking_adaptation::disallowed_t<I>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef Executor result_type;
};
template <typename Executor, typename Property>
struct require_member<
execution::detail::blocking_adaptation::adapter<Executor>, Property,
enable_if_t<
can_require<const Executor&, Property>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_require<Executor, Property>::value;
typedef execution::detail::blocking_adaptation::adapter<
decay_t<require_result_t<Executor, Property>>> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT)
template <typename Executor, typename Property>
struct prefer_member<
execution::detail::blocking_adaptation::adapter<Executor>, Property,
enable_if_t<
can_prefer<const Executor&, Property>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_prefer<Executor, Property>::value;
typedef execution::detail::blocking_adaptation::adapter<
decay_t<prefer_result_t<Executor, Property>>> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_BLOCKING_ADAPTATION_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/bad_executor.hpp | //
// execution/bad_executor.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_BAD_EXECUTOR_HPP
#define BOOST_ASIO_EXECUTION_BAD_EXECUTOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <exception>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace execution {
/// Exception thrown when trying to access an empty polymorphic executor.
class bad_executor
: public std::exception
{
public:
/// Constructor.
BOOST_ASIO_DECL bad_executor() noexcept;
/// Obtain message associated with exception.
BOOST_ASIO_DECL virtual const char* what() const noexcept;
};
} // namespace execution
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#if defined(BOOST_ASIO_HEADER_ONLY)
# include <boost/asio/execution/impl/bad_executor.ipp>
#endif // defined(BOOST_ASIO_HEADER_ONLY)
#endif // BOOST_ASIO_EXECUTION_BAD_EXECUTOR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/allocator.hpp | //
// execution/allocator.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_ALLOCATOR_HPP
#define BOOST_ASIO_EXECUTION_ALLOCATOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/is_applicable_property.hpp>
#include <boost/asio/traits/query_static_constexpr_member.hpp>
#include <boost/asio/traits/static_query.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// A property to describe which allocator an executor will use to allocate the
/// memory required to store a submitted function object.
template <typename ProtoAllocator>
struct allocator_t
{
/// The allocator_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The allocator_t property can be required.
static constexpr bool is_requirable = true;
/// The allocator_t property can be preferred.
static constexpr bool is_preferable = true;
/// Default constructor.
constexpr allocator_t();
/// Obtain the allocator stored in the allocator_t property object.
/**
* Present only if @c ProtoAllocator is non-void.
*/
constexpr ProtoAllocator value() const;
/// Create an allocator_t object with a different allocator.
/**
* Present only if @c ProtoAllocator is void.
*/
template <typename OtherAllocator>
allocator_t<OtherAllocator operator()(const OtherAllocator& a);
};
/// A special value used for accessing the allocator_t property.
constexpr allocator_t<void> allocator;
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
template <typename ProtoAllocator>
struct allocator_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
template <typename T>
struct static_proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
struct type
{
template <typename P>
static constexpr auto query(P&& p)
noexcept(
noexcept(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
)
-> decltype(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
{
return T::query(static_cast<P&&>(p));
}
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename static_proxy<T>::type, allocator_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename E, typename T = decltype(allocator_t::static_query<E>())>
static constexpr const T static_query_v = allocator_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
constexpr ProtoAllocator value() const
{
return a_;
}
private:
friend struct allocator_t<void>;
explicit constexpr allocator_t(const ProtoAllocator& a)
: a_(a)
{
}
ProtoAllocator a_;
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename ProtoAllocator> template <typename E, typename T>
const T allocator_t<ProtoAllocator>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <>
struct allocator_t<void>
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = true;
static constexpr bool is_preferable = true;
constexpr allocator_t()
{
}
template <typename T>
struct static_proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
struct type
{
template <typename P>
static constexpr auto query(P&& p)
noexcept(
noexcept(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
)
-> decltype(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
{
return T::query(static_cast<P&&>(p));
}
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename static_proxy<T>::type, allocator_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename E, typename T = decltype(allocator_t::static_query<E>())>
static constexpr const T static_query_v = allocator_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename OtherProtoAllocator>
constexpr allocator_t<OtherProtoAllocator> operator()(
const OtherProtoAllocator& a) const
{
return allocator_t<OtherProtoAllocator>(a);
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename E, typename T>
const T allocator_t<void>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
constexpr allocator_t<void> allocator;
} // namespace execution
#if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T, typename ProtoAllocator>
struct is_applicable_property<T, execution::allocator_t<ProtoAllocator>>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
#endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
|| !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T, typename ProtoAllocator>
struct static_query<T, execution::allocator_t<ProtoAllocator>,
enable_if_t<
execution::allocator_t<ProtoAllocator>::template
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::allocator_t<ProtoAllocator>::template
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::allocator_t<ProtoAllocator>::template
query_static_constexpr_member<T>::value();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_ALLOCATOR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/occupancy.hpp | //
// execution/occupancy.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
#define BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/is_applicable_property.hpp>
#include <boost/asio/traits/query_static_constexpr_member.hpp>
#include <boost/asio/traits/static_query.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// A property that gives an estimate of the number of execution agents that
/// should occupy the associated execution context.
struct occupancy_t
{
/// The occupancy_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The occupancy_t property cannot be required.
static constexpr bool is_requirable = false;
/// The occupancy_t property cannot be preferred.
static constexpr bool is_preferable = false;
/// The type returned by queries against an @c any_executor.
typedef std::size_t polymorphic_query_result_type;
};
/// A special value used for accessing the occupancy_t property.
constexpr occupancy_t occupancy;
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
namespace detail {
template <int I = 0>
struct occupancy_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
static constexpr bool is_applicable_property_v = is_executor<T>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = false;
static constexpr bool is_preferable = false;
typedef std::size_t polymorphic_query_result_type;
constexpr occupancy_t()
{
}
template <typename T>
struct static_proxy
{
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
struct type
{
template <typename P>
static constexpr auto query(P&& p)
noexcept(
noexcept(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
)
-> decltype(
conditional_t<true, T, P>::query(static_cast<P&&>(p))
)
{
return T::query(static_cast<P&&>(p));
}
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
typedef T type;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
};
template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename static_proxy<T>::type, occupancy_t> {};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr typename query_static_constexpr_member<T>::result_type
static_query()
noexcept(query_static_constexpr_member<T>::is_noexcept)
{
return query_static_constexpr_member<T>::value();
}
template <typename E, typename T = decltype(occupancy_t::static_query<E>())>
static constexpr const T static_query_v = occupancy_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <int I> template <typename E, typename T>
const T occupancy_t<I>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace detail
typedef detail::occupancy_t<> occupancy_t;
constexpr occupancy_t occupancy;
} // namespace execution
#if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T>
struct is_applicable_property<T, execution::occupancy_t>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
#endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
|| !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
struct static_query<T, execution::occupancy_t,
enable_if_t<
execution::detail::occupancy_t<0>::
query_static_constexpr_member<T>::is_valid
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
typedef typename execution::detail::occupancy_t<0>::
query_static_constexpr_member<T>::result_type result_type;
static constexpr result_type value()
{
return execution::detail::occupancy_t<0>::
query_static_constexpr_member<T>::value();
}
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_OCCUPANCY_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/context_as.hpp | //
// execution/context_as.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_CONTEXT_AS_HPP
#define BOOST_ASIO_EXECUTION_CONTEXT_AS_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/execution/context.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/is_applicable_property.hpp>
#include <boost/asio/query.hpp>
#include <boost/asio/traits/query_static_constexpr_member.hpp>
#include <boost/asio/traits/static_query.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// A property that is used to obtain the execution context that is associated
/// with an executor.
template <typename U>
struct context_as_t
{
/// The context_as_t property applies to executors.
template <typename T>
static constexpr bool is_applicable_property_v = is_executor_v<T>;
/// The context_t property cannot be required.
static constexpr bool is_requirable = false;
/// The context_t property cannot be preferred.
static constexpr bool is_preferable = false;
/// The type returned by queries against an @c any_executor.
typedef T polymorphic_query_result_type;
};
/// A special value used for accessing the context_as_t property.
template <typename U>
constexpr context_as_t context_as;
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
template <typename T>
struct context_as_t
{
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename U>
static constexpr bool is_applicable_property_v = is_executor<U>::value;
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
static constexpr bool is_requirable = false;
static constexpr bool is_preferable = false;
typedef T polymorphic_query_result_type;
constexpr context_as_t()
{
}
constexpr context_as_t(context_t)
{
}
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename E>
static constexpr
typename context_t::query_static_constexpr_member<E>::result_type
static_query()
noexcept(context_t::query_static_constexpr_member<E>::is_noexcept)
{
return context_t::query_static_constexpr_member<E>::value();
}
template <typename E, typename U = decltype(context_as_t::static_query<E>())>
static constexpr const U static_query_v
= context_as_t::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename Executor, typename U>
friend constexpr U query(
const Executor& ex, const context_as_t<U>&,
enable_if_t<
is_same<T, U>::value
>* = 0,
enable_if_t<
can_query<const Executor&, const context_t&>::value
>* = 0)
#if !defined(__clang__) // Clang crashes if noexcept is used here.
#if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
noexcept(is_nothrow_query<const Executor&, const context_t&>::value)
#else // defined(BOOST_ASIO_MSVC)
noexcept(is_nothrow_query<const Executor&, const context_t&>::value)
#endif // defined(BOOST_ASIO_MSVC)
#endif // !defined(__clang__)
{
return boost::asio::query(ex, context);
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T> template <typename E, typename U>
const U context_as_t<T>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
#if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) \
|| defined(GENERATING_DOCUMENTATION)
template <typename T>
constexpr context_as_t<T> context_as{};
#endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
// || defined(GENERATING_DOCUMENTATION)
} // namespace execution
#if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
template <typename T, typename U>
struct is_applicable_property<T, execution::context_as_t<U>>
: integral_constant<bool, execution::is_executor<T>::value>
{
};
#endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
|| !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T, typename U>
struct static_query<T, execution::context_as_t<U>,
enable_if_t<
static_query<T, execution::context_t>::is_valid
>> : static_query<T, execution::context_t>
{
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
template <typename T, typename U>
struct query_free<T, execution::context_as_t<U>,
enable_if_t<
can_query<const T&, const execution::context_t&>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<const T&, const execution::context_t&>::value;
typedef U result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_CONTEXT_AS_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/any_executor.hpp | //
// execution/any_executor.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_ANY_EXECUTOR_HPP
#define BOOST_ASIO_EXECUTION_ANY_EXECUTOR_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <new>
#include <typeinfo>
#include <boost/asio/detail/assert.hpp>
#include <boost/asio/detail/atomic_count.hpp>
#include <boost/asio/detail/cstddef.hpp>
#include <boost/asio/detail/executor_function.hpp>
#include <boost/asio/detail/memory.hpp>
#include <boost/asio/detail/non_const_lvalue.hpp>
#include <boost/asio/detail/scoped_ptr.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/asio/execution/bad_executor.hpp>
#include <boost/asio/execution/blocking.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/prefer.hpp>
#include <boost/asio/query.hpp>
#include <boost/asio/require.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// Polymorphic executor wrapper.
template <typename... SupportableProperties>
class any_executor
{
public:
/// Default constructor.
any_executor() noexcept;
/// Construct in an empty state. Equivalent effects to default constructor.
any_executor(nullptr_t) noexcept;
/// Copy constructor.
any_executor(const any_executor& e) noexcept;
/// Move constructor.
any_executor(any_executor&& e) noexcept;
/// Construct to point to the same target as another any_executor.
template <class... OtherSupportableProperties>
any_executor(any_executor<OtherSupportableProperties...> e);
/// Construct to point to the same target as another any_executor.
template <class... OtherSupportableProperties>
any_executor(std::nothrow_t,
any_executor<OtherSupportableProperties...> e) noexcept;
/// Construct to point to the same target as another any_executor.
any_executor(std::nothrow_t, const any_executor& e) noexcept;
/// Construct to point to the same target as another any_executor.
any_executor(std::nothrow_t, any_executor&& e) noexcept;
/// Construct a polymorphic wrapper for the specified executor.
template <typename Executor>
any_executor(Executor e);
/// Construct a polymorphic wrapper for the specified executor.
template <typename Executor>
any_executor(std::nothrow_t, Executor e) noexcept;
/// Assignment operator.
any_executor& operator=(const any_executor& e) noexcept;
/// Move assignment operator.
any_executor& operator=(any_executor&& e) noexcept;
/// Assignment operator that sets the polymorphic wrapper to the empty state.
any_executor& operator=(nullptr_t);
/// Assignment operator to create a polymorphic wrapper for the specified
/// executor.
template <typename Executor>
any_executor& operator=(Executor e);
/// Destructor.
~any_executor();
/// Swap targets with another polymorphic wrapper.
void swap(any_executor& other) noexcept;
/// Obtain a polymorphic wrapper with the specified property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::require and boost::asio::prefer customisation points.
*
* For example:
* @code execution::any_executor<execution::blocking_t::possibly_t> ex = ...;
* auto ex2 = boost::asio::requre(ex, execution::blocking.possibly); @endcode
*/
template <typename Property>
any_executor require(Property) const;
/// Obtain a polymorphic wrapper with the specified property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::prefer customisation point.
*
* For example:
* @code execution::any_executor<execution::blocking_t::possibly_t> ex = ...;
* auto ex2 = boost::asio::prefer(ex, execution::blocking.possibly); @endcode
*/
template <typename Property>
any_executor prefer(Property) const;
/// Obtain the value associated with the specified property.
/**
* Do not call this function directly. It is intended for use with the
* boost::asio::query customisation point.
*
* For example:
* @code execution::any_executor<execution::occupancy_t> ex = ...;
* size_t n = boost::asio::query(ex, execution::occupancy); @endcode
*/
template <typename Property>
typename Property::polymorphic_query_result_type query(Property) const;
/// Execute the function on the target executor.
/**
* Throws boost::asio::bad_executor if the polymorphic wrapper has no target.
*/
template <typename Function>
void execute(Function&& f) const;
/// Obtain the underlying execution context.
/**
* This function is provided for backward compatibility. It is automatically
* defined when the @c SupportableProperties... list includes a property of
* type <tt>execution::context_as<U></tt>, for some type <tt>U</tt>.
*/
automatically_determined context() const;
/// Determine whether the wrapper has a target executor.
/**
* @returns @c true if the polymorphic wrapper has a target executor,
* otherwise false.
*/
explicit operator bool() const noexcept;
/// Get the type of the target executor.
const type_info& target_type() const noexcept;
/// Get a pointer to the target executor.
template <typename Executor> Executor* target() noexcept;
/// Get a pointer to the target executor.
template <typename Executor> const Executor* target() const noexcept;
};
/// Equality operator.
/**
* @relates any_executor
*/
template <typename... SupportableProperties>
bool operator==(const any_executor<SupportableProperties...>& a,
const any_executor<SupportableProperties...>& b) noexcept;
/// Equality operator.
/**
* @relates any_executor
*/
template <typename... SupportableProperties>
bool operator==(const any_executor<SupportableProperties...>& a,
nullptr_t) noexcept;
/// Equality operator.
/**
* @relates any_executor
*/
template <typename... SupportableProperties>
bool operator==(nullptr_t,
const any_executor<SupportableProperties...>& b) noexcept;
/// Inequality operator.
/**
* @relates any_executor
*/
template <typename... SupportableProperties>
bool operator!=(const any_executor<SupportableProperties...>& a,
const any_executor<SupportableProperties...>& b) noexcept;
/// Inequality operator.
/**
* @relates any_executor
*/
template <typename... SupportableProperties>
bool operator!=(const any_executor<SupportableProperties...>& a,
nullptr_t) noexcept;
/// Inequality operator.
/**
* @relates any_executor
*/
template <typename... SupportableProperties>
bool operator!=(nullptr_t,
const any_executor<SupportableProperties...>& b) noexcept;
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
#if !defined(BOOST_ASIO_EXECUTION_ANY_EXECUTOR_FWD_DECL)
#define BOOST_ASIO_EXECUTION_ANY_EXECUTOR_FWD_DECL
template <typename... SupportableProperties>
class any_executor;
#endif // !defined(BOOST_ASIO_EXECUTION_ANY_EXECUTOR_FWD_DECL)
template <typename U>
struct context_as_t;
namespace detail {
// Traits used to detect whether a property is requirable or preferable, taking
// into account that T::is_requirable or T::is_preferable may not not be well
// formed.
template <typename T, typename = void>
struct is_requirable : false_type {};
template <typename T>
struct is_requirable<T, enable_if_t<T::is_requirable>> : true_type {};
template <typename T, typename = void>
struct is_preferable : false_type {};
template <typename T>
struct is_preferable<T, enable_if_t<T::is_preferable>> : true_type {};
// Trait used to detect context_as property, for backward compatibility.
template <typename T>
struct is_context_as : false_type {};
template <typename U>
struct is_context_as<context_as_t<U>> : true_type {};
// Helper template to:
// - Check if a target can supply the supportable properties.
// - Find the first convertible-from-T property in the list.
template <std::size_t I, typename Props>
struct supportable_properties;
template <std::size_t I, typename Prop>
struct supportable_properties<I, void(Prop)>
{
template <typename T>
struct is_valid_target : integral_constant<bool,
(
is_requirable<Prop>::value
? can_require<T, Prop>::value
: true
)
&&
(
is_preferable<Prop>::value
? can_prefer<T, Prop>::value
: true
)
&&
(
!is_requirable<Prop>::value && !is_preferable<Prop>::value
? can_query<T, Prop>::value
: true
)
>
{
};
struct found
{
static constexpr bool value = true;
typedef Prop type;
typedef typename Prop::polymorphic_query_result_type query_result_type;
static constexpr std::size_t index = I;
};
struct not_found
{
static constexpr bool value = false;
};
template <typename T>
struct find_convertible_property :
conditional_t<
is_same<T, Prop>::value || is_convertible<T, Prop>::value,
found,
not_found
> {};
template <typename T>
struct find_convertible_requirable_property :
conditional_t<
is_requirable<Prop>::value
&& (is_same<T, Prop>::value || is_convertible<T, Prop>::value),
found,
not_found
> {};
template <typename T>
struct find_convertible_preferable_property :
conditional_t<
is_preferable<Prop>::value
&& (is_same<T, Prop>::value || is_convertible<T, Prop>::value),
found,
not_found
> {};
struct find_context_as_property :
conditional_t<
is_context_as<Prop>::value,
found,
not_found
> {};
};
template <std::size_t I, typename Head, typename... Tail>
struct supportable_properties<I, void(Head, Tail...)>
{
template <typename T>
struct is_valid_target : integral_constant<bool,
(
supportable_properties<I,
void(Head)>::template is_valid_target<T>::value
&&
supportable_properties<I + 1,
void(Tail...)>::template is_valid_target<T>::value
)
>
{
};
template <typename T>
struct find_convertible_property :
conditional_t<
is_convertible<T, Head>::value,
typename supportable_properties<I, void(Head)>::found,
typename supportable_properties<I + 1,
void(Tail...)>::template find_convertible_property<T>
> {};
template <typename T>
struct find_convertible_requirable_property :
conditional_t<
is_requirable<Head>::value
&& is_convertible<T, Head>::value,
typename supportable_properties<I, void(Head)>::found,
typename supportable_properties<I + 1,
void(Tail...)>::template find_convertible_requirable_property<T>
> {};
template <typename T>
struct find_convertible_preferable_property :
conditional_t<
is_preferable<Head>::value
&& is_convertible<T, Head>::value,
typename supportable_properties<I, void(Head)>::found,
typename supportable_properties<I + 1,
void(Tail...)>::template find_convertible_preferable_property<T>
> {};
struct find_context_as_property :
conditional_t<
is_context_as<Head>::value,
typename supportable_properties<I, void(Head)>::found,
typename supportable_properties<I + 1,
void(Tail...)>::find_context_as_property
> {};
};
template <typename T, typename Props>
struct is_valid_target_executor :
conditional_t<
is_executor<T>::value,
typename supportable_properties<0, Props>::template is_valid_target<T>,
false_type
>
{
};
template <typename Props>
struct is_valid_target_executor<int, Props> : false_type
{
};
class shared_target_executor
{
public:
template <typename E>
shared_target_executor(E&& e, decay_t<E>*& target)
{
impl<decay_t<E>>* i =
new impl<decay_t<E>>(static_cast<E&&>(e));
target = &i->ex_;
impl_ = i;
}
template <typename E>
shared_target_executor(std::nothrow_t, E&& e, decay_t<E>*& target) noexcept
{
impl<decay_t<E>>* i =
new (std::nothrow) impl<decay_t<E>>(static_cast<E&&>(e));
target = i ? &i->ex_ : 0;
impl_ = i;
}
shared_target_executor(const shared_target_executor& other) noexcept
: impl_(other.impl_)
{
if (impl_)
boost::asio::detail::ref_count_up(impl_->ref_count_);
}
shared_target_executor(shared_target_executor&& other) noexcept
: impl_(other.impl_)
{
other.impl_ = 0;
}
~shared_target_executor()
{
if (impl_)
if (boost::asio::detail::ref_count_down(impl_->ref_count_))
delete impl_;
}
void* get() const noexcept
{
return impl_ ? impl_->get() : 0;
}
private:
shared_target_executor& operator=(
const shared_target_executor& other) = delete;
shared_target_executor& operator=(
shared_target_executor&& other) = delete;
struct impl_base
{
impl_base() : ref_count_(1) {}
virtual ~impl_base() {}
virtual void* get() = 0;
boost::asio::detail::atomic_count ref_count_;
};
template <typename Executor>
struct impl : impl_base
{
impl(Executor ex) : ex_(static_cast<Executor&&>(ex)) {}
virtual void* get() { return &ex_; }
Executor ex_;
};
impl_base* impl_;
};
class any_executor_base
{
public:
any_executor_base() noexcept
: object_fns_(0),
target_(0),
target_fns_(0)
{
}
template <BOOST_ASIO_EXECUTION_EXECUTOR Executor>
any_executor_base(Executor ex, false_type)
: target_fns_(target_fns_table<Executor>(
any_executor_base::query_blocking(ex,
can_query<const Executor&, const execution::blocking_t&>())
== execution::blocking.always))
{
any_executor_base::construct_object(ex,
integral_constant<bool,
sizeof(Executor) <= sizeof(object_type)
&& alignment_of<Executor>::value <= alignment_of<object_type>::value
>());
}
template <BOOST_ASIO_EXECUTION_EXECUTOR Executor>
any_executor_base(std::nothrow_t, Executor ex, false_type) noexcept
: target_fns_(target_fns_table<Executor>(
any_executor_base::query_blocking(ex,
can_query<const Executor&, const execution::blocking_t&>())
== execution::blocking.always))
{
any_executor_base::construct_object(std::nothrow, ex,
integral_constant<bool,
sizeof(Executor) <= sizeof(object_type)
&& alignment_of<Executor>::value <= alignment_of<object_type>::value
>());
if (target_ == 0)
{
object_fns_ = 0;
target_fns_ = 0;
}
}
template <BOOST_ASIO_EXECUTION_EXECUTOR Executor>
any_executor_base(Executor other, true_type)
: object_fns_(object_fns_table<shared_target_executor>()),
target_fns_(other.target_fns_)
{
Executor* p = 0;
new (&object_) shared_target_executor(
static_cast<Executor&&>(other), p);
target_ = p->template target<void>();
}
template <BOOST_ASIO_EXECUTION_EXECUTOR Executor>
any_executor_base(std::nothrow_t,
Executor other, true_type) noexcept
: object_fns_(object_fns_table<shared_target_executor>()),
target_fns_(other.target_fns_)
{
Executor* p = 0;
new (&object_) shared_target_executor(
std::nothrow, static_cast<Executor&&>(other), p);
if (p)
target_ = p->template target<void>();
else
{
target_ = 0;
object_fns_ = 0;
target_fns_ = 0;
}
}
any_executor_base(const any_executor_base& other) noexcept
{
if (!!other)
{
object_fns_ = other.object_fns_;
target_fns_ = other.target_fns_;
object_fns_->copy(*this, other);
}
else
{
object_fns_ = 0;
target_ = 0;
target_fns_ = 0;
}
}
~any_executor_base() noexcept
{
if (!!*this)
object_fns_->destroy(*this);
}
any_executor_base& operator=(
const any_executor_base& other) noexcept
{
if (this != &other)
{
if (!!*this)
object_fns_->destroy(*this);
if (!!other)
{
object_fns_ = other.object_fns_;
target_fns_ = other.target_fns_;
object_fns_->copy(*this, other);
}
else
{
object_fns_ = 0;
target_ = 0;
target_fns_ = 0;
}
}
return *this;
}
any_executor_base& operator=(nullptr_t) noexcept
{
if (target_)
object_fns_->destroy(*this);
target_ = 0;
object_fns_ = 0;
target_fns_ = 0;
return *this;
}
any_executor_base(any_executor_base&& other) noexcept
{
if (other.target_)
{
object_fns_ = other.object_fns_;
target_fns_ = other.target_fns_;
other.object_fns_ = 0;
other.target_fns_ = 0;
object_fns_->move(*this, other);
other.target_ = 0;
}
else
{
object_fns_ = 0;
target_ = 0;
target_fns_ = 0;
}
}
any_executor_base& operator=(
any_executor_base&& other) noexcept
{
if (this != &other)
{
if (!!*this)
object_fns_->destroy(*this);
if (!!other)
{
object_fns_ = other.object_fns_;
target_fns_ = other.target_fns_;
other.object_fns_ = 0;
other.target_fns_ = 0;
object_fns_->move(*this, other);
other.target_ = 0;
}
else
{
object_fns_ = 0;
target_ = 0;
target_fns_ = 0;
}
}
return *this;
}
void swap(any_executor_base& other) noexcept
{
if (this != &other)
{
any_executor_base tmp(static_cast<any_executor_base&&>(other));
other = static_cast<any_executor_base&&>(*this);
*this = static_cast<any_executor_base&&>(tmp);
}
}
template <typename F>
void execute(F&& f) const
{
if (target_)
{
if (target_fns_->blocking_execute != 0)
{
boost::asio::detail::non_const_lvalue<F> f2(f);
target_fns_->blocking_execute(*this, function_view(f2.value));
}
else
{
target_fns_->execute(*this,
function(static_cast<F&&>(f), std::allocator<void>()));
}
}
else
{
bad_executor ex;
boost::asio::detail::throw_exception(ex);
}
}
template <typename Executor>
Executor* target()
{
return target_ && (is_same<Executor, void>::value
|| target_fns_->target_type() == target_type_ex<Executor>())
? static_cast<Executor*>(target_) : 0;
}
template <typename Executor>
const Executor* target() const
{
return target_ && (is_same<Executor, void>::value
|| target_fns_->target_type() == target_type_ex<Executor>())
? static_cast<const Executor*>(target_) : 0;
}
#if !defined(BOOST_ASIO_NO_TYPEID)
const std::type_info& target_type() const
{
return target_ ? target_fns_->target_type() : typeid(void);
}
#else // !defined(BOOST_ASIO_NO_TYPEID)
const void* target_type() const
{
return target_ ? target_fns_->target_type() : 0;
}
#endif // !defined(BOOST_ASIO_NO_TYPEID)
struct unspecified_bool_type_t {};
typedef void (*unspecified_bool_type)(unspecified_bool_type_t);
static void unspecified_bool_true(unspecified_bool_type_t) {}
operator unspecified_bool_type() const noexcept
{
return target_ ? &any_executor_base::unspecified_bool_true : 0;
}
bool operator!() const noexcept
{
return target_ == 0;
}
protected:
bool equality_helper(const any_executor_base& other) const noexcept
{
if (target_ == other.target_)
return true;
if (target_ && !other.target_)
return false;
if (!target_ && other.target_)
return false;
if (target_fns_ != other.target_fns_)
return false;
return target_fns_->equal(*this, other);
}
template <typename Ex>
Ex& object()
{
return *static_cast<Ex*>(static_cast<void*>(&object_));
}
template <typename Ex>
const Ex& object() const
{
return *static_cast<const Ex*>(static_cast<const void*>(&object_));
}
struct object_fns
{
void (*destroy)(any_executor_base&);
void (*copy)(any_executor_base&, const any_executor_base&);
void (*move)(any_executor_base&, any_executor_base&);
const void* (*target)(const any_executor_base&);
};
static void destroy_shared(any_executor_base& ex)
{
typedef shared_target_executor type;
ex.object<type>().~type();
}
static void copy_shared(any_executor_base& ex1, const any_executor_base& ex2)
{
typedef shared_target_executor type;
new (&ex1.object_) type(ex2.object<type>());
ex1.target_ = ex2.target_;
}
static void move_shared(any_executor_base& ex1, any_executor_base& ex2)
{
typedef shared_target_executor type;
new (&ex1.object_) type(static_cast<type&&>(ex2.object<type>()));
ex1.target_ = ex2.target_;
ex2.object<type>().~type();
}
static const void* target_shared(const any_executor_base& ex)
{
typedef shared_target_executor type;
return ex.object<type>().get();
}
template <typename Obj>
static const object_fns* object_fns_table(
enable_if_t<
is_same<Obj, shared_target_executor>::value
>* = 0)
{
static const object_fns fns =
{
&any_executor_base::destroy_shared,
&any_executor_base::copy_shared,
&any_executor_base::move_shared,
&any_executor_base::target_shared
};
return &fns;
}
template <typename Obj>
static void destroy_object(any_executor_base& ex)
{
ex.object<Obj>().~Obj();
}
template <typename Obj>
static void copy_object(any_executor_base& ex1, const any_executor_base& ex2)
{
new (&ex1.object_) Obj(ex2.object<Obj>());
ex1.target_ = &ex1.object<Obj>();
}
template <typename Obj>
static void move_object(any_executor_base& ex1, any_executor_base& ex2)
{
new (&ex1.object_) Obj(static_cast<Obj&&>(ex2.object<Obj>()));
ex1.target_ = &ex1.object<Obj>();
ex2.object<Obj>().~Obj();
}
template <typename Obj>
static const void* target_object(const any_executor_base& ex)
{
return &ex.object<Obj>();
}
template <typename Obj>
static const object_fns* object_fns_table(
enable_if_t<
!is_same<Obj, void>::value
&& !is_same<Obj, shared_target_executor>::value
>* = 0)
{
static const object_fns fns =
{
&any_executor_base::destroy_object<Obj>,
&any_executor_base::copy_object<Obj>,
&any_executor_base::move_object<Obj>,
&any_executor_base::target_object<Obj>
};
return &fns;
}
typedef boost::asio::detail::executor_function function;
typedef boost::asio::detail::executor_function_view function_view;
struct target_fns
{
#if !defined(BOOST_ASIO_NO_TYPEID)
const std::type_info& (*target_type)();
#else // !defined(BOOST_ASIO_NO_TYPEID)
const void* (*target_type)();
#endif // !defined(BOOST_ASIO_NO_TYPEID)
bool (*equal)(const any_executor_base&, const any_executor_base&);
void (*execute)(const any_executor_base&, function&&);
void (*blocking_execute)(const any_executor_base&, function_view);
};
#if !defined(BOOST_ASIO_NO_TYPEID)
template <typename Ex>
static const std::type_info& target_type_ex()
{
return typeid(Ex);
}
#else // !defined(BOOST_ASIO_NO_TYPEID)
template <typename Ex>
static const void* target_type_ex()
{
static int unique_id;
return &unique_id;
}
#endif // !defined(BOOST_ASIO_NO_TYPEID)
template <typename Ex>
static bool equal_ex(const any_executor_base& ex1,
const any_executor_base& ex2)
{
const Ex* p1 = ex1.target<Ex>();
const Ex* p2 = ex2.target<Ex>();
BOOST_ASIO_ASSUME(p1 != 0 && p2 != 0);
return *p1 == *p2;
}
template <typename Ex>
static void execute_ex(const any_executor_base& ex, function&& f)
{
const Ex* p = ex.target<Ex>();
BOOST_ASIO_ASSUME(p != 0);
p->execute(static_cast<function&&>(f));
}
template <typename Ex>
static void blocking_execute_ex(const any_executor_base& ex, function_view f)
{
const Ex* p = ex.target<Ex>();
BOOST_ASIO_ASSUME(p != 0);
p->execute(f);
}
template <typename Ex>
static const target_fns* target_fns_table(bool is_always_blocking,
enable_if_t<
!is_same<Ex, void>::value
>* = 0)
{
static const target_fns fns_with_execute =
{
&any_executor_base::target_type_ex<Ex>,
&any_executor_base::equal_ex<Ex>,
&any_executor_base::execute_ex<Ex>,
0
};
static const target_fns fns_with_blocking_execute =
{
&any_executor_base::target_type_ex<Ex>,
&any_executor_base::equal_ex<Ex>,
0,
&any_executor_base::blocking_execute_ex<Ex>
};
return is_always_blocking ? &fns_with_blocking_execute : &fns_with_execute;
}
#if defined(BOOST_ASIO_MSVC)
# pragma warning (push)
# pragma warning (disable:4702)
#endif // defined(BOOST_ASIO_MSVC)
static void query_fn_void(void*, const void*, const void*)
{
bad_executor ex;
boost::asio::detail::throw_exception(ex);
}
template <typename Ex, class Prop>
static void query_fn_non_void(void*, const void* ex, const void* prop,
enable_if_t<
boost::asio::can_query<const Ex&, const Prop&>::value
&& is_same<typename Prop::polymorphic_query_result_type, void>::value
>*)
{
boost::asio::query(*static_cast<const Ex*>(ex),
*static_cast<const Prop*>(prop));
}
template <typename Ex, class Prop>
static void query_fn_non_void(void*, const void*, const void*,
enable_if_t<
!boost::asio::can_query<const Ex&, const Prop&>::value
&& is_same<typename Prop::polymorphic_query_result_type, void>::value
>*)
{
}
template <typename Ex, class Prop>
static void query_fn_non_void(void* result, const void* ex, const void* prop,
enable_if_t<
boost::asio::can_query<const Ex&, const Prop&>::value
&& !is_same<typename Prop::polymorphic_query_result_type, void>::value
&& is_reference<typename Prop::polymorphic_query_result_type>::value
>*)
{
*static_cast<remove_reference_t<
typename Prop::polymorphic_query_result_type>**>(result)
= &static_cast<typename Prop::polymorphic_query_result_type>(
boost::asio::query(*static_cast<const Ex*>(ex),
*static_cast<const Prop*>(prop)));
}
template <typename Ex, class Prop>
static void query_fn_non_void(void*, const void*, const void*,
enable_if_t<
!boost::asio::can_query<const Ex&, const Prop&>::value
&& !is_same<typename Prop::polymorphic_query_result_type, void>::value
&& is_reference<typename Prop::polymorphic_query_result_type>::value
>*)
{
std::terminate(); // Combination should not be possible.
}
template <typename Ex, class Prop>
static void query_fn_non_void(void* result, const void* ex, const void* prop,
enable_if_t<
boost::asio::can_query<const Ex&, const Prop&>::value
&& !is_same<typename Prop::polymorphic_query_result_type, void>::value
&& is_scalar<typename Prop::polymorphic_query_result_type>::value
>*)
{
*static_cast<typename Prop::polymorphic_query_result_type*>(result)
= static_cast<typename Prop::polymorphic_query_result_type>(
boost::asio::query(*static_cast<const Ex*>(ex),
*static_cast<const Prop*>(prop)));
}
template <typename Ex, class Prop>
static void query_fn_non_void(void* result, const void*, const void*,
enable_if_t<
!boost::asio::can_query<const Ex&, const Prop&>::value
&& !is_same<typename Prop::polymorphic_query_result_type, void>::value
&& is_scalar<typename Prop::polymorphic_query_result_type>::value
>*)
{
*static_cast<typename Prop::polymorphic_query_result_type*>(result)
= typename Prop::polymorphic_query_result_type();
}
template <typename Ex, class Prop>
static void query_fn_non_void(void* result, const void* ex, const void* prop,
enable_if_t<
boost::asio::can_query<const Ex&, const Prop&>::value
&& !is_same<typename Prop::polymorphic_query_result_type, void>::value
&& !is_reference<typename Prop::polymorphic_query_result_type>::value
&& !is_scalar<typename Prop::polymorphic_query_result_type>::value
>*)
{
*static_cast<typename Prop::polymorphic_query_result_type**>(result)
= new typename Prop::polymorphic_query_result_type(
boost::asio::query(*static_cast<const Ex*>(ex),
*static_cast<const Prop*>(prop)));
}
template <typename Ex, class Prop>
static void query_fn_non_void(void* result, const void*, const void*, ...)
{
*static_cast<typename Prop::polymorphic_query_result_type**>(result)
= new typename Prop::polymorphic_query_result_type();
}
template <typename Ex, class Prop>
static void query_fn_impl(void* result, const void* ex, const void* prop,
enable_if_t<
is_same<Ex, void>::value
>*)
{
query_fn_void(result, ex, prop);
}
template <typename Ex, class Prop>
static void query_fn_impl(void* result, const void* ex, const void* prop,
enable_if_t<
!is_same<Ex, void>::value
>*)
{
query_fn_non_void<Ex, Prop>(result, ex, prop, 0);
}
template <typename Ex, class Prop>
static void query_fn(void* result, const void* ex, const void* prop)
{
query_fn_impl<Ex, Prop>(result, ex, prop, 0);
}
template <typename Poly, typename Ex, class Prop>
static Poly require_fn_impl(const void*, const void*,
enable_if_t<
is_same<Ex, void>::value
>*)
{
bad_executor ex;
boost::asio::detail::throw_exception(ex);
return Poly();
}
template <typename Poly, typename Ex, class Prop>
static Poly require_fn_impl(const void* ex, const void* prop,
enable_if_t<
!is_same<Ex, void>::value && Prop::is_requirable
>*)
{
return boost::asio::require(*static_cast<const Ex*>(ex),
*static_cast<const Prop*>(prop));
}
template <typename Poly, typename Ex, class Prop>
static Poly require_fn_impl(const void*, const void*, ...)
{
return Poly();
}
template <typename Poly, typename Ex, class Prop>
static Poly require_fn(const void* ex, const void* prop)
{
return require_fn_impl<Poly, Ex, Prop>(ex, prop, 0);
}
template <typename Poly, typename Ex, class Prop>
static Poly prefer_fn_impl(const void*, const void*,
enable_if_t<
is_same<Ex, void>::value
>*)
{
bad_executor ex;
boost::asio::detail::throw_exception(ex);
return Poly();
}
template <typename Poly, typename Ex, class Prop>
static Poly prefer_fn_impl(const void* ex, const void* prop,
enable_if_t<
!is_same<Ex, void>::value && Prop::is_preferable
>*)
{
return boost::asio::prefer(*static_cast<const Ex*>(ex),
*static_cast<const Prop*>(prop));
}
template <typename Poly, typename Ex, class Prop>
static Poly prefer_fn_impl(const void*, const void*, ...)
{
return Poly();
}
template <typename Poly, typename Ex, class Prop>
static Poly prefer_fn(const void* ex, const void* prop)
{
return prefer_fn_impl<Poly, Ex, Prop>(ex, prop, 0);
}
template <typename Poly>
struct prop_fns
{
void (*query)(void*, const void*, const void*);
Poly (*require)(const void*, const void*);
Poly (*prefer)(const void*, const void*);
};
#if defined(BOOST_ASIO_MSVC)
# pragma warning (pop)
#endif // defined(BOOST_ASIO_MSVC)
private:
template <typename Executor>
static execution::blocking_t query_blocking(const Executor& ex, true_type)
{
return boost::asio::query(ex, execution::blocking);
}
template <typename Executor>
static execution::blocking_t query_blocking(const Executor&, false_type)
{
return execution::blocking_t();
}
template <typename Executor>
void construct_object(Executor& ex, true_type)
{
object_fns_ = object_fns_table<Executor>();
target_ = new (&object_) Executor(static_cast<Executor&&>(ex));
}
template <typename Executor>
void construct_object(Executor& ex, false_type)
{
object_fns_ = object_fns_table<shared_target_executor>();
Executor* p = 0;
new (&object_) shared_target_executor(
static_cast<Executor&&>(ex), p);
target_ = p;
}
template <typename Executor>
void construct_object(std::nothrow_t,
Executor& ex, true_type) noexcept
{
object_fns_ = object_fns_table<Executor>();
target_ = new (&object_) Executor(static_cast<Executor&&>(ex));
}
template <typename Executor>
void construct_object(std::nothrow_t,
Executor& ex, false_type) noexcept
{
object_fns_ = object_fns_table<shared_target_executor>();
Executor* p = 0;
new (&object_) shared_target_executor(
std::nothrow, static_cast<Executor&&>(ex), p);
target_ = p;
}
/*private:*/public:
// template <typename...> friend class any_executor;
typedef aligned_storage<
sizeof(boost::asio::detail::shared_ptr<void>) + sizeof(void*),
alignment_of<boost::asio::detail::shared_ptr<void>>::value
>::type object_type;
object_type object_;
const object_fns* object_fns_;
void* target_;
const target_fns* target_fns_;
};
template <typename Derived, typename Property, typename = void>
struct any_executor_context
{
};
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Derived, typename Property>
struct any_executor_context<Derived, Property, enable_if_t<Property::value>>
{
typename Property::query_result_type context() const
{
return static_cast<const Derived*>(this)->query(typename Property::type());
}
};
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
} // namespace detail
template <>
class any_executor<> : public detail::any_executor_base
{
public:
any_executor() noexcept
: detail::any_executor_base()
{
}
any_executor(nullptr_t) noexcept
: detail::any_executor_base()
{
}
template <typename Executor>
any_executor(Executor ex,
enable_if_t<
conditional_t<
!is_same<Executor, any_executor>::value
&& !is_base_of<detail::any_executor_base, Executor>::value,
is_executor<Executor>,
false_type
>::value
>* = 0)
: detail::any_executor_base(
static_cast<Executor&&>(ex), false_type())
{
}
template <typename Executor>
any_executor(std::nothrow_t, Executor ex,
enable_if_t<
conditional_t<
!is_same<Executor, any_executor>::value
&& !is_base_of<detail::any_executor_base, Executor>::value,
is_executor<Executor>,
false_type
>::value
>* = 0) noexcept
: detail::any_executor_base(std::nothrow,
static_cast<Executor&&>(ex), false_type())
{
}
template <typename... OtherSupportableProperties>
any_executor(any_executor<OtherSupportableProperties...> other)
: detail::any_executor_base(
static_cast<const detail::any_executor_base&>(other))
{
}
template <typename... OtherSupportableProperties>
any_executor(std::nothrow_t,
any_executor<OtherSupportableProperties...> other) noexcept
: detail::any_executor_base(
static_cast<const detail::any_executor_base&>(other))
{
}
any_executor(const any_executor& other) noexcept
: detail::any_executor_base(
static_cast<const detail::any_executor_base&>(other))
{
}
any_executor(std::nothrow_t, const any_executor& other) noexcept
: detail::any_executor_base(
static_cast<const detail::any_executor_base&>(other))
{
}
any_executor& operator=(const any_executor& other) noexcept
{
if (this != &other)
{
detail::any_executor_base::operator=(
static_cast<const detail::any_executor_base&>(other));
}
return *this;
}
any_executor& operator=(nullptr_t p) noexcept
{
detail::any_executor_base::operator=(p);
return *this;
}
any_executor(any_executor&& other) noexcept
: detail::any_executor_base(
static_cast<any_executor_base&&>(
static_cast<any_executor_base&>(other)))
{
}
any_executor(std::nothrow_t, any_executor&& other) noexcept
: detail::any_executor_base(
static_cast<any_executor_base&&>(
static_cast<any_executor_base&>(other)))
{
}
any_executor& operator=(any_executor&& other) noexcept
{
if (this != &other)
{
detail::any_executor_base::operator=(
static_cast<detail::any_executor_base&&>(
static_cast<detail::any_executor_base&>(other)));
}
return *this;
}
void swap(any_executor& other) noexcept
{
detail::any_executor_base::swap(
static_cast<detail::any_executor_base&>(other));
}
using detail::any_executor_base::execute;
using detail::any_executor_base::target;
using detail::any_executor_base::target_type;
using detail::any_executor_base::operator unspecified_bool_type;
using detail::any_executor_base::operator!;
bool equality_helper(const any_executor& other) const noexcept
{
return any_executor_base::equality_helper(other);
}
template <typename AnyExecutor1, typename AnyExecutor2>
friend enable_if_t<
is_base_of<any_executor, AnyExecutor1>::value
|| is_base_of<any_executor, AnyExecutor2>::value,
bool
> operator==(const AnyExecutor1& a,
const AnyExecutor2& b) noexcept
{
return static_cast<const any_executor&>(a).equality_helper(b);
}
template <typename AnyExecutor>
friend enable_if_t<
is_same<AnyExecutor, any_executor>::value,
bool
> operator==(const AnyExecutor& a, nullptr_t) noexcept
{
return !a;
}
template <typename AnyExecutor>
friend enable_if_t<
is_same<AnyExecutor, any_executor>::value,
bool
> operator==(nullptr_t, const AnyExecutor& b) noexcept
{
return !b;
}
template <typename AnyExecutor1, typename AnyExecutor2>
friend enable_if_t<
is_base_of<any_executor, AnyExecutor1>::value
|| is_base_of<any_executor, AnyExecutor2>::value,
bool
> operator!=(const AnyExecutor1& a,
const AnyExecutor2& b) noexcept
{
return !static_cast<const any_executor&>(a).equality_helper(b);
}
template <typename AnyExecutor>
friend enable_if_t<
is_same<AnyExecutor, any_executor>::value,
bool
> operator!=(const AnyExecutor& a, nullptr_t) noexcept
{
return !!a;
}
template <typename AnyExecutor>
friend enable_if_t<
is_same<AnyExecutor, any_executor>::value,
bool
> operator!=(nullptr_t, const AnyExecutor& b) noexcept
{
return !!b;
}
};
inline void swap(any_executor<>& a, any_executor<>& b) noexcept
{
return a.swap(b);
}
template <typename... SupportableProperties>
class any_executor :
public detail::any_executor_base,
public detail::any_executor_context<
any_executor<SupportableProperties...>,
typename detail::supportable_properties<
0, void(SupportableProperties...)>::find_context_as_property>
{
public:
any_executor() noexcept
: detail::any_executor_base(),
prop_fns_(prop_fns_table<void>())
{
}
any_executor(nullptr_t) noexcept
: detail::any_executor_base(),
prop_fns_(prop_fns_table<void>())
{
}
template <typename Executor>
any_executor(Executor ex,
enable_if_t<
conditional_t<
!is_same<Executor, any_executor>::value
&& !is_base_of<detail::any_executor_base, Executor>::value,
detail::is_valid_target_executor<
Executor, void(SupportableProperties...)>,
false_type
>::value
>* = 0)
: detail::any_executor_base(
static_cast<Executor&&>(ex), false_type()),
prop_fns_(prop_fns_table<Executor>())
{
}
template <typename Executor>
any_executor(std::nothrow_t, Executor ex,
enable_if_t<
conditional_t<
!is_same<Executor, any_executor>::value
&& !is_base_of<detail::any_executor_base, Executor>::value,
detail::is_valid_target_executor<
Executor, void(SupportableProperties...)>,
false_type
>::value
>* = 0) noexcept
: detail::any_executor_base(std::nothrow,
static_cast<Executor&&>(ex), false_type()),
prop_fns_(prop_fns_table<Executor>())
{
if (this->template target<void>() == 0)
prop_fns_ = prop_fns_table<void>();
}
template <typename... OtherSupportableProperties>
any_executor(any_executor<OtherSupportableProperties...> other,
enable_if_t<
conditional_t<
!is_same<
any_executor<OtherSupportableProperties...>,
any_executor
>::value,
typename detail::supportable_properties<
0, void(SupportableProperties...)>::template is_valid_target<
any_executor<OtherSupportableProperties...>>,
false_type
>::value
>* = 0)
: detail::any_executor_base(
static_cast<any_executor<OtherSupportableProperties...>&&>(other),
true_type()),
prop_fns_(prop_fns_table<any_executor<OtherSupportableProperties...>>())
{
}
template <typename... OtherSupportableProperties>
any_executor(std::nothrow_t,
any_executor<OtherSupportableProperties...> other,
enable_if_t<
conditional_t<
!is_same<
any_executor<OtherSupportableProperties...>,
any_executor
>::value,
typename detail::supportable_properties<
0, void(SupportableProperties...)>::template is_valid_target<
any_executor<OtherSupportableProperties...>>,
false_type
>::value
>* = 0) noexcept
: detail::any_executor_base(std::nothrow,
static_cast<any_executor<OtherSupportableProperties...>&&>(other),
true_type()),
prop_fns_(prop_fns_table<any_executor<OtherSupportableProperties...>>())
{
if (this->template target<void>() == 0)
prop_fns_ = prop_fns_table<void>();
}
any_executor(const any_executor& other) noexcept
: detail::any_executor_base(
static_cast<const detail::any_executor_base&>(other)),
prop_fns_(other.prop_fns_)
{
}
any_executor(std::nothrow_t, const any_executor& other) noexcept
: detail::any_executor_base(
static_cast<const detail::any_executor_base&>(other)),
prop_fns_(other.prop_fns_)
{
}
any_executor& operator=(const any_executor& other) noexcept
{
if (this != &other)
{
prop_fns_ = other.prop_fns_;
detail::any_executor_base::operator=(
static_cast<const detail::any_executor_base&>(other));
}
return *this;
}
any_executor& operator=(nullptr_t p) noexcept
{
prop_fns_ = prop_fns_table<void>();
detail::any_executor_base::operator=(p);
return *this;
}
any_executor(any_executor&& other) noexcept
: detail::any_executor_base(
static_cast<any_executor_base&&>(
static_cast<any_executor_base&>(other))),
prop_fns_(other.prop_fns_)
{
other.prop_fns_ = prop_fns_table<void>();
}
any_executor(std::nothrow_t, any_executor&& other) noexcept
: detail::any_executor_base(
static_cast<any_executor_base&&>(
static_cast<any_executor_base&>(other))),
prop_fns_(other.prop_fns_)
{
other.prop_fns_ = prop_fns_table<void>();
}
any_executor& operator=(any_executor&& other) noexcept
{
if (this != &other)
{
prop_fns_ = other.prop_fns_;
detail::any_executor_base::operator=(
static_cast<detail::any_executor_base&&>(
static_cast<detail::any_executor_base&>(other)));
}
return *this;
}
void swap(any_executor& other) noexcept
{
if (this != &other)
{
detail::any_executor_base::swap(
static_cast<detail::any_executor_base&>(other));
const prop_fns<any_executor>* tmp_prop_fns = other.prop_fns_;
other.prop_fns_ = prop_fns_;
prop_fns_ = tmp_prop_fns;
}
}
using detail::any_executor_base::execute;
using detail::any_executor_base::target;
using detail::any_executor_base::target_type;
using detail::any_executor_base::operator unspecified_bool_type;
using detail::any_executor_base::operator!;
bool equality_helper(const any_executor& other) const noexcept
{
return any_executor_base::equality_helper(other);
}
template <typename AnyExecutor1, typename AnyExecutor2>
friend enable_if_t<
is_base_of<any_executor, AnyExecutor1>::value
|| is_base_of<any_executor, AnyExecutor2>::value,
bool
> operator==(const AnyExecutor1& a,
const AnyExecutor2& b) noexcept
{
return static_cast<const any_executor&>(a).equality_helper(b);
}
template <typename AnyExecutor>
friend enable_if_t<
is_same<AnyExecutor, any_executor>::value,
bool
> operator==(const AnyExecutor& a, nullptr_t) noexcept
{
return !a;
}
template <typename AnyExecutor>
friend enable_if_t<
is_same<AnyExecutor, any_executor>::value,
bool
> operator==(nullptr_t, const AnyExecutor& b) noexcept
{
return !b;
}
template <typename AnyExecutor1, typename AnyExecutor2>
friend enable_if_t<
is_base_of<any_executor, AnyExecutor1>::value
|| is_base_of<any_executor, AnyExecutor2>::value,
bool
> operator!=(const AnyExecutor1& a,
const AnyExecutor2& b) noexcept
{
return !static_cast<const any_executor&>(a).equality_helper(b);
}
template <typename AnyExecutor>
friend enable_if_t<
is_same<AnyExecutor, any_executor>::value,
bool
> operator!=(const AnyExecutor& a, nullptr_t) noexcept
{
return !!a;
}
template <typename AnyExecutor>
friend enable_if_t<
is_same<AnyExecutor, any_executor>::value,
bool
> operator!=(nullptr_t, const AnyExecutor& b) noexcept
{
return !!b;
}
template <typename T>
struct find_convertible_property :
detail::supportable_properties<
0, void(SupportableProperties...)>::template
find_convertible_property<T> {};
template <typename Property>
void query(const Property& p,
enable_if_t<
is_same<
typename find_convertible_property<Property>::query_result_type,
void
>::value
>* = 0) const
{
if (!target_)
{
bad_executor ex;
boost::asio::detail::throw_exception(ex);
}
typedef find_convertible_property<Property> found;
prop_fns_[found::index].query(0, object_fns_->target(*this),
&static_cast<const typename found::type&>(p));
}
template <typename Property>
typename find_convertible_property<Property>::query_result_type
query(const Property& p,
enable_if_t<
!is_same<
typename find_convertible_property<Property>::query_result_type,
void
>::value
&&
is_reference<
typename find_convertible_property<Property>::query_result_type
>::value
>* = 0) const
{
if (!target_)
{
bad_executor ex;
boost::asio::detail::throw_exception(ex);
}
typedef find_convertible_property<Property> found;
remove_reference_t<typename found::query_result_type>* result = 0;
prop_fns_[found::index].query(&result, object_fns_->target(*this),
&static_cast<const typename found::type&>(p));
return *result;
}
template <typename Property>
typename find_convertible_property<Property>::query_result_type
query(const Property& p,
enable_if_t<
!is_same<
typename find_convertible_property<Property>::query_result_type,
void
>::value
&&
is_scalar<
typename find_convertible_property<Property>::query_result_type
>::value
>* = 0) const
{
if (!target_)
{
bad_executor ex;
boost::asio::detail::throw_exception(ex);
}
typedef find_convertible_property<Property> found;
typename found::query_result_type result;
prop_fns_[found::index].query(&result, object_fns_->target(*this),
&static_cast<const typename found::type&>(p));
return result;
}
template <typename Property>
typename find_convertible_property<Property>::query_result_type
query(const Property& p,
enable_if_t<
!is_same<
typename find_convertible_property<Property>::query_result_type,
void
>::value
&&
!is_reference<
typename find_convertible_property<Property>::query_result_type
>::value
&&
!is_scalar<
typename find_convertible_property<Property>::query_result_type
>::value
>* = 0) const
{
if (!target_)
{
bad_executor ex;
boost::asio::detail::throw_exception(ex);
}
typedef find_convertible_property<Property> found;
typename found::query_result_type* result;
prop_fns_[found::index].query(&result, object_fns_->target(*this),
&static_cast<const typename found::type&>(p));
return *boost::asio::detail::scoped_ptr<
typename found::query_result_type>(result);
}
template <typename T>
struct find_convertible_requirable_property :
detail::supportable_properties<
0, void(SupportableProperties...)>::template
find_convertible_requirable_property<T> {};
template <typename Property>
any_executor require(const Property& p,
enable_if_t<
find_convertible_requirable_property<Property>::value
>* = 0) const
{
if (!target_)
{
bad_executor ex;
boost::asio::detail::throw_exception(ex);
}
typedef find_convertible_requirable_property<Property> found;
return prop_fns_[found::index].require(object_fns_->target(*this),
&static_cast<const typename found::type&>(p));
}
template <typename T>
struct find_convertible_preferable_property :
detail::supportable_properties<
0, void(SupportableProperties...)>::template
find_convertible_preferable_property<T> {};
template <typename Property>
any_executor prefer(const Property& p,
enable_if_t<
find_convertible_preferable_property<Property>::value
>* = 0) const
{
if (!target_)
{
bad_executor ex;
boost::asio::detail::throw_exception(ex);
}
typedef find_convertible_preferable_property<Property> found;
return prop_fns_[found::index].prefer(object_fns_->target(*this),
&static_cast<const typename found::type&>(p));
}
//private:
template <typename Ex>
static const prop_fns<any_executor>* prop_fns_table()
{
static const prop_fns<any_executor> fns[] =
{
{
&detail::any_executor_base::query_fn<
Ex, SupportableProperties>,
&detail::any_executor_base::require_fn<
any_executor, Ex, SupportableProperties>,
&detail::any_executor_base::prefer_fn<
any_executor, Ex, SupportableProperties>
}...
};
return fns;
}
const prop_fns<any_executor>* prop_fns_;
};
template <typename... SupportableProperties>
inline void swap(any_executor<SupportableProperties...>& a,
any_executor<SupportableProperties...>& b) noexcept
{
return a.swap(b);
}
} // namespace execution
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
template <typename... SupportableProperties>
struct equality_comparable<execution::any_executor<SupportableProperties...>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = true;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename F, typename... SupportableProperties>
struct execute_member<execution::any_executor<SupportableProperties...>, F>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef void result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
template <typename Prop, typename... SupportableProperties>
struct query_member<
execution::any_executor<SupportableProperties...>, Prop,
enable_if_t<
execution::detail::supportable_properties<
0, void(SupportableProperties...)>::template
find_convertible_property<Prop>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef typename execution::detail::supportable_properties<
0, void(SupportableProperties...)>::template
find_convertible_property<Prop>::query_result_type result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
template <typename Prop, typename... SupportableProperties>
struct require_member<
execution::any_executor<SupportableProperties...>, Prop,
enable_if_t<
execution::detail::supportable_properties<
0, void(SupportableProperties...)>::template
find_convertible_requirable_property<Prop>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef execution::any_executor<SupportableProperties...> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT)
template <typename Prop, typename... SupportableProperties>
struct prefer_member<
execution::any_executor<SupportableProperties...>, Prop,
enable_if_t<
execution::detail::supportable_properties<
0, void(SupportableProperties...)>::template
find_convertible_preferable_property<Prop>::value
>>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept = false;
typedef execution::any_executor<SupportableProperties...> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_ANY_EXECUTOR_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/execution/prefer_only.hpp | //
// execution/prefer_only.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_EXECUTION_PREFER_ONLY_HPP
#define BOOST_ASIO_EXECUTION_PREFER_ONLY_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/is_applicable_property.hpp>
#include <boost/asio/prefer.hpp>
#include <boost/asio/query.hpp>
#include <boost/asio/traits/static_query.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(GENERATING_DOCUMENTATION)
namespace execution {
/// A property adapter that is used with the polymorphic executor wrapper
/// to mark properties as preferable, but not requirable.
template <typename Property>
struct prefer_only
{
/// The prefer_only adapter applies to the same types as the nested property.
template <typename T>
static constexpr bool is_applicable_property_v =
is_applicable_property<T, Property>::value;
/// The context_t property cannot be required.
static constexpr bool is_requirable = false;
/// The context_t property can be preferred, it the underlying property can
/// be preferred.
/**
* @c true if @c Property::is_preferable is @c true, otherwise @c false.
*/
static constexpr bool is_preferable = automatically_determined;
/// The type returned by queries against an @c any_executor.
typedef typename Property::polymorphic_query_result_type
polymorphic_query_result_type;
};
} // namespace execution
#else // defined(GENERATING_DOCUMENTATION)
namespace execution {
namespace detail {
template <typename InnerProperty, typename = void>
struct prefer_only_is_preferable
{
static constexpr bool is_preferable = false;
};
template <typename InnerProperty>
struct prefer_only_is_preferable<InnerProperty,
enable_if_t<
InnerProperty::is_preferable
>
>
{
static constexpr bool is_preferable = true;
};
template <typename InnerProperty, typename = void>
struct prefer_only_polymorphic_query_result_type
{
};
template <typename InnerProperty>
struct prefer_only_polymorphic_query_result_type<InnerProperty,
void_t<
typename InnerProperty::polymorphic_query_result_type
>
>
{
typedef typename InnerProperty::polymorphic_query_result_type
polymorphic_query_result_type;
};
template <typename InnerProperty, typename = void>
struct prefer_only_property
{
InnerProperty property;
prefer_only_property(const InnerProperty& p)
: property(p)
{
}
};
#if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
template <typename InnerProperty>
struct prefer_only_property<InnerProperty,
void_t<
decltype(boost::asio::declval<const InnerProperty>().value())
>
>
{
InnerProperty property;
prefer_only_property(const InnerProperty& p)
: property(p)
{
}
constexpr auto value() const
noexcept(noexcept(boost::asio::declval<const InnerProperty>().value()))
-> decltype(boost::asio::declval<const InnerProperty>().value())
{
return property.value();
}
};
#else // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
struct prefer_only_memfns_base
{
void value();
};
template <typename T>
struct prefer_only_memfns_derived
: T, prefer_only_memfns_base
{
};
template <typename T, T>
struct prefer_only_memfns_check
{
};
template <typename>
char (&prefer_only_value_memfn_helper(...))[2];
template <typename T>
char prefer_only_value_memfn_helper(
prefer_only_memfns_check<
void (prefer_only_memfns_base::*)(),
&prefer_only_memfns_derived<T>::value>*);
template <typename InnerProperty>
struct prefer_only_property<InnerProperty,
enable_if_t<
sizeof(prefer_only_value_memfn_helper<InnerProperty>(0)) != 1
&& !is_same<typename InnerProperty::polymorphic_query_result_type,
void>::value
>
>
{
InnerProperty property;
prefer_only_property(const InnerProperty& p)
: property(p)
{
}
constexpr typename InnerProperty::polymorphic_query_result_type
value() const
{
return property.value();
}
};
#endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
} // namespace detail
template <typename InnerProperty>
struct prefer_only :
detail::prefer_only_is_preferable<InnerProperty>,
detail::prefer_only_polymorphic_query_result_type<InnerProperty>,
detail::prefer_only_property<InnerProperty>
{
static constexpr bool is_requirable = false;
constexpr prefer_only(const InnerProperty& p)
: detail::prefer_only_property<InnerProperty>(p)
{
}
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static constexpr
typename traits::static_query<T, InnerProperty>::result_type
static_query()
noexcept(traits::static_query<T, InnerProperty>::is_noexcept)
{
return traits::static_query<T, InnerProperty>::value();
}
template <typename E, typename T = decltype(prefer_only::static_query<E>())>
static constexpr const T static_query_v
= prefer_only::static_query<E>();
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename Executor, typename Property>
friend constexpr
prefer_result_t<const Executor&, const InnerProperty&>
prefer(const Executor& ex, const prefer_only<Property>& p,
enable_if_t<
is_same<Property, InnerProperty>::value
>* = 0,
enable_if_t<
can_prefer<const Executor&, const InnerProperty&>::value
>* = 0)
#if !defined(BOOST_ASIO_MSVC) \
&& !defined(__clang__) // Clang crashes if noexcept is used here.
noexcept(is_nothrow_prefer<const Executor&, const InnerProperty&>::value)
#endif // !defined(BOOST_ASIO_MSVC)
// && !defined(__clang__)
{
return boost::asio::prefer(ex, p.property);
}
template <typename Executor, typename Property>
friend constexpr
query_result_t<const Executor&, const InnerProperty&>
query(const Executor& ex, const prefer_only<Property>& p,
enable_if_t<
is_same<Property, InnerProperty>::value
>* = 0,
enable_if_t<
can_query<const Executor&, const InnerProperty&>::value
>* = 0)
#if !defined(BOOST_ASIO_MSVC) \
&& !defined(__clang__) // Clang crashes if noexcept is used here.
noexcept(is_nothrow_query<const Executor&, const InnerProperty&>::value)
#endif // !defined(BOOST_ASIO_MSVC)
// && !defined(__clang__)
{
return boost::asio::query(ex, p.property);
}
};
#if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename InnerProperty> template <typename E, typename T>
const T prefer_only<InnerProperty>::static_query_v;
#endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
} // namespace execution
template <typename T, typename InnerProperty>
struct is_applicable_property<T, execution::prefer_only<InnerProperty>>
: is_applicable_property<T, InnerProperty>
{
};
namespace traits {
#if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
|| !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T, typename InnerProperty>
struct static_query<T, execution::prefer_only<InnerProperty>> :
static_query<T, const InnerProperty&>
{
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
#if !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT)
template <typename T, typename InnerProperty>
struct prefer_free_default<T, execution::prefer_only<InnerProperty>,
enable_if_t<
can_prefer<const T&, const InnerProperty&>::value
>
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_prefer<const T&, const InnerProperty&>::value;
typedef prefer_result_t<const T&, const InnerProperty&> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_FREE_TRAIT)
#if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
template <typename T, typename InnerProperty>
struct query_free<T, execution::prefer_only<InnerProperty>,
enable_if_t<
can_query<const T&, const InnerProperty&>::value
>
>
{
static constexpr bool is_valid = true;
static constexpr bool is_noexcept =
is_nothrow_query<const T&, const InnerProperty&>::value;
typedef query_result_t<const T&, const InnerProperty&> result_type;
};
#endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
} // namespace traits
#endif // defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_EXECUTION_PREFER_ONLY_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/traits/query_member.hpp | //
// traits/query_member.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_TRAITS_QUERY_MEMBER_HPP
#define BOOST_ASIO_TRAITS_QUERY_MEMBER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
# define BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT 1
#endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace traits {
template <typename T, typename Property, typename = void>
struct query_member_default;
template <typename T, typename Property, typename = void>
struct query_member;
} // namespace traits
namespace detail {
struct no_query_member
{
static constexpr bool is_valid = false;
static constexpr bool is_noexcept = false;
};
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
template <typename T, typename Property, typename = void>
struct query_member_trait : no_query_member
{
};
template <typename T, typename Property>
struct query_member_trait<T, Property,
void_t<
decltype(declval<T>().query(declval<Property>()))
>>
{
static constexpr bool is_valid = true;
using result_type = decltype(
declval<T>().query(declval<Property>()));
static constexpr bool is_noexcept =
noexcept(declval<T>().query(declval<Property>()));
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
template <typename T, typename Property, typename = void>
struct query_member_trait :
conditional_t<
is_same<T, decay_t<T>>::value
&& is_same<Property, decay_t<Property>>::value,
no_query_member,
traits::query_member<
decay_t<T>,
decay_t<Property>>
>
{
};
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
} // namespace detail
namespace traits {
template <typename T, typename Property, typename>
struct query_member_default :
detail::query_member_trait<T, Property>
{
};
template <typename T, typename Property, typename>
struct query_member :
query_member_default<T, Property>
{
};
} // namespace traits
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_TRAITS_QUERY_MEMBER_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/traits/query_free.hpp | //
// traits/query_free.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_TRAITS_QUERY_FREE_HPP
#define BOOST_ASIO_TRAITS_QUERY_FREE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
# define BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT 1
#endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace traits {
template <typename T, typename Property, typename = void>
struct query_free_default;
template <typename T, typename Property, typename = void>
struct query_free;
} // namespace traits
namespace detail {
struct no_query_free
{
static constexpr bool is_valid = false;
static constexpr bool is_noexcept = false;
};
#if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
template <typename T, typename Property, typename = void>
struct query_free_trait : no_query_free
{
};
template <typename T, typename Property>
struct query_free_trait<T, Property,
void_t<
decltype(query(declval<T>(), declval<Property>()))
>>
{
static constexpr bool is_valid = true;
using result_type = decltype(
query(declval<T>(), declval<Property>()));
static constexpr bool is_noexcept =
noexcept(query(declval<T>(), declval<Property>()));
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
template <typename T, typename Property, typename = void>
struct query_free_trait :
conditional_t<
is_same<T, decay_t<T>>::value
&& is_same<Property, decay_t<Property>>::value,
no_query_free,
traits::query_free<
decay_t<T>,
decay_t<Property>>
>
{
};
#endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
} // namespace detail
namespace traits {
template <typename T, typename Property, typename>
struct query_free_default :
detail::query_free_trait<T, Property>
{
};
template <typename T, typename Property, typename>
struct query_free :
query_free_default<T, Property>
{
};
} // namespace traits
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_TRAITS_QUERY_FREE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/traits/static_require_concept.hpp | //
// traits/static_require_concept.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_TRAITS_STATIC_REQUIRE_CONCEPT_HPP
#define BOOST_ASIO_TRAITS_STATIC_REQUIRE_CONCEPT_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/traits/static_query.hpp>
#define BOOST_ASIO_HAS_DEDUCED_STATIC_REQUIRE_CONCEPT_TRAIT 1
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace traits {
template <typename T, typename Property, typename = void>
struct static_require_concept_default;
template <typename T, typename Property, typename = void>
struct static_require_concept;
} // namespace traits
namespace detail {
struct no_static_require_concept
{
static constexpr bool is_valid = false;
};
template <typename T, typename Property, typename = void>
struct static_require_concept_trait :
conditional_t<
is_same<T, decay_t<T>>::value
&& is_same<Property, decay_t<Property>>::value,
no_static_require_concept,
traits::static_require_concept<
decay_t<T>,
decay_t<Property>>
>
{
};
#if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
template <typename T, typename Property>
struct static_require_concept_trait<T, Property,
enable_if_t<
decay_t<Property>::value() == traits::static_query<T, Property>::value()
>>
{
static constexpr bool is_valid = true;
};
#else // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
false_type static_require_concept_test(...);
template <typename T, typename Property>
true_type static_require_concept_test(T*, Property*,
enable_if_t<
Property::value() == traits::static_query<T, Property>::value()
>* = 0);
template <typename T, typename Property>
struct has_static_require_concept
{
static constexpr bool value =
decltype((static_require_concept_test)(
static_cast<T*>(0), static_cast<Property*>(0)))::value;
};
template <typename T, typename Property>
struct static_require_concept_trait<T, Property,
enable_if_t<
has_static_require_concept<decay_t<T>,
decay_t<Property>>::value
>>
{
static constexpr bool is_valid = true;
};
#endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
} // namespace detail
namespace traits {
template <typename T, typename Property, typename>
struct static_require_concept_default :
detail::static_require_concept_trait<T, Property>
{
};
template <typename T, typename Property, typename>
struct static_require_concept : static_require_concept_default<T, Property>
{
};
} // namespace traits
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_TRAITS_STATIC_REQUIRE_CONCEPT_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/traits/require_concept_free.hpp | //
// traits/require_concept_free.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_TRAITS_REQUIRE_CONCEPT_FREE_HPP
#define BOOST_ASIO_TRAITS_REQUIRE_CONCEPT_FREE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
# define BOOST_ASIO_HAS_DEDUCED_REQUIRE_CONCEPT_FREE_TRAIT 1
#endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace traits {
template <typename T, typename Property, typename = void>
struct require_concept_free_default;
template <typename T, typename Property, typename = void>
struct require_concept_free;
} // namespace traits
namespace detail {
struct no_require_concept_free
{
static constexpr bool is_valid = false;
static constexpr bool is_noexcept = false;
};
#if defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_CONCEPT_FREE_TRAIT)
template <typename T, typename Property, typename = void>
struct require_concept_free_trait : no_require_concept_free
{
};
template <typename T, typename Property>
struct require_concept_free_trait<T, Property,
void_t<
decltype(require_concept(declval<T>(), declval<Property>()))
>>
{
static constexpr bool is_valid = true;
using result_type = decltype(
require_concept(declval<T>(), declval<Property>()));
static constexpr bool is_noexcept =
noexcept(require_concept(declval<T>(), declval<Property>()));
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_CONCEPT_FREE_TRAIT)
template <typename T, typename Property, typename = void>
struct require_concept_free_trait :
conditional_t<
is_same<T, decay_t<T>>::value
&& is_same<Property, decay_t<Property>>::value,
no_require_concept_free,
traits::require_concept_free<
decay_t<T>,
decay_t<Property>>
>
{
};
#endif // defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_CONCEPT_FREE_TRAIT)
} // namespace detail
namespace traits {
template <typename T, typename Property, typename>
struct require_concept_free_default :
detail::require_concept_free_trait<T, Property>
{
};
template <typename T, typename Property, typename>
struct require_concept_free :
require_concept_free_default<T, Property>
{
};
} // namespace traits
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_TRAITS_REQUIRE_CONCEPT_FREE_HPP
| hpp |
asio | data/projects/asio/include/boost/asio/traits/execute_member.hpp | //
// traits/execute_member.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 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)
//
#ifndef BOOST_ASIO_TRAITS_EXECUTE_MEMBER_HPP
#define BOOST_ASIO_TRAITS_EXECUTE_MEMBER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/type_traits.hpp>
#if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
# define BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT 1
#endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace traits {
template <typename T, typename F, typename = void>
struct execute_member_default;
template <typename T, typename F, typename = void>
struct execute_member;
} // namespace traits
namespace detail {
struct no_execute_member
{
static constexpr bool is_valid = false;
static constexpr bool is_noexcept = false;
};
#if defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename T, typename F, typename = void>
struct execute_member_trait : no_execute_member
{
};
template <typename T, typename F>
struct execute_member_trait<T, F,
void_t<
decltype(declval<T>().execute(declval<F>()))
>>
{
static constexpr bool is_valid = true;
using result_type = decltype(
declval<T>().execute(declval<F>()));
static constexpr bool is_noexcept =
noexcept(declval<T>().execute(declval<F>()));
};
#else // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
template <typename T, typename F, typename = void>
struct execute_member_trait :
conditional_t<
is_same<T, decay_t<T>>::value
&& is_same<F, decay_t<F>>::value,
no_execute_member,
traits::execute_member<
decay_t<T>,
decay_t<F>>
>
{
};
#endif // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
} // namespace detail
namespace traits {
template <typename T, typename F, typename>
struct execute_member_default :
detail::execute_member_trait<T, F>
{
};
template <typename T, typename F, typename>
struct execute_member :
execute_member_default<T, F>
{
};
} // namespace traits
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_TRAITS_EXECUTE_MEMBER_HPP
| hpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.