early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,131 @@
//
// impl/any_io_executor.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_ANY_IO_EXECUTOR_IPP
#define BOOST_ASIO_IMPL_ANY_IO_EXECUTOR_IPP
#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_USE_TS_EXECUTOR_AS_DEFAULT)
#include <boost/asio/any_io_executor.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
any_io_executor::any_io_executor() BOOST_ASIO_NOEXCEPT
: base_type()
{
}
any_io_executor::any_io_executor(nullptr_t) BOOST_ASIO_NOEXCEPT
: base_type(nullptr_t())
{
}
any_io_executor::any_io_executor(const any_io_executor& e) BOOST_ASIO_NOEXCEPT
: base_type(static_cast<const base_type&>(e))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
any_io_executor::any_io_executor(any_io_executor&& e) BOOST_ASIO_NOEXCEPT
: base_type(static_cast<base_type&&>(e))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
any_io_executor& any_io_executor::operator=(
const any_io_executor& e) BOOST_ASIO_NOEXCEPT
{
base_type::operator=(static_cast<const base_type&>(e));
return *this;
}
#if defined(BOOST_ASIO_HAS_MOVE)
any_io_executor& any_io_executor::operator=(
any_io_executor&& e) BOOST_ASIO_NOEXCEPT
{
base_type::operator=(static_cast<base_type&&>(e));
return *this;
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
any_io_executor& any_io_executor::operator=(nullptr_t)
{
base_type::operator=(nullptr_t());
return *this;
}
any_io_executor::~any_io_executor()
{
}
void any_io_executor::swap(any_io_executor& other) BOOST_ASIO_NOEXCEPT
{
static_cast<base_type&>(*this).swap(static_cast<base_type&>(other));
}
template <>
any_io_executor any_io_executor::require(
const execution::blocking_t::never_t& p, int) const
{
return static_cast<const base_type&>(*this).require(p);
}
template <>
any_io_executor any_io_executor::prefer(
const execution::blocking_t::possibly_t& p, int) const
{
return static_cast<const base_type&>(*this).prefer(p);
}
template <>
any_io_executor any_io_executor::prefer(
const execution::outstanding_work_t::tracked_t& p, int) const
{
return static_cast<const base_type&>(*this).prefer(p);
}
template <>
any_io_executor any_io_executor::prefer(
const execution::outstanding_work_t::untracked_t& p, int) const
{
return static_cast<const base_type&>(*this).prefer(p);
}
template <>
any_io_executor any_io_executor::prefer(
const execution::relationship_t::fork_t& p, int) const
{
return static_cast<const base_type&>(*this).prefer(p);
}
template <>
any_io_executor any_io_executor::prefer(
const execution::relationship_t::continuation_t& p, int) const
{
return static_cast<const base_type&>(*this).prefer(p);
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
#endif // BOOST_ASIO_IMPL_ANY_IO_EXECUTOR_IPP

View File

@@ -0,0 +1,761 @@
//
// impl/awaitable.hpp
// ~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
struct awaitable_thread_has_context_switched {};
// 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())
do_throw_error(boost::asio::error::operation_aborted, "co_await");
return a;
}
// 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(
BOOST_ASIO_MOVE_CAST(Filter)(filter_));
}
};
return result{this, BOOST_ASIO_MOVE_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(
BOOST_ASIO_MOVE_CAST(InFilter)(in_filter_),
BOOST_ASIO_MOVE_CAST(OutFilter)(out_filter_));
}
};
return result{this,
BOOST_ASIO_MOVE_CAST(InFilter)(reset.in_filter),
BOOST_ASIO_MOVE_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,
typename enable_if<
is_convertible<
typename result_of<Function(awaitable_frame_base*)>::type,
awaitable_thread<Executor>*
>::value
>::type* = nullptr)
{
struct result
{
Function function_;
awaitable_frame_base* this_;
bool await_ready() const noexcept
{
return false;
}
void await_suspend(coroutine_handle<void>) noexcept
{
function_(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;
}
void resume()
{
coro_.resume();
}
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;
};
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_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(BOOST_ASIO_MOVE_ARG(Filter) filter)
{
bottom_of_stack_.frame_->cancellation_state_ =
cancellation_state(bottom_of_stack_.frame_->parent_cancellation_slot_,
BOOST_ASIO_MOVE_CAST(Filter)(filter));
}
template <typename InFilter, typename OutFilter>
void reset_cancellation_state(BOOST_ASIO_MOVE_ARG(InFilter) in_filter,
BOOST_ASIO_MOVE_ARG(OutFilter) out_filter)
{
bottom_of_stack_.frame_->cancellation_state_ =
cancellation_state(bottom_of_stack_.frame_->parent_cancellation_slot_,
BOOST_ASIO_MOVE_CAST(InFilter)(in_filter),
BOOST_ASIO_MOVE_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_;
};
} // 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

View File

@@ -0,0 +1,500 @@
//
// impl/buffered_read_stream.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_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_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
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_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
const std::size_t bytes_transferred)
{
storage_.resize(previous_size_ + bytes_transferred);
BOOST_ASIO_MOVE_OR_LVALUE(ReadHandler)(handler_)(ec, bytes_transferred);
}
//private:
detail::buffered_stream_storage& storage_;
std::size_t previous_size_;
ReadHandler handler_;
};
template <typename ReadHandler>
inline asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
buffered_fill_handler<ReadHandler>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename ReadHandler>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
buffered_fill_handler<ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 Function, typename ReadHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
buffered_fill_handler<ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename ReadHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
buffered_fill_handler<ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Stream>
class initiate_async_buffered_fill
{
public:
typedef typename remove_reference<
Stream>::type::lowest_layer_type::executor_type executor_type;
explicit initiate_async_buffered_fill(
typename remove_reference<Stream>::type& next_layer)
: next_layer_(next_layer)
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return next_layer_.lowest_layer().get_executor();
}
template <typename ReadHandler>
void operator()(BOOST_ASIO_MOVE_ARG(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<typename decay<ReadHandler>::type>(
*storage, previous_size, handler2.value));
}
private:
typename remove_reference<Stream>::type& 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,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
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>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
buffered_read_stream<Stream>::async_fill(
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
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_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
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_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec, std::size_t)
{
if (ec || storage_.empty())
{
const std::size_t length = 0;
BOOST_ASIO_MOVE_OR_LVALUE(ReadHandler)(handler_)(ec, length);
}
else
{
const std::size_t bytes_copied = boost::asio::buffer_copy(
buffers_, storage_.data(), storage_.size());
storage_.consume(bytes_copied);
BOOST_ASIO_MOVE_OR_LVALUE(ReadHandler)(handler_)(ec, bytes_copied);
}
}
//private:
detail::buffered_stream_storage& storage_;
MutableBufferSequence buffers_;
ReadHandler handler_;
};
template <typename MutableBufferSequence, typename ReadHandler>
inline asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
buffered_read_some_handler<
MutableBufferSequence, ReadHandler>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename MutableBufferSequence, typename ReadHandler>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
buffered_read_some_handler<
MutableBufferSequence, ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 Function, typename MutableBufferSequence,
typename ReadHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
buffered_read_some_handler<
MutableBufferSequence, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename MutableBufferSequence,
typename ReadHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
buffered_read_some_handler<
MutableBufferSequence, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Stream>
class initiate_async_buffered_read_some
{
public:
typedef typename remove_reference<
Stream>::type::lowest_layer_type::executor_type executor_type;
explicit initiate_async_buffered_read_some(
typename remove_reference<Stream>::type& next_layer)
: next_layer_(next_layer)
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return next_layer_.lowest_layer().get_executor();
}
template <typename ReadHandler, typename MutableBufferSequence>
void operator()(BOOST_ASIO_MOVE_ARG(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,
typename decay<ReadHandler>::type>(
*storage, buffers, handler2.value));
}
else
{
initiate_async_buffered_fill<Stream>(this->next_layer_)(
buffered_read_some_handler<MutableBufferSequence,
typename decay<ReadHandler>::type>(
*storage, buffers, handler2.value),
storage);
}
}
private:
typename remove_reference<Stream>::type& 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,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
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>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
buffered_read_stream<Stream>::async_read_some(
const MutableBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
{
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

View File

@@ -0,0 +1,480 @@
//
// impl/buffered_write_stream.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_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_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
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_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
const std::size_t bytes_written)
{
storage_.consume(bytes_written);
BOOST_ASIO_MOVE_OR_LVALUE(WriteHandler)(handler_)(ec, bytes_written);
}
//private:
detail::buffered_stream_storage& storage_;
WriteHandler handler_;
};
template <typename WriteHandler>
inline asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
buffered_flush_handler<WriteHandler>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename WriteHandler>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
buffered_flush_handler<WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 Function, typename WriteHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
buffered_flush_handler<WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename WriteHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
buffered_flush_handler<WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Stream>
class initiate_async_buffered_flush
{
public:
typedef typename remove_reference<
Stream>::type::lowest_layer_type::executor_type executor_type;
explicit initiate_async_buffered_flush(
typename remove_reference<Stream>::type& next_layer)
: next_layer_(next_layer)
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return next_layer_.lowest_layer().get_executor();
}
template <typename WriteHandler>
void operator()(BOOST_ASIO_MOVE_ARG(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<typename decay<WriteHandler>::type>(
*storage, handler2.value));
}
private:
typename remove_reference<Stream>::type& 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,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
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>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
buffered_write_stream<Stream>::async_flush(
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
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_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
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_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec, std::size_t)
{
if (ec)
{
const std::size_t length = 0;
BOOST_ASIO_MOVE_OR_LVALUE(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);
BOOST_ASIO_MOVE_OR_LVALUE(WriteHandler)(handler_)(ec, bytes_copied);
}
}
//private:
detail::buffered_stream_storage& storage_;
ConstBufferSequence buffers_;
WriteHandler handler_;
};
template <typename ConstBufferSequence, typename WriteHandler>
inline asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
buffered_write_some_handler<
ConstBufferSequence, WriteHandler>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename ConstBufferSequence, typename WriteHandler>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
buffered_write_some_handler<
ConstBufferSequence, WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 Function, typename ConstBufferSequence,
typename WriteHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
buffered_write_some_handler<
ConstBufferSequence, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename ConstBufferSequence,
typename WriteHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
buffered_write_some_handler<
ConstBufferSequence, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Stream>
class initiate_async_buffered_write_some
{
public:
typedef typename remove_reference<
Stream>::type::lowest_layer_type::executor_type executor_type;
explicit initiate_async_buffered_write_some(
typename remove_reference<Stream>::type& next_layer)
: next_layer_(next_layer)
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return next_layer_.lowest_layer().get_executor();
}
template <typename WriteHandler, typename ConstBufferSequence>
void operator()(BOOST_ASIO_MOVE_ARG(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,
typename decay<WriteHandler>::type>(
*storage, buffers, handler2.value));
}
else
{
initiate_async_buffered_flush<Stream>(this->next_layer_)(
buffered_write_some_handler<ConstBufferSequence,
typename decay<WriteHandler>::type>(
*storage, buffers, handler2.value),
storage);
}
}
private:
typename remove_reference<Stream>::type& 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,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
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>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
buffered_write_stream<Stream>::async_write_some(
const ConstBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
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

View File

@@ -0,0 +1,98 @@
//
// impl/cancellation_signal.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_CANCELLATION_SIGNAL_IPP
#define BOOST_ASIO_IMPL_CANCELLATION_SIGNAL_IPP
#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/cancellation_signal.hpp>
#include <boost/asio/detail/thread_context.hpp>
#include <boost/asio/detail/thread_info_base.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
cancellation_signal::~cancellation_signal()
{
if (handler_)
{
std::pair<void*, std::size_t> mem = handler_->destroy();
detail::thread_info_base::deallocate(
detail::thread_info_base::cancellation_signal_tag(),
detail::thread_context::top_of_thread_call_stack(),
mem.first, mem.second);
}
}
void cancellation_slot::clear()
{
if (handler_ != 0 && *handler_ != 0)
{
std::pair<void*, std::size_t> mem = (*handler_)->destroy();
detail::thread_info_base::deallocate(
detail::thread_info_base::cancellation_signal_tag(),
detail::thread_context::top_of_thread_call_stack(),
mem.first, mem.second);
*handler_ = 0;
}
}
std::pair<void*, std::size_t> cancellation_slot::prepare_memory(
std::size_t size, std::size_t align)
{
assert(handler_);
std::pair<void*, std::size_t> mem;
if (*handler_)
{
mem = (*handler_)->destroy();
*handler_ = 0;
}
if (size > mem.second
|| reinterpret_cast<std::size_t>(mem.first) % align != 0)
{
if (mem.first)
{
detail::thread_info_base::deallocate(
detail::thread_info_base::cancellation_signal_tag(),
detail::thread_context::top_of_thread_call_stack(),
mem.first, mem.second);
}
mem.first = detail::thread_info_base::allocate(
detail::thread_info_base::cancellation_signal_tag(),
detail::thread_context::top_of_thread_call_stack(),
size, align);
mem.second = size;
}
return mem;
}
cancellation_slot::auto_delete_helper::~auto_delete_helper()
{
if (mem.first)
{
detail::thread_info_base::deallocate(
detail::thread_info_base::cancellation_signal_tag(),
detail::thread_context::top_of_thread_call_stack(),
mem.first, mem.second);
}
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_CANCELLATION_SIGNAL_IPP

View File

@@ -0,0 +1,348 @@
//
// impl/co_spawn.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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/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 typename decay<
typename prefer_result<Executor,
execution::outstanding_work_t::tracked_t
>::type
>::type executor_type;
co_spawn_work_guard(const Executor& ex)
: executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked))
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return executor_;
}
private:
executor_type executor_;
};
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Executor>
struct co_spawn_work_guard<Executor,
typename enable_if<
!execution::is_executor<Executor>::value
>::type> : 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 Executor>
inline co_spawn_work_guard<Executor>
make_co_spawn_work_guard(const Executor& ex)
{
return co_spawn_work_guard<Executor>(ex);
}
template <typename T, typename Executor, typename F, typename Handler>
awaitable<awaitable_thread_entry_point, Executor> co_spawn_entry_point(
awaitable<T, Executor>*, Executor ex, F f, Handler handler)
{
auto spawn_work = make_co_spawn_work_guard(ex);
auto handler_work = make_co_spawn_work_guard(
boost::asio::get_associated_executor(handler, ex));
(void) co_await (dispatch)(
use_awaitable_t<Executor>{__FILE__, __LINE__, "co_spawn_entry_point"});
(co_await awaitable_thread_has_context_switched{}) = false;
std::exception_ptr e = nullptr;
bool done = false;
try
{
T t = co_await f();
done = true;
if (co_await awaitable_thread_has_context_switched{})
{
(dispatch)(handler_work.get_executor(),
[handler = std::move(handler), t = std::move(t)]() mutable
{
std::move(handler)(std::exception_ptr(), std::move(t));
});
}
else
{
(post)(handler_work.get_executor(),
[handler = std::move(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();
}
if (co_await awaitable_thread_has_context_switched{})
{
(dispatch)(handler_work.get_executor(),
[handler = std::move(handler), e]() mutable
{
std::move(handler)(e, T());
});
}
else
{
(post)(handler_work.get_executor(),
[handler = std::move(handler), e]() mutable
{
std::move(handler)(e, T());
});
}
}
template <typename Executor, typename F, typename Handler>
awaitable<awaitable_thread_entry_point, Executor> co_spawn_entry_point(
awaitable<void, Executor>*, Executor ex, F f, Handler handler)
{
auto spawn_work = make_co_spawn_work_guard(ex);
auto handler_work = make_co_spawn_work_guard(
boost::asio::get_associated_executor(handler, ex));
(void) co_await (dispatch)(
use_awaitable_t<Executor>{__FILE__, __LINE__, "co_spawn_entry_point"});
(co_await awaitable_thread_has_context_switched{}) = false;
std::exception_ptr e = nullptr;
try
{
co_await f();
}
catch (...)
{
e = std::current_exception();
}
if (co_await awaitable_thread_has_context_switched{})
{
(dispatch)(handler_work.get_executor(),
[handler = std::move(handler), e]() mutable
{
std::move(handler)(e);
});
}
else
{
(post)(handler_work.get_executor(),
[handler = std::move(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 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 BOOST_ASIO_NOEXCEPT
{
return ex_;
}
template <typename Handler, typename F>
void operator()(Handler&& handler, F&& f) const
{
typedef typename result_of<F()>::type awaitable_type;
cancellation_state proxy_cancel_state(
boost::asio::get_associated_cancellation_slot(handler),
enable_total_cancellation());
cancellation_state cancel_state(proxy_cancel_state.slot());
auto a = (co_spawn_entry_point)(static_cast<awaitable_type*>(nullptr),
ex_, std::forward<F>(f), std::forward<Handler>(handler));
awaitable_handler<executor_type, void>(std::move(a), ex_,
proxy_cancel_state.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,
typename constraint<
(is_executor<Executor>::value || execution::is_executor<Executor>::value)
&& is_convertible<Executor, AwaitableExecutor>::value
>::type)
{
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,
typename constraint<
(is_executor<Executor>::value || execution::is_executor<Executor>::value)
&& is_convertible<Executor, AwaitableExecutor>::value
>::type)
{
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,
typename constraint<
is_convertible<ExecutionContext&, execution_context&>::value
&& is_convertible<typename ExecutionContext::executor_type,
AwaitableExecutor>::value
>::type)
{
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,
typename constraint<
is_convertible<ExecutionContext&, execution_context&>::value
&& is_convertible<typename ExecutionContext::executor_type,
AwaitableExecutor>::value
>::type)
{
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<
typename result_of<F()>::type>::type) CompletionToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
typename detail::awaitable_signature<typename result_of<F()>::type>::type)
co_spawn(const Executor& ex, F&& f, CompletionToken&& token,
typename constraint<
is_executor<Executor>::value || execution::is_executor<Executor>::value
>::type)
{
return async_initiate<CompletionToken,
typename detail::awaitable_signature<typename result_of<F()>::type>::type>(
detail::initiate_co_spawn<
typename result_of<F()>::type::executor_type>(ex),
token, std::forward<F>(f));
}
template <typename ExecutionContext, typename F,
BOOST_ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
typename result_of<F()>::type>::type) CompletionToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken,
typename detail::awaitable_signature<typename result_of<F()>::type>::type)
co_spawn(ExecutionContext& ctx, F&& f, CompletionToken&& token,
typename constraint<
is_convertible<ExecutionContext&, execution_context&>::value
>::type)
{
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

View File

@@ -0,0 +1,709 @@
//
// impl/compose.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_COMPOSE_HPP
#define BOOST_ASIO_IMPL_COMPOSE_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_executor.hpp>
#include <boost/asio/detail/base_from_cancellation_state.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/variadic_templates.hpp>
#include <boost/asio/execution/executor.hpp>
#include <boost/asio/execution/outstanding_work.hpp>
#include <boost/asio/executor_work_guard.hpp>
#include <boost/asio/is_executor.hpp>
#include <boost/asio/system_executor.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail
{
template <typename Executor, typename = void>
class composed_work_guard
{
public:
typedef typename decay<
typename prefer_result<Executor,
execution::outstanding_work_t::tracked_t
>::type
>::type executor_type;
composed_work_guard(const Executor& ex)
: executor_(boost::asio::prefer(ex, execution::outstanding_work.tracked))
{
}
void reset()
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return executor_;
}
private:
executor_type executor_;
};
template <>
struct composed_work_guard<system_executor>
{
public:
typedef system_executor executor_type;
composed_work_guard(const system_executor&)
{
}
void reset()
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return system_executor();
}
};
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Executor>
struct composed_work_guard<Executor,
typename enable_if<
!execution::is_executor<Executor>::value
>::type> : executor_work_guard<Executor>
{
composed_work_guard(const Executor& ex)
: executor_work_guard<Executor>(ex)
{
}
};
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename>
struct composed_io_executors;
template <>
struct composed_io_executors<void()>
{
composed_io_executors() BOOST_ASIO_NOEXCEPT
: head_(system_executor())
{
}
typedef system_executor head_type;
system_executor head_;
};
inline composed_io_executors<void()> make_composed_io_executors()
{
return composed_io_executors<void()>();
}
template <typename Head>
struct composed_io_executors<void(Head)>
{
explicit composed_io_executors(const Head& ex) BOOST_ASIO_NOEXCEPT
: head_(ex)
{
}
typedef Head head_type;
Head head_;
};
template <typename Head>
inline composed_io_executors<void(Head)>
make_composed_io_executors(const Head& head)
{
return composed_io_executors<void(Head)>(head);
}
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Head, typename... Tail>
struct composed_io_executors<void(Head, Tail...)>
{
explicit composed_io_executors(const Head& head,
const Tail&... tail) BOOST_ASIO_NOEXCEPT
: head_(head),
tail_(tail...)
{
}
void reset()
{
head_.reset();
tail_.reset();
}
typedef Head head_type;
Head head_;
composed_io_executors<void(Tail...)> tail_;
};
template <typename Head, typename... Tail>
inline composed_io_executors<void(Head, Tail...)>
make_composed_io_executors(const Head& head, const Tail&... tail)
{
return composed_io_executors<void(Head, Tail...)>(head, tail...);
}
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
#define BOOST_ASIO_PRIVATE_COMPOSED_IO_EXECUTORS_DEF(n) \
template <typename Head, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct composed_io_executors<void(Head, BOOST_ASIO_VARIADIC_TARGS(n))> \
{ \
explicit composed_io_executors(const Head& head, \
BOOST_ASIO_VARIADIC_CONSTREF_PARAMS(n)) BOOST_ASIO_NOEXCEPT \
: head_(head), \
tail_(BOOST_ASIO_VARIADIC_BYVAL_ARGS(n)) \
{ \
} \
\
void reset() \
{ \
head_.reset(); \
tail_.reset(); \
} \
\
typedef Head head_type; \
Head head_; \
composed_io_executors<void(BOOST_ASIO_VARIADIC_TARGS(n))> tail_; \
}; \
\
template <typename Head, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
inline composed_io_executors<void(Head, BOOST_ASIO_VARIADIC_TARGS(n))> \
make_composed_io_executors(const Head& head, \
BOOST_ASIO_VARIADIC_CONSTREF_PARAMS(n)) \
{ \
return composed_io_executors< \
void(Head, BOOST_ASIO_VARIADIC_TARGS(n))>( \
head, BOOST_ASIO_VARIADIC_BYVAL_ARGS(n)); \
} \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_COMPOSED_IO_EXECUTORS_DEF)
#undef BOOST_ASIO_PRIVATE_COMPOSED_IO_EXECUTORS_DEF
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename>
struct composed_work;
template <>
struct composed_work<void()>
{
typedef composed_io_executors<void()> executors_type;
composed_work(const executors_type&) BOOST_ASIO_NOEXCEPT
: head_(system_executor())
{
}
void reset()
{
head_.reset();
}
typedef system_executor head_type;
composed_work_guard<system_executor> head_;
};
template <typename Head>
struct composed_work<void(Head)>
{
typedef composed_io_executors<void(Head)> executors_type;
explicit composed_work(const executors_type& ex) BOOST_ASIO_NOEXCEPT
: head_(ex.head_)
{
}
void reset()
{
head_.reset();
}
typedef Head head_type;
composed_work_guard<Head> head_;
};
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Head, typename... Tail>
struct composed_work<void(Head, Tail...)>
{
typedef composed_io_executors<void(Head, Tail...)> executors_type;
explicit composed_work(const executors_type& ex) BOOST_ASIO_NOEXCEPT
: head_(ex.head_),
tail_(ex.tail_)
{
}
void reset()
{
head_.reset();
tail_.reset();
}
typedef Head head_type;
composed_work_guard<Head> head_;
composed_work<void(Tail...)> tail_;
};
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
#define BOOST_ASIO_PRIVATE_COMPOSED_WORK_DEF(n) \
template <typename Head, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct composed_work<void(Head, BOOST_ASIO_VARIADIC_TARGS(n))> \
{ \
typedef composed_io_executors<void(Head, \
BOOST_ASIO_VARIADIC_TARGS(n))> executors_type; \
\
explicit composed_work(const executors_type& ex) BOOST_ASIO_NOEXCEPT \
: head_(ex.head_), \
tail_(ex.tail_) \
{ \
} \
\
void reset() \
{ \
head_.reset(); \
tail_.reset(); \
} \
\
typedef Head head_type; \
composed_work_guard<Head> head_; \
composed_work<void(BOOST_ASIO_VARIADIC_TARGS(n))> tail_; \
}; \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_COMPOSED_WORK_DEF)
#undef BOOST_ASIO_PRIVATE_COMPOSED_WORK_DEF
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Impl, typename Work, typename Handler, typename Signature>
class composed_op;
template <typename Impl, typename Work, typename Handler,
typename R, typename... Args>
class composed_op<Impl, Work, Handler, R(Args...)>
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Impl, typename Work, typename Handler, typename Signature>
class composed_op
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
: public base_from_cancellation_state<Handler>
{
public:
template <typename I, typename W, typename H>
composed_op(BOOST_ASIO_MOVE_ARG(I) impl,
BOOST_ASIO_MOVE_ARG(W) work,
BOOST_ASIO_MOVE_ARG(H) handler)
: base_from_cancellation_state<Handler>(
handler, enable_terminal_cancellation()),
impl_(BOOST_ASIO_MOVE_CAST(I)(impl)),
work_(BOOST_ASIO_MOVE_CAST(W)(work)),
handler_(BOOST_ASIO_MOVE_CAST(H)(handler)),
invocations_(0)
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
composed_op(composed_op&& other)
: base_from_cancellation_state<Handler>(
BOOST_ASIO_MOVE_CAST(base_from_cancellation_state<
Handler>)(other)),
impl_(BOOST_ASIO_MOVE_CAST(Impl)(other.impl_)),
work_(BOOST_ASIO_MOVE_CAST(Work)(other.work_)),
handler_(BOOST_ASIO_MOVE_CAST(Handler)(other.handler_)),
invocations_(other.invocations_)
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
typedef typename associated_executor<Handler,
typename composed_work_guard<
typename Work::head_type
>::executor_type
>::type executor_type;
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return (get_associated_executor)(handler_, work_.head_.get_executor());
}
typedef typename associated_allocator<Handler,
std::allocator<void> >::type allocator_type;
allocator_type get_allocator() const BOOST_ASIO_NOEXCEPT
{
return (get_associated_allocator)(handler_, std::allocator<void>());
}
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template<typename... T>
void operator()(BOOST_ASIO_MOVE_ARG(T)... t)
{
if (invocations_ < ~0u)
++invocations_;
this->get_cancellation_state().slot().clear();
impl_(*this, BOOST_ASIO_MOVE_CAST(T)(t)...);
}
void complete(Args... args)
{
this->work_.reset();
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(this->handler_)(
BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
void operator()()
{
if (invocations_ < ~0u)
++invocations_;
this->get_cancellation_state().slot().clear();
impl_(*this);
}
void complete()
{
this->work_.reset();
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(this->handler_)();
}
#define BOOST_ASIO_PRIVATE_COMPOSED_OP_DEF(n) \
template<BOOST_ASIO_VARIADIC_TPARAMS(n)> \
void operator()(BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
{ \
if (invocations_ < ~0u) \
++invocations_; \
this->get_cancellation_state().slot().clear(); \
impl_(*this, BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
} \
\
template<BOOST_ASIO_VARIADIC_TPARAMS(n)> \
void complete(BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
{ \
this->work_.reset(); \
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(this->handler_)( \
BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
} \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_COMPOSED_OP_DEF)
#undef BOOST_ASIO_PRIVATE_COMPOSED_OP_DEF
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
void reset_cancellation_state()
{
base_from_cancellation_state<Handler>::reset_cancellation_state(handler_);
}
template <typename Filter>
void reset_cancellation_state(BOOST_ASIO_MOVE_ARG(Filter) filter)
{
base_from_cancellation_state<Handler>::reset_cancellation_state(handler_,
BOOST_ASIO_MOVE_CAST(Filter)(filter));
}
template <typename InFilter, typename OutFilter>
void reset_cancellation_state(BOOST_ASIO_MOVE_ARG(InFilter) in_filter,
BOOST_ASIO_MOVE_ARG(OutFilter) out_filter)
{
base_from_cancellation_state<Handler>::reset_cancellation_state(handler_,
BOOST_ASIO_MOVE_CAST(InFilter)(in_filter),
BOOST_ASIO_MOVE_CAST(OutFilter)(out_filter));
}
//private:
Impl impl_;
Work work_;
Handler handler_;
unsigned invocations_;
};
template <typename Impl, typename Work, typename Handler, typename Signature>
inline asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
composed_op<Impl, Work, Handler, Signature>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Impl, typename Work, typename Handler, typename Signature>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
composed_op<Impl, Work, Handler, Signature>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Impl, typename Work, typename Handler, typename Signature>
inline bool asio_handler_is_continuation(
composed_op<Impl, Work, Handler, Signature>* this_handler)
{
return this_handler->invocations_ > 1 ? true
: boost_asio_handler_cont_helpers::is_continuation(
this_handler->handler_);
}
template <typename Function, typename Impl,
typename Work, typename Handler, typename Signature>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
composed_op<Impl, Work, Handler, Signature>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename Impl,
typename Work, typename Handler, typename Signature>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
composed_op<Impl, Work, Handler, Signature>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Signature, typename Executors>
class initiate_composed_op
{
public:
typedef typename composed_io_executors<Executors>::head_type executor_type;
template <typename T>
explicit initiate_composed_op(int, BOOST_ASIO_MOVE_ARG(T) executors)
: executors_(BOOST_ASIO_MOVE_CAST(T)(executors))
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return executors_.head_;
}
template <typename Handler, typename Impl>
void operator()(BOOST_ASIO_MOVE_ARG(Handler) handler,
BOOST_ASIO_MOVE_ARG(Impl) impl) const
{
composed_op<typename decay<Impl>::type, composed_work<Executors>,
typename decay<Handler>::type, Signature>(
BOOST_ASIO_MOVE_CAST(Impl)(impl),
composed_work<Executors>(executors_),
BOOST_ASIO_MOVE_CAST(Handler)(handler))();
}
private:
composed_io_executors<Executors> executors_;
};
template <typename Signature, typename Executors>
inline initiate_composed_op<Signature, Executors> make_initiate_composed_op(
BOOST_ASIO_MOVE_ARG(composed_io_executors<Executors>) executors)
{
return initiate_composed_op<Signature, Executors>(0,
BOOST_ASIO_MOVE_CAST(composed_io_executors<Executors>)(executors));
}
template <typename IoObject>
inline typename IoObject::executor_type
get_composed_io_executor(IoObject& io_object,
typename enable_if<
!is_executor<IoObject>::value
>::type* = 0,
typename enable_if<
!execution::is_executor<IoObject>::value
>::type* = 0)
{
return io_object.get_executor();
}
template <typename Executor>
inline const Executor& get_composed_io_executor(const Executor& ex,
typename enable_if<
is_executor<Executor>::value
|| execution::is_executor<Executor>::value
>::type* = 0)
{
return ex;
}
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <template <typename, typename> class Associator,
typename Impl, typename Work, typename Handler,
typename Signature, typename DefaultCandidate>
struct associator<Associator,
detail::composed_op<Impl, Work, Handler, Signature>,
DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::composed_op<Impl, Work, Handler, Signature>& h,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename CompletionToken, typename Signature,
typename Implementation, typename... IoObjectsOrExecutors>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, Signature)
async_compose(BOOST_ASIO_MOVE_ARG(Implementation) implementation,
BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token,
BOOST_ASIO_MOVE_ARG(IoObjectsOrExecutors)... io_objects_or_executors)
{
return async_initiate<CompletionToken, Signature>(
detail::make_initiate_composed_op<Signature>(
detail::make_composed_io_executors(
detail::get_composed_io_executor(
BOOST_ASIO_MOVE_CAST(IoObjectsOrExecutors)(
io_objects_or_executors))...)),
token, BOOST_ASIO_MOVE_CAST(Implementation)(implementation));
}
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename CompletionToken, typename Signature, typename Implementation>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, Signature)
async_compose(BOOST_ASIO_MOVE_ARG(Implementation) implementation,
BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token)
{
return async_initiate<CompletionToken, Signature>(
detail::make_initiate_composed_op<Signature>(
detail::make_composed_io_executors()),
token, BOOST_ASIO_MOVE_CAST(Implementation)(implementation));
}
# define BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR(n) \
BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_##n
# define BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_1 \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T1)(x1))
# define BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_2 \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T1)(x1)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T2)(x2))
# define BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_3 \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T1)(x1)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T2)(x2)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T3)(x3))
# define BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_4 \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T1)(x1)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T2)(x2)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T3)(x3)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T4)(x4))
# define BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_5 \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T1)(x1)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T2)(x2)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T3)(x3)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T4)(x4)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T5)(x5))
# define BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_6 \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T1)(x1)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T2)(x2)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T3)(x3)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T4)(x4)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T5)(x5)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T6)(x6))
# define BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_7 \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T1)(x1)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T2)(x2)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T3)(x3)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T4)(x4)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T5)(x5)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T6)(x6)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T7)(x7))
# define BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_8 \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T1)(x1)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T2)(x2)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T3)(x3)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T4)(x4)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T5)(x5)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T6)(x6)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T7)(x7)), \
detail::get_composed_io_executor(BOOST_ASIO_MOVE_CAST(T8)(x8))
#define BOOST_ASIO_PRIVATE_ASYNC_COMPOSE_DEF(n) \
template <typename CompletionToken, typename Signature, \
typename Implementation, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, Signature) \
async_compose(BOOST_ASIO_MOVE_ARG(Implementation) implementation, \
BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \
BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
{ \
return async_initiate<CompletionToken, Signature>( \
detail::make_initiate_composed_op<Signature>( \
detail::make_composed_io_executors( \
BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR(n))), \
token, BOOST_ASIO_MOVE_CAST(Implementation)(implementation)); \
} \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_ASYNC_COMPOSE_DEF)
#undef BOOST_ASIO_PRIVATE_ASYNC_COMPOSE_DEF
#undef BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR
#undef BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_1
#undef BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_2
#undef BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_3
#undef BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_4
#undef BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_5
#undef BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_6
#undef BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_7
#undef BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_8
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_COMPOSE_HPP

View File

@@ -0,0 +1,907 @@
//
// impl/connect.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_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,
typename enable_if<is_legacy_connect_condition<
ConnectCondition, Iterator>::value>::type* = 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,
typename enable_if<!is_legacy_connect_condition<
ConnectCondition, Iterator>::value>::type* = 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,
typename constraint<is_endpoint_sequence<
EndpointSequence>::value>::type)
{
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,
typename constraint<is_endpoint_sequence<
EndpointSequence>::value>::type)
{
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,
typename constraint<!is_endpoint_sequence<Iterator>::value>::type)
{
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,
typename constraint<!is_endpoint_sequence<Iterator>::value>::type)
{
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,
typename constraint<is_endpoint_sequence<
EndpointSequence>::value>::type)
{
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,
typename constraint<is_endpoint_sequence<
EndpointSequence>::value>::type)
{
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,
typename constraint<!is_endpoint_sequence<Iterator>::value>::type)
{
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,
typename constraint<!is_endpoint_sequence<Iterator>::value>::type)
{
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_(BOOST_ASIO_MOVE_CAST(RangeConnectHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
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>(
BOOST_ASIO_MOVE_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_(BOOST_ASIO_MOVE_CAST(RangeConnectHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
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,
BOOST_ASIO_MOVE_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(
BOOST_ASIO_MOVE_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_;
}
BOOST_ASIO_MOVE_OR_LVALUE(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 asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
range_connect_op<Protocol, Executor, EndpointSequence,
ConnectCondition, RangeConnectHandler>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Protocol, typename Executor, typename EndpointSequence,
typename ConnectCondition, typename RangeConnectHandler>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
range_connect_op<Protocol, Executor, EndpointSequence,
ConnectCondition, RangeConnectHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 Function, typename Executor, typename Protocol,
typename EndpointSequence, typename ConnectCondition,
typename RangeConnectHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
range_connect_op<Protocol, Executor, EndpointSequence,
ConnectCondition, RangeConnectHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename Executor, typename Protocol,
typename EndpointSequence, typename ConnectCondition,
typename RangeConnectHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
range_connect_op<Protocol, Executor, EndpointSequence,
ConnectCondition, RangeConnectHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 BOOST_ASIO_NOEXCEPT
{
return socket_.get_executor();
}
template <typename RangeConnectHandler,
typename EndpointSequence, typename ConnectCondition>
void operator()(BOOST_ASIO_MOVE_ARG(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,
typename decay<RangeConnectHandler>::type>(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_(BOOST_ASIO_MOVE_CAST(IteratorConnectHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
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>(
BOOST_ASIO_MOVE_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_(BOOST_ASIO_MOVE_CAST(IteratorConnectHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
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_,
BOOST_ASIO_MOVE_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(
BOOST_ASIO_MOVE_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_;
}
BOOST_ASIO_MOVE_OR_LVALUE(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 asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
iterator_connect_op<Protocol, Executor, Iterator,
ConnectCondition, IteratorConnectHandler>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Protocol, typename Executor, typename Iterator,
typename ConnectCondition, typename IteratorConnectHandler>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
iterator_connect_op<Protocol, Executor, Iterator,
ConnectCondition, IteratorConnectHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 Function, typename Executor, typename Protocol,
typename Iterator, typename ConnectCondition,
typename IteratorConnectHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
iterator_connect_op<Protocol, Executor, Iterator,
ConnectCondition, IteratorConnectHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename Executor, typename Protocol,
typename Iterator, typename ConnectCondition,
typename IteratorConnectHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
iterator_connect_op<Protocol, Executor, Iterator,
ConnectCondition, IteratorConnectHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 BOOST_ASIO_NOEXCEPT
{
return socket_.get_executor();
}
template <typename IteratorConnectHandler,
typename Iterator, typename ConnectCondition>
void operator()(BOOST_ASIO_MOVE_ARG(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,
typename decay<IteratorConnectHandler>::type>(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,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
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,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
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 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(RangeConnectToken,
void (boost::system::error_code, typename Protocol::endpoint))
async_connect(basic_socket<Protocol, Executor>& s,
const EndpointSequence& endpoints,
BOOST_ASIO_MOVE_ARG(RangeConnectToken) token,
typename constraint<is_endpoint_sequence<
EndpointSequence>::value>::type)
{
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 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(IteratorConnectToken,
void (boost::system::error_code, Iterator))
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin,
BOOST_ASIO_MOVE_ARG(IteratorConnectToken) token,
typename constraint<!is_endpoint_sequence<Iterator>::value>::type)
{
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 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(IteratorConnectToken,
void (boost::system::error_code, Iterator))
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin, Iterator end,
BOOST_ASIO_MOVE_ARG(IteratorConnectToken) token)
{
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 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(RangeConnectToken,
void (boost::system::error_code, typename Protocol::endpoint))
async_connect(basic_socket<Protocol, Executor>& s,
const EndpointSequence& endpoints, ConnectCondition connect_condition,
BOOST_ASIO_MOVE_ARG(RangeConnectToken) token,
typename constraint<is_endpoint_sequence<
EndpointSequence>::value>::type)
{
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 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(IteratorConnectToken,
void (boost::system::error_code, Iterator))
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin,
ConnectCondition connect_condition,
BOOST_ASIO_MOVE_ARG(IteratorConnectToken) token,
typename constraint<!is_endpoint_sequence<Iterator>::value>::type)
{
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 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(IteratorConnectToken,
void (boost::system::error_code, Iterator))
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin,
Iterator end, ConnectCondition connect_condition,
BOOST_ASIO_MOVE_ARG(IteratorConnectToken) token)
{
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

View File

@@ -0,0 +1,75 @@
//
// impl/connect_pipe.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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

View File

@@ -0,0 +1,151 @@
//
// impl/connect_pipe.ipp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2021 Klemens D. Morgenstern
// (klemens dot morgenstern at gmx dot net)
//
// 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_IPP
#define BOOST_ASIO_IMPL_CONNECT_PIPE_IPP
#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>
#if defined(BOOST_ASIO_HAS_IOCP)
# include <cstdio>
# if _WIN32_WINNT >= 0x601
# include <bcrypt.h>
# if !defined(BOOST_ASIO_NO_DEFAULT_LINKED_LIBS)
# if defined(_MSC_VER)
# pragma comment(lib, "bcrypt.lib")
# endif // defined(_MSC_VER)
# endif // !defined(BOOST_ASIO_NO_DEFAULT_LINKED_LIBS)
# endif // _WIN32_WINNT >= 0x601
#else // defined(BOOST_ASIO_HAS_IOCP)
# include <boost/asio/detail/descriptor_ops.hpp>
#endif // defined(BOOST_ASIO_HAS_IOCP)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
void create_pipe(native_pipe_handle p[2], boost::system::error_code& ec)
{
#if defined(BOOST_ASIO_HAS_IOCP)
using namespace std; // For sprintf and memcmp.
static long counter1 = 0;
static long counter2 = 0;
long n1 = ::InterlockedIncrement(&counter1);
long n2 = (static_cast<unsigned long>(n1) % 0x10000000) == 0
? ::InterlockedIncrement(&counter2)
: ::InterlockedExchangeAdd(&counter2, 0);
wchar_t pipe_name[128];
#if defined(BOOST_ASIO_HAS_SECURE_RTL)
swprintf_s(
#else // defined(BOOST_ASIO_HAS_SECURE_RTL)
_snwprintf(
#endif // defined(BOOST_ASIO_HAS_SECURE_RTL)
pipe_name, 128,
L"\\\\.\\pipe\\asio-A0812896-741A-484D-AF23-BE51BF620E22-%u-%ld-%ld",
static_cast<unsigned int>(::GetCurrentProcessId()), n1, n2);
p[0] = ::CreateNamedPipeW(pipe_name,
PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
0, 1, 8192, 8192, 0, 0);
if (p[0] == INVALID_HANDLE_VALUE)
{
DWORD last_error = ::GetLastError();
ec.assign(last_error, boost::asio::error::get_system_category());
return;
}
p[1] = ::CreateFileW(pipe_name, GENERIC_WRITE, 0,
0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
if (p[1] == INVALID_HANDLE_VALUE)
{
DWORD last_error = ::GetLastError();
::CloseHandle(p[0]);
ec.assign(last_error, boost::asio::error::get_system_category());
return;
}
# if _WIN32_WINNT >= 0x601
unsigned char nonce[16];
if (::BCryptGenRandom(0, nonce, sizeof(nonce),
BCRYPT_USE_SYSTEM_PREFERRED_RNG) != 0)
{
ec = boost::asio::error::connection_aborted;
::CloseHandle(p[0]);
::CloseHandle(p[1]);
return;
}
DWORD bytes_written = 0;
BOOL ok = ::WriteFile(p[1], nonce, sizeof(nonce), &bytes_written, 0);
if (!ok || bytes_written != sizeof(nonce))
{
ec = boost::asio::error::connection_aborted;
::CloseHandle(p[0]);
::CloseHandle(p[1]);
return;
}
unsigned char nonce_check[sizeof(nonce)];
DWORD bytes_read = 0;
ok = ::ReadFile(p[0], nonce_check, sizeof(nonce), &bytes_read, 0);
if (!ok || bytes_read != sizeof(nonce)
|| memcmp(nonce, nonce_check, sizeof(nonce)) != 0)
{
ec = boost::asio::error::connection_aborted;
::CloseHandle(p[0]);
::CloseHandle(p[1]);
return;
}
#endif // _WIN32_WINNT >= 0x601
ec.assign(0, ec.category());
#else // defined(BOOST_ASIO_HAS_IOCP)
int result = ::pipe(p);
detail::descriptor_ops::get_last_error(ec, result != 0);
#endif // defined(BOOST_ASIO_HAS_IOCP)
}
void close_pipe(native_pipe_handle p)
{
#if defined(BOOST_ASIO_HAS_IOCP)
::CloseHandle(p);
#else // defined(BOOST_ASIO_HAS_IOCP)
boost::system::error_code ignored_ec;
detail::descriptor_ops::state_type state = 0;
detail::descriptor_ops::close(p, state, ignored_ec);
#endif // defined(BOOST_ASIO_HAS_IOCP)
}
} // namespace detail
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // defined(BOOST_ASIO_HAS_PIPE)
#endif // BOOST_ASIO_IMPL_CONNECT_PIPE_IPP

View File

@@ -0,0 +1,258 @@
//
// impl/defer.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_DEFER_HPP
#define BOOST_ASIO_IMPL_DEFER_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_allocator.hpp>
#include <boost/asio/associated_executor.hpp>
#include <boost/asio/detail/work_dispatcher.hpp>
#include <boost/asio/execution/allocator.hpp>
#include <boost/asio/execution/blocking.hpp>
#include <boost/asio/execution/relationship.hpp>
#include <boost/asio/prefer.hpp>
#include <boost/asio/require.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
class initiate_defer
{
public:
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
execution::is_executor<
typename associated_executor<
typename decay<CompletionHandler>::type
>::type
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_executor<handler_t>::type ex(
(get_associated_executor)(handler));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
execution::execute(
boost::asio::prefer(
boost::asio::require(ex, execution::blocking.never),
execution::relationship.continuation,
execution::allocator(alloc)),
boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)));
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
!execution::is_executor<
typename associated_executor<
typename decay<CompletionHandler>::type
>::type
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_executor<handler_t>::type ex(
(get_associated_executor)(handler));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
ex.defer(boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)), alloc);
}
};
template <typename Executor>
class initiate_defer_with_executor
{
public:
typedef Executor executor_type;
explicit initiate_defer_with_executor(const Executor& ex)
: ex_(ex)
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return ex_;
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
!detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
execution::execute(
boost::asio::prefer(
boost::asio::require(ex_, execution::blocking.never),
execution::relationship.continuation,
execution::allocator(alloc)),
boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)));
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typedef typename associated_executor<
handler_t, Executor>::type handler_ex_t;
handler_ex_t handler_ex((get_associated_executor)(handler, ex_));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
execution::execute(
boost::asio::prefer(
boost::asio::require(ex_, execution::blocking.never),
execution::relationship.continuation,
execution::allocator(alloc)),
detail::work_dispatcher<handler_t, handler_ex_t>(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler), handler_ex));
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
!execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
!detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
ex_.defer(boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)), alloc);
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
!execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typedef typename associated_executor<
handler_t, Executor>::type handler_ex_t;
handler_ex_t handler_ex((get_associated_executor)(handler, ex_));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
ex_.defer(detail::work_dispatcher<handler_t, handler_ex_t>(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler),
handler_ex), alloc);
}
private:
Executor ex_;
};
} // namespace detail
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(NullaryToken, void()) defer(
BOOST_ASIO_MOVE_ARG(NullaryToken) token)
{
return async_initiate<NullaryToken, void()>(
detail::initiate_defer(), token);
}
template <typename Executor,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(NullaryToken, void()) defer(
const Executor& ex, BOOST_ASIO_MOVE_ARG(NullaryToken) token,
typename constraint<
execution::is_executor<Executor>::value || is_executor<Executor>::value
>::type)
{
return async_initiate<NullaryToken, void()>(
detail::initiate_defer_with_executor<Executor>(ex), token);
}
template <typename ExecutionContext,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(NullaryToken, void()) defer(
ExecutionContext& ctx, BOOST_ASIO_MOVE_ARG(NullaryToken) token,
typename constraint<is_convertible<
ExecutionContext&, execution_context&>::value>::type)
{
return async_initiate<NullaryToken, void()>(
detail::initiate_defer_with_executor<
typename ExecutionContext::executor_type>(
ctx.get_executor()), token);
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_DEFER_HPP

View File

@@ -0,0 +1,132 @@
//
// impl/detached.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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/variadic_templates.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)
{
}
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename... Args>
void operator()(Args...)
{
}
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
void operator()()
{
}
#define BOOST_ASIO_PRIVATE_DETACHED_DEF(n) \
template <BOOST_ASIO_VARIADIC_TPARAMS(n)> \
void operator()(BOOST_ASIO_VARIADIC_TARGS(n)) \
{ \
} \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_DETACHED_DEF)
#undef BOOST_ASIO_PRIVATE_DETACHED_DEF
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
};
} // 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()
{
}
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Initiation, typename RawCompletionToken, typename... Args>
static return_type initiate(
BOOST_ASIO_MOVE_ARG(Initiation) initiation,
BOOST_ASIO_MOVE_ARG(RawCompletionToken),
BOOST_ASIO_MOVE_ARG(Args)... args)
{
BOOST_ASIO_MOVE_CAST(Initiation)(initiation)(
detail::detached_handler(detached_t()),
BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Initiation, typename RawCompletionToken>
static return_type initiate(
BOOST_ASIO_MOVE_ARG(Initiation) initiation,
BOOST_ASIO_MOVE_ARG(RawCompletionToken))
{
BOOST_ASIO_MOVE_CAST(Initiation)(initiation)(
detail::detached_handler(detached_t()));
}
#define BOOST_ASIO_PRIVATE_INITIATE_DEF(n) \
template <typename Initiation, typename RawCompletionToken, \
BOOST_ASIO_VARIADIC_TPARAMS(n)> \
static return_type initiate( \
BOOST_ASIO_MOVE_ARG(Initiation) initiation, \
BOOST_ASIO_MOVE_ARG(RawCompletionToken), \
BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
{ \
BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( \
detail::detached_handler(detached_t()), \
BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
} \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_INITIATE_DEF)
#undef BOOST_ASIO_PRIVATE_INITIATE_DEF
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
};
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_DETACHED_HPP

View File

@@ -0,0 +1,253 @@
//
// impl/dispatch.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_DISPATCH_HPP
#define BOOST_ASIO_IMPL_DISPATCH_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_allocator.hpp>
#include <boost/asio/associated_executor.hpp>
#include <boost/asio/detail/work_dispatcher.hpp>
#include <boost/asio/execution/allocator.hpp>
#include <boost/asio/execution/blocking.hpp>
#include <boost/asio/prefer.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
class initiate_dispatch
{
public:
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
execution::is_executor<
typename associated_executor<
typename decay<CompletionHandler>::type
>::type
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_executor<handler_t>::type ex(
(get_associated_executor)(handler));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
execution::execute(
boost::asio::prefer(ex,
execution::blocking.possibly,
execution::allocator(alloc)),
boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)));
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
!execution::is_executor<
typename associated_executor<
typename decay<CompletionHandler>::type
>::type
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_executor<handler_t>::type ex(
(get_associated_executor)(handler));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
ex.dispatch(boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)), alloc);
}
};
template <typename Executor>
class initiate_dispatch_with_executor
{
public:
typedef Executor executor_type;
explicit initiate_dispatch_with_executor(const Executor& ex)
: ex_(ex)
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return ex_;
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
!detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
execution::execute(
boost::asio::prefer(ex_,
execution::blocking.possibly,
execution::allocator(alloc)),
boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)));
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typedef typename associated_executor<
handler_t, Executor>::type handler_ex_t;
handler_ex_t handler_ex((get_associated_executor)(handler, ex_));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
execution::execute(
boost::asio::prefer(ex_,
execution::blocking.possibly,
execution::allocator(alloc)),
detail::work_dispatcher<handler_t, handler_ex_t>(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler), handler_ex));
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
!execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
!detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
ex_.dispatch(boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)), alloc);
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
!execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typedef typename associated_executor<
handler_t, Executor>::type handler_ex_t;
handler_ex_t handler_ex((get_associated_executor)(handler, ex_));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
ex_.dispatch(detail::work_dispatcher<handler_t, handler_ex_t>(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler),
handler_ex), alloc);
}
private:
Executor ex_;
};
} // namespace detail
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(NullaryToken, void()) dispatch(
BOOST_ASIO_MOVE_ARG(NullaryToken) token)
{
return async_initiate<NullaryToken, void()>(
detail::initiate_dispatch(), token);
}
template <typename Executor,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(NullaryToken, void()) dispatch(
const Executor& ex, BOOST_ASIO_MOVE_ARG(NullaryToken) token,
typename constraint<
execution::is_executor<Executor>::value || is_executor<Executor>::value
>::type)
{
return async_initiate<NullaryToken, void()>(
detail::initiate_dispatch_with_executor<Executor>(ex), token);
}
template <typename ExecutionContext,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(NullaryToken, void()) dispatch(
ExecutionContext& ctx, BOOST_ASIO_MOVE_ARG(NullaryToken) token,
typename constraint<is_convertible<
ExecutionContext&, execution_context&>::value>::type)
{
return async_initiate<NullaryToken, void()>(
detail::initiate_dispatch_with_executor<
typename ExecutionContext::executor_type>(
ctx.get_executor()), token);
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_DISPATCH_HPP

View File

@@ -0,0 +1,130 @@
//
// impl/error.ipp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_ERROR_IPP
#define BOOST_ASIO_IMPL_ERROR_IPP
#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/error.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace error {
#if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
namespace detail {
class netdb_category : public boost::system::error_category
{
public:
const char* name() const BOOST_ASIO_ERROR_CATEGORY_NOEXCEPT
{
return "asio.netdb";
}
std::string message(int value) const
{
if (value == error::host_not_found)
return "Host not found (authoritative)";
if (value == error::host_not_found_try_again)
return "Host not found (non-authoritative), try again later";
if (value == error::no_data)
return "The query is valid, but it does not have associated data";
if (value == error::no_recovery)
return "A non-recoverable error occurred during database lookup";
return "asio.netdb error";
}
};
} // namespace detail
const boost::system::error_category& get_netdb_category()
{
static detail::netdb_category instance;
return instance;
}
namespace detail {
class addrinfo_category : public boost::system::error_category
{
public:
const char* name() const BOOST_ASIO_ERROR_CATEGORY_NOEXCEPT
{
return "asio.addrinfo";
}
std::string message(int value) const
{
if (value == error::service_not_found)
return "Service not found";
if (value == error::socket_type_not_supported)
return "Socket type not supported";
return "asio.addrinfo error";
}
};
} // namespace detail
const boost::system::error_category& get_addrinfo_category()
{
static detail::addrinfo_category instance;
return instance;
}
#endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
namespace detail {
class misc_category : public boost::system::error_category
{
public:
const char* name() const BOOST_ASIO_ERROR_CATEGORY_NOEXCEPT
{
return "asio.misc";
}
std::string message(int value) const
{
if (value == error::already_open)
return "Already open";
if (value == error::eof)
return "End of file";
if (value == error::not_found)
return "Element not found";
if (value == error::fd_set_failure)
return "The descriptor does not fit into the select call's fd_set";
return "asio.misc error";
}
};
} // namespace detail
const boost::system::error_category& get_misc_category()
{
static detail::misc_category instance;
return instance;
}
} // namespace error
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_ERROR_IPP

View File

@@ -0,0 +1,111 @@
//
// impl/execution_context.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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>();
}
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Service, typename... Args>
Service& make_service(execution_context& e, BOOST_ASIO_MOVE_ARG(Args)... args)
{
detail::scoped_ptr<Service> svc(
new Service(e, BOOST_ASIO_MOVE_CAST(Args)(args)...));
e.service_registry_->template add_service<Service>(svc.get());
Service& result = *svc;
svc.release();
return result;
}
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Service>
Service& make_service(execution_context& e)
{
detail::scoped_ptr<Service> svc(new Service(e));
e.service_registry_->template add_service<Service>(svc.get());
Service& result = *svc;
svc.release();
return result;
}
#define BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF(n) \
template <typename Service, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
Service& make_service(execution_context& e, \
BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
{ \
detail::scoped_ptr<Service> svc( \
new Service(e, BOOST_ASIO_VARIADIC_MOVE_ARGS(n))); \
e.service_registry_->template add_service<Service>(svc.get()); \
Service& result = *svc; \
svc.release(); \
return result; \
} \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF)
#undef BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
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

View File

@@ -0,0 +1,84 @@
//
// impl/execution_context.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_IPP
#define BOOST_ASIO_IMPL_EXECUTION_CONTEXT_IPP
#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/execution_context.hpp>
#include <boost/asio/detail/service_registry.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
execution_context::execution_context()
: service_registry_(new boost::asio::detail::service_registry(*this))
{
}
execution_context::~execution_context()
{
shutdown();
destroy();
delete service_registry_;
}
void execution_context::shutdown()
{
service_registry_->shutdown_services();
}
void execution_context::destroy()
{
service_registry_->destroy_services();
}
void execution_context::notify_fork(
boost::asio::execution_context::fork_event event)
{
service_registry_->notify_fork(event);
}
execution_context::service::service(execution_context& owner)
: owner_(owner),
next_(0)
{
}
execution_context::service::~service()
{
}
void execution_context::service::notify_fork(execution_context::fork_event)
{
}
service_already_exists::service_already_exists()
: std::logic_error("Service already exists.")
{
}
invalid_service_owner::invalid_service_owner()
: std::logic_error("Invalid service owner.")
{
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_EXECUTION_CONTEXT_IPP

View File

@@ -0,0 +1,302 @@
//
// impl/executor.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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 <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;
}
impl(const Executor& e, const Allocator& a) BOOST_ASIO_NOEXCEPT
: impl_base(false),
ref_count_(1),
executor_(e),
allocator_(a)
{
}
impl_base* clone() const BOOST_ASIO_NOEXCEPT
{
detail::ref_count_up(ref_count_);
return const_cast<impl_base*>(static_cast<const impl_base*>(this));
}
void destroy() BOOST_ASIO_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() BOOST_ASIO_NOEXCEPT
{
executor_.on_work_started();
}
void on_work_finished() BOOST_ASIO_NOEXCEPT
{
executor_.on_work_finished();
}
execution_context& context() BOOST_ASIO_NOEXCEPT
{
return executor_.context();
}
void dispatch(BOOST_ASIO_MOVE_ARG(function) f)
{
executor_.dispatch(BOOST_ASIO_MOVE_CAST(function)(f), allocator_);
}
void post(BOOST_ASIO_MOVE_ARG(function) f)
{
executor_.post(BOOST_ASIO_MOVE_CAST(function)(f), allocator_);
}
void defer(BOOST_ASIO_MOVE_ARG(function) f)
{
executor_.defer(BOOST_ASIO_MOVE_CAST(function)(f), allocator_);
}
type_id_result_type target_type() const BOOST_ASIO_NOEXCEPT
{
return type_id<Executor>();
}
void* target() BOOST_ASIO_NOEXCEPT
{
return &executor_;
}
const void* target() const BOOST_ASIO_NOEXCEPT
{
return &executor_;
}
bool equals(const impl_base* e) const BOOST_ASIO_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> > >();
}
impl()
: impl_base(true)
{
}
impl_base* clone() const BOOST_ASIO_NOEXCEPT
{
return const_cast<impl_base*>(static_cast<const impl_base*>(this));
}
void destroy() BOOST_ASIO_NOEXCEPT
{
}
void on_work_started() BOOST_ASIO_NOEXCEPT
{
executor_.on_work_started();
}
void on_work_finished() BOOST_ASIO_NOEXCEPT
{
executor_.on_work_finished();
}
execution_context& context() BOOST_ASIO_NOEXCEPT
{
return executor_.context();
}
void dispatch(BOOST_ASIO_MOVE_ARG(function) f)
{
executor_.dispatch(BOOST_ASIO_MOVE_CAST(function)(f),
std::allocator<void>());
}
void post(BOOST_ASIO_MOVE_ARG(function) f)
{
executor_.post(BOOST_ASIO_MOVE_CAST(function)(f),
std::allocator<void>());
}
void defer(BOOST_ASIO_MOVE_ARG(function) f)
{
executor_.defer(BOOST_ASIO_MOVE_CAST(function)(f),
std::allocator<void>());
}
type_id_result_type target_type() const BOOST_ASIO_NOEXCEPT
{
return type_id<system_executor>();
}
void* target() BOOST_ASIO_NOEXCEPT
{
return &executor_;
}
const void* target() const BOOST_ASIO_NOEXCEPT
{
return &executor_;
}
bool equals(const impl_base* e) const BOOST_ASIO_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, 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(BOOST_ASIO_MOVE_ARG(Function) f,
const Allocator& a) const
{
impl_base* i = get_impl();
if (i->fast_dispatch_)
system_executor().dispatch(BOOST_ASIO_MOVE_CAST(Function)(f), a);
else
i->dispatch(function(BOOST_ASIO_MOVE_CAST(Function)(f), a));
}
template <typename Function, typename Allocator>
void executor::post(BOOST_ASIO_MOVE_ARG(Function) f,
const Allocator& a) const
{
get_impl()->post(function(BOOST_ASIO_MOVE_CAST(Function)(f), a));
}
template <typename Function, typename Allocator>
void executor::defer(BOOST_ASIO_MOVE_ARG(Function) f,
const Allocator& a) const
{
get_impl()->defer(function(BOOST_ASIO_MOVE_CAST(Function)(f), a));
}
template <typename Executor>
Executor* executor::target() BOOST_ASIO_NOEXCEPT
{
return impl_ && impl_->target_type() == type_id<Executor>()
? static_cast<Executor*>(impl_->target()) : 0;
}
template <typename Executor>
const Executor* executor::target() const BOOST_ASIO_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

View File

@@ -0,0 +1,45 @@
//
// impl/executor.ipp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_IPP
#define BOOST_ASIO_IMPL_EXECUTOR_IPP
#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 <boost/asio/executor.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
bad_executor::bad_executor() BOOST_ASIO_NOEXCEPT
{
}
const char* bad_executor::what() const BOOST_ASIO_NOEXCEPT_OR_NOTHROW
{
return "bad executor";
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
#endif // BOOST_ASIO_IMPL_EXECUTOR_IPP

View File

@@ -0,0 +1,64 @@
//
// impl/handler_alloc_hook.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_HANDLER_ALLOC_HOOK_IPP
#define BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
#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/memory.hpp>
#include <boost/asio/detail/thread_context.hpp>
#include <boost/asio/detail/thread_info_base.hpp>
#include <boost/asio/handler_alloc_hook.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size, ...)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
(void)size;
return asio_handler_allocate_is_no_longer_used();
#elif !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
return detail::thread_info_base::allocate(
detail::thread_context::top_of_thread_call_stack(), size);
#else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
return aligned_new(BOOST_ASIO_DEFAULT_ALIGN, size);
#endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
}
asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size, ...)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
(void)pointer;
(void)size;
return asio_handler_deallocate_is_no_longer_used();
#elif !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
detail::thread_info_base::deallocate(
detail::thread_context::top_of_thread_call_stack(), pointer, size);
#else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
(void)size;
aligned_delete(pointer)
#endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP

View File

@@ -0,0 +1,446 @@
//
// impl/io_context.hpp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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() BOOST_ASIO_NOEXCEPT
{
return executor_type(*this);
}
#if defined(BOOST_ASIO_HAS_CHRONO)
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;
}
#endif // defined(BOOST_ASIO_HAS_CHRONO)
#if !defined(BOOST_ASIO_NO_DEPRECATED)
inline void io_context::reset()
{
restart();
}
struct io_context::initiate_dispatch
{
template <typename LegacyCompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(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);
boost_asio_handler_invoke_helpers::invoke(
handler2.value, handler2.value);
}
else
{
// Allocate and construct an operation to wrap the handler.
typedef detail::completion_handler<
typename decay<LegacyCompletionHandler>::type, 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>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(LegacyCompletionHandler, void ())
io_context::dispatch(BOOST_ASIO_MOVE_ARG(LegacyCompletionHandler) handler)
{
return async_initiate<LegacyCompletionHandler, void ()>(
initiate_dispatch(), handler, this);
}
struct io_context::initiate_post
{
template <typename LegacyCompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(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<
typename decay<LegacyCompletionHandler>::type, 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>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(LegacyCompletionHandler, void ())
io_context::post(BOOST_ASIO_MOVE_ARG(LegacyCompletionHandler) handler)
{
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) BOOST_ASIO_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;
}
#if defined(BOOST_ASIO_HAS_MOVE)
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) BOOST_ASIO_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;
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename Allocator, uintptr_t Bits>
inline bool io_context::basic_executor_type<Allocator,
Bits>::running_in_this_thread() const BOOST_ASIO_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(
BOOST_ASIO_MOVE_ARG(Function) f) const
{
typedef typename decay<Function>::type 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(BOOST_ASIO_MOVE_CAST(Function)(f));
#if defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR) \
&& !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
{
#endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
// && !defined(BOOST_ASIO_NO_EXCEPTIONS)
detail::fenced_block b(detail::fenced_block::full);
boost_asio_handler_invoke_helpers::invoke(tmp, tmp);
return;
#if defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR) \
&& !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
catch (...)
{
context_ptr()->impl_.capture_current_exception();
return;
}
#endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
// && !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(BOOST_ASIO_MOVE_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 BOOST_ASIO_NOEXCEPT
{
return *context_ptr();
}
template <typename Allocator, uintptr_t Bits>
inline void io_context::basic_executor_type<Allocator,
Bits>::on_work_started() const BOOST_ASIO_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 BOOST_ASIO_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(
BOOST_ASIO_MOVE_ARG(Function) f, const OtherAllocator& a) const
{
typedef typename decay<Function>::type 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(BOOST_ASIO_MOVE_CAST(Function)(f));
detail::fenced_block b(detail::fenced_block::full);
boost_asio_handler_invoke_helpers::invoke(tmp, 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(BOOST_ASIO_MOVE_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(
BOOST_ASIO_MOVE_ARG(Function) f, const OtherAllocator& a) const
{
typedef typename decay<Function>::type function_type;
// 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(BOOST_ASIO_MOVE_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(
BOOST_ASIO_MOVE_ARG(Function) f, const OtherAllocator& a) const
{
typedef typename decay<Function>::type function_type;
// 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(BOOST_ASIO_MOVE_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

View File

@@ -0,0 +1,177 @@
//
// impl/io_context.ipp
// ~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_IPP
#define BOOST_ASIO_IMPL_IO_CONTEXT_IPP
#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/io_context.hpp>
#include <boost/asio/detail/concurrency_hint.hpp>
#include <boost/asio/detail/limits.hpp>
#include <boost/asio/detail/scoped_ptr.hpp>
#include <boost/asio/detail/service_registry.hpp>
#include <boost/asio/detail/throw_error.hpp>
#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 {
io_context::io_context()
: impl_(add_impl(new impl_type(*this,
BOOST_ASIO_CONCURRENCY_HINT_DEFAULT, false)))
{
}
io_context::io_context(int concurrency_hint)
: impl_(add_impl(new impl_type(*this, concurrency_hint == 1
? BOOST_ASIO_CONCURRENCY_HINT_1 : concurrency_hint, false)))
{
}
io_context::impl_type& io_context::add_impl(io_context::impl_type* impl)
{
boost::asio::detail::scoped_ptr<impl_type> scoped_impl(impl);
boost::asio::add_service<impl_type>(*this, scoped_impl.get());
return *scoped_impl.release();
}
io_context::~io_context()
{
}
io_context::count_type io_context::run()
{
boost::system::error_code ec;
count_type s = impl_.run(ec);
boost::asio::detail::throw_error(ec);
return s;
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
io_context::count_type io_context::run(boost::system::error_code& ec)
{
return impl_.run(ec);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
io_context::count_type io_context::run_one()
{
boost::system::error_code ec;
count_type s = impl_.run_one(ec);
boost::asio::detail::throw_error(ec);
return s;
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
io_context::count_type io_context::run_one(boost::system::error_code& ec)
{
return impl_.run_one(ec);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
io_context::count_type io_context::poll()
{
boost::system::error_code ec;
count_type s = impl_.poll(ec);
boost::asio::detail::throw_error(ec);
return s;
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
io_context::count_type io_context::poll(boost::system::error_code& ec)
{
return impl_.poll(ec);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
io_context::count_type io_context::poll_one()
{
boost::system::error_code ec;
count_type s = impl_.poll_one(ec);
boost::asio::detail::throw_error(ec);
return s;
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
io_context::count_type io_context::poll_one(boost::system::error_code& ec)
{
return impl_.poll_one(ec);
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
void io_context::stop()
{
impl_.stop();
}
bool io_context::stopped() const
{
return impl_.stopped();
}
void io_context::restart()
{
impl_.restart();
}
io_context::service::service(boost::asio::io_context& owner)
: execution_context::service(owner)
{
}
io_context::service::~service()
{
}
void io_context::service::shutdown()
{
#if !defined(BOOST_ASIO_NO_DEPRECATED)
shutdown_service();
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
void io_context::service::shutdown_service()
{
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
void io_context::service::notify_fork(io_context::fork_event ev)
{
#if !defined(BOOST_ASIO_NO_DEPRECATED)
fork_service(ev);
#else // !defined(BOOST_ASIO_NO_DEPRECATED)
(void)ev;
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
}
#if !defined(BOOST_ASIO_NO_DEPRECATED)
void io_context::service::fork_service(io_context::fork_event)
{
}
#endif // !defined(BOOST_ASIO_NO_DEPRECATED)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_IO_CONTEXT_IPP

View File

@@ -0,0 +1,51 @@
//
// impl/multiple_exceptions.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_MULTIPLE_EXCEPTIONS_IPP
#define BOOST_ASIO_IMPL_MULTIPLE_EXCEPTIONS_IPP
#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/multiple_exceptions.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
#if defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
multiple_exceptions::multiple_exceptions(
std::exception_ptr first) BOOST_ASIO_NOEXCEPT
: first_(BOOST_ASIO_MOVE_CAST(std::exception_ptr)(first))
{
}
const char* multiple_exceptions::what() const BOOST_ASIO_NOEXCEPT_OR_NOTHROW
{
return "multiple exceptions";
}
std::exception_ptr multiple_exceptions::first_exception() const
{
return first_;
}
#endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_MULTIPLE_EXCEPTIONS_IPP

View File

@@ -0,0 +1,258 @@
//
// impl/post.hpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_POST_HPP
#define BOOST_ASIO_IMPL_POST_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_allocator.hpp>
#include <boost/asio/associated_executor.hpp>
#include <boost/asio/detail/work_dispatcher.hpp>
#include <boost/asio/execution/allocator.hpp>
#include <boost/asio/execution/blocking.hpp>
#include <boost/asio/execution/relationship.hpp>
#include <boost/asio/prefer.hpp>
#include <boost/asio/require.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
namespace detail {
class initiate_post
{
public:
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
execution::is_executor<
typename associated_executor<
typename decay<CompletionHandler>::type
>::type
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_executor<handler_t>::type ex(
(get_associated_executor)(handler));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
execution::execute(
boost::asio::prefer(
boost::asio::require(ex, execution::blocking.never),
execution::relationship.fork,
execution::allocator(alloc)),
boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)));
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
!execution::is_executor<
typename associated_executor<
typename decay<CompletionHandler>::type
>::type
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_executor<handler_t>::type ex(
(get_associated_executor)(handler));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
ex.post(boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)), alloc);
}
};
template <typename Executor>
class initiate_post_with_executor
{
public:
typedef Executor executor_type;
explicit initiate_post_with_executor(const Executor& ex)
: ex_(ex)
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return ex_;
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
!detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
execution::execute(
boost::asio::prefer(
boost::asio::require(ex_, execution::blocking.never),
execution::relationship.fork,
execution::allocator(alloc)),
boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)));
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typedef typename associated_executor<
handler_t, Executor>::type handler_ex_t;
handler_ex_t handler_ex((get_associated_executor)(handler, ex_));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
execution::execute(
boost::asio::prefer(
boost::asio::require(ex_, execution::blocking.never),
execution::relationship.fork,
execution::allocator(alloc)),
detail::work_dispatcher<handler_t, handler_ex_t>(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler), handler_ex));
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
!execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
!detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
ex_.post(boost::asio::detail::bind_handler(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)), alloc);
}
template <typename CompletionHandler>
void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler,
typename enable_if<
!execution::is_executor<
typename conditional<true, executor_type, CompletionHandler>::type
>::value
>::type* = 0,
typename enable_if<
detail::is_work_dispatcher_required<
typename decay<CompletionHandler>::type,
Executor
>::value
>::type* = 0) const
{
typedef typename decay<CompletionHandler>::type handler_t;
typedef typename associated_executor<
handler_t, Executor>::type handler_ex_t;
handler_ex_t handler_ex((get_associated_executor)(handler, ex_));
typename associated_allocator<handler_t>::type alloc(
(get_associated_allocator)(handler));
ex_.post(detail::work_dispatcher<handler_t, handler_ex_t>(
BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler),
handler_ex), alloc);
}
private:
Executor ex_;
};
} // namespace detail
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(NullaryToken, void()) post(
BOOST_ASIO_MOVE_ARG(NullaryToken) token)
{
return async_initiate<NullaryToken, void()>(
detail::initiate_post(), token);
}
template <typename Executor,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(NullaryToken, void()) post(
const Executor& ex, BOOST_ASIO_MOVE_ARG(NullaryToken) token,
typename constraint<
execution::is_executor<Executor>::value || is_executor<Executor>::value
>::type)
{
return async_initiate<NullaryToken, void()>(
detail::initiate_post_with_executor<Executor>(ex), token);
}
template <typename ExecutionContext,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(NullaryToken, void()) post(
ExecutionContext& ctx, BOOST_ASIO_MOVE_ARG(NullaryToken) token,
typename constraint<is_convertible<
ExecutionContext&, execution_context&>::value>::type)
{
return async_initiate<NullaryToken, void()>(
detail::initiate_post_with_executor<
typename ExecutionContext::executor_type>(
ctx.get_executor()), token);
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_POST_HPP

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,735 @@
//
// impl/read_at.hpp
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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/completion_condition.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_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_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),
BOOST_ASIO_MOVE_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,
BOOST_ASIO_MOVE_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,
BOOST_ASIO_MOVE_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_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
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>(
BOOST_ASIO_MOVE_CAST(base_from_cancellation_state<
ReadHandler>)(other)),
base_from_completion_cond<CompletionCondition>(
BOOST_ASIO_MOVE_CAST(base_from_completion_cond<
CompletionCondition>)(other)),
device_(other.device_),
offset_(other.offset_),
buffers_(BOOST_ASIO_MOVE_CAST(buffers_type)(other.buffers_)),
start_(other.start_),
handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
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),
BOOST_ASIO_MOVE_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;
}
}
BOOST_ASIO_MOVE_OR_LVALUE(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 asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
MutableBufferIterator, CompletionCondition, ReadHandler>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename MutableBufferIterator,
typename CompletionCondition, typename ReadHandler>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
MutableBufferIterator, CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 Function, typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename MutableBufferIterator,
typename CompletionCondition, typename ReadHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
MutableBufferIterator, CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename MutableBufferIterator,
typename CompletionCondition, typename ReadHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
MutableBufferIterator, CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename AsyncRandomAccessReadDevice,
typename MutableBufferSequence, typename MutableBufferIterator,
typename CompletionCondition, typename ReadHandler>
inline void start_read_at_buffer_sequence_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_buffer_sequence
{
public:
typedef typename AsyncRandomAccessReadDevice::executor_type executor_type;
explicit initiate_async_read_at_buffer_sequence(
AsyncRandomAccessReadDevice& device)
: device_(device)
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return device_.get_executor();
}
template <typename ReadHandler, typename MutableBufferSequence,
typename CompletionCondition>
void operator()(BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
uint64_t offset, const MutableBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(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_buffer_sequence_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,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
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 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
void (boost::system::error_code, std::size_t))
async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(ReadToken) token)
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_at_buffer_sequence<
AsyncRandomAccessReadDevice>(d),
token, offset, buffers,
BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
}
template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
void (boost::system::error_code, std::size_t))
async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, const MutableBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(ReadToken) token)
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_at_buffer_sequence<
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_(BOOST_ASIO_MOVE_CAST(ReadHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
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>(
BOOST_ASIO_MOVE_CAST(base_from_cancellation_state<
ReadHandler>)(other)),
base_from_completion_cond<CompletionCondition>(
BOOST_ASIO_MOVE_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_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
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),
BOOST_ASIO_MOVE_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;
}
}
BOOST_ASIO_MOVE_OR_LVALUE(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 asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename AsyncRandomAccessReadDevice, typename Allocator,
typename CompletionCondition, typename ReadHandler>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 Function, typename AsyncRandomAccessReadDevice,
typename Allocator, typename CompletionCondition, typename ReadHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename AsyncRandomAccessReadDevice,
typename Allocator, typename CompletionCondition, typename ReadHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
read_at_streambuf_op<AsyncRandomAccessReadDevice, Allocator,
CompletionCondition, ReadHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 BOOST_ASIO_NOEXCEPT
{
return device_.get_executor();
}
template <typename ReadHandler,
typename Allocator, typename CompletionCondition>
void operator()(BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
uint64_t offset, basic_streambuf<Allocator>* b,
BOOST_ASIO_MOVE_ARG(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, typename decay<ReadHandler>::type>(
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,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
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 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
void (boost::system::error_code, std::size_t))
async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(ReadToken) token)
{
return async_initiate<ReadToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_read_at_streambuf<AsyncRandomAccessReadDevice>(d),
token, offset, &b,
BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
}
template <typename AsyncRandomAccessReadDevice, typename Allocator,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) ReadToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ReadToken,
void (boost::system::error_code, std::size_t))
async_read_at(AsyncRandomAccessReadDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
BOOST_ASIO_MOVE_ARG(ReadToken) token)
{
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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,611 @@
// impl/redirect_error.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/type_traits.hpp>
#include <boost/asio/detail/variadic_templates.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_(BOOST_ASIO_MOVE_CAST(CompletionToken)(e.token_))
{
}
template <typename RedirectedHandler>
redirect_error_handler(boost::system::error_code& ec,
BOOST_ASIO_MOVE_ARG(RedirectedHandler) h)
: ec_(ec),
handler_(BOOST_ASIO_MOVE_CAST(RedirectedHandler)(h))
{
}
void operator()()
{
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)();
}
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Arg, typename... Args>
typename enable_if<
!is_same<typename decay<Arg>::type, boost::system::error_code>::value
>::type
operator()(BOOST_ASIO_MOVE_ARG(Arg) arg, BOOST_ASIO_MOVE_ARG(Args)... args)
{
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)(
BOOST_ASIO_MOVE_CAST(Arg)(arg),
BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
template <typename... Args>
void operator()(const boost::system::error_code& ec,
BOOST_ASIO_MOVE_ARG(Args)... args)
{
ec_ = ec;
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)(
BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Arg>
typename enable_if<
!is_same<typename decay<Arg>::type, boost::system::error_code>::value
>::type
operator()(BOOST_ASIO_MOVE_ARG(Arg) arg)
{
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)(
BOOST_ASIO_MOVE_CAST(Arg)(arg));
}
void operator()(const boost::system::error_code& ec)
{
ec_ = ec;
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)();
}
#define BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \
template <typename Arg, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
typename enable_if< \
!is_same<typename decay<Arg>::type, boost::system::error_code>::value \
>::type \
operator()(BOOST_ASIO_MOVE_ARG(Arg) arg, BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
{ \
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)( \
BOOST_ASIO_MOVE_CAST(Arg)(arg), \
BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
} \
\
template <BOOST_ASIO_VARIADIC_TPARAMS(n)> \
void operator()(const boost::system::error_code& ec, \
BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
{ \
ec_ = ec; \
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(handler_)( \
BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
} \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF)
#undef BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
//private:
boost::system::error_code& ec_;
Handler handler_;
};
template <typename Handler>
inline asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
redirect_error_handler<Handler>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Handler>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
redirect_error_handler<Handler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 Function, typename Handler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
redirect_error_handler<Handler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename Handler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
redirect_error_handler<Handler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Signature>
struct redirect_error_signature
{
typedef Signature type;
};
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
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_REF_QUALIFIED_FUNCTIONS)
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)
# endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename R>
struct redirect_error_signature<R(boost::system::error_code)>
{
typedef R type();
};
template <typename R>
struct redirect_error_signature<R(const boost::system::error_code&)>
{
typedef R type();
};
#define BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(boost::system::error_code, BOOST_ASIO_VARIADIC_TARGS(n))> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \
}; \
\
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(const boost::system::error_code&, BOOST_ASIO_VARIADIC_TARGS(n))> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)); \
}; \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF)
#undef BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF
# if defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
template <typename R>
struct redirect_error_signature<R(boost::system::error_code) &>
{
typedef R type() &;
};
template <typename R>
struct redirect_error_signature<R(const boost::system::error_code&) &>
{
typedef R type() &;
};
template <typename R>
struct redirect_error_signature<R(boost::system::error_code) &&>
{
typedef R type() &&;
};
template <typename R>
struct redirect_error_signature<R(const boost::system::error_code&) &&>
{
typedef R type() &&;
};
#define BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(boost::system::error_code, BOOST_ASIO_VARIADIC_TARGS(n)) &> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) &; \
}; \
\
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(const boost::system::error_code&, BOOST_ASIO_VARIADIC_TARGS(n)) &> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) &; \
}; \
\
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(boost::system::error_code, BOOST_ASIO_VARIADIC_TARGS(n)) &&> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) &&; \
}; \
\
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(const boost::system::error_code&, BOOST_ASIO_VARIADIC_TARGS(n)) &&> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) &&; \
}; \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF)
#undef BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF
# if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
template <typename R>
struct redirect_error_signature<
R(boost::system::error_code) noexcept>
{
typedef R type() noexcept;
};
template <typename R>
struct redirect_error_signature<
R(const boost::system::error_code&) noexcept>
{
typedef R type() noexcept;
};
template <typename R>
struct redirect_error_signature<
R(boost::system::error_code) & noexcept>
{
typedef R type() & noexcept;
};
template <typename R>
struct redirect_error_signature<
R(const boost::system::error_code&) & noexcept>
{
typedef R type() & noexcept;
};
template <typename R>
struct redirect_error_signature<
R(boost::system::error_code) && noexcept>
{
typedef R type() && noexcept;
};
template <typename R>
struct redirect_error_signature<
R(const boost::system::error_code&) && noexcept>
{
typedef R type() && noexcept;
};
#define BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(boost::system::error_code, BOOST_ASIO_VARIADIC_TARGS(n)) noexcept> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) noexcept; \
}; \
\
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(const boost::system::error_code&, \
BOOST_ASIO_VARIADIC_TARGS(n)) noexcept> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) noexcept; \
}; \
\
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(boost::system::error_code, \
BOOST_ASIO_VARIADIC_TARGS(n)) & noexcept> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) & noexcept; \
}; \
\
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(const boost::system::error_code&, \
BOOST_ASIO_VARIADIC_TARGS(n)) & noexcept> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) & noexcept; \
}; \
\
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(boost::system::error_code, \
BOOST_ASIO_VARIADIC_TARGS(n)) && noexcept> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) && noexcept; \
}; \
\
template <typename R, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
struct redirect_error_signature< \
R(const boost::system::error_code&, \
BOOST_ASIO_VARIADIC_TARGS(n)) && noexcept> \
{ \
typedef R type(BOOST_ASIO_VARIADIC_TARGS(n)) && noexcept; \
}; \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF)
#undef BOOST_ASIO_PRIVATE_REDIRECT_ERROR_DEF
# endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
# endif // defined(BOOST_ASIO_HAS_REF_QUALIFIED_FUNCTIONS)
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <typename CompletionToken, typename Signature>
struct async_result<redirect_error_t<CompletionToken>, Signature>
{
typedef typename async_result<CompletionToken,
typename detail::redirect_error_signature<Signature>::type>
::return_type return_type;
template <typename Initiation>
struct init_wrapper
{
template <typename Init>
init_wrapper(boost::system::error_code& ec, BOOST_ASIO_MOVE_ARG(Init) init)
: ec_(ec),
initiation_(BOOST_ASIO_MOVE_CAST(Init)(init))
{
}
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Handler, typename... Args>
void operator()(
BOOST_ASIO_MOVE_ARG(Handler) handler,
BOOST_ASIO_MOVE_ARG(Args)... args)
{
BOOST_ASIO_MOVE_CAST(Initiation)(initiation_)(
detail::redirect_error_handler<
typename decay<Handler>::type>(
ec_, BOOST_ASIO_MOVE_CAST(Handler)(handler)),
BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Handler>
void operator()(
BOOST_ASIO_MOVE_ARG(Handler) handler)
{
BOOST_ASIO_MOVE_CAST(Initiation)(initiation_)(
detail::redirect_error_handler<
typename decay<Handler>::type>(
ec_, BOOST_ASIO_MOVE_CAST(Handler)(handler)));
}
#define BOOST_ASIO_PRIVATE_INIT_WRAPPER_DEF(n) \
template <typename Handler, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
void operator()( \
BOOST_ASIO_MOVE_ARG(Handler) handler, \
BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
{ \
BOOST_ASIO_MOVE_CAST(Initiation)(initiation_)( \
detail::redirect_error_handler< \
typename decay<Handler>::type>( \
ec_, BOOST_ASIO_MOVE_CAST(Handler)(handler)), \
BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
} \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_INIT_WRAPPER_DEF)
#undef BOOST_ASIO_PRIVATE_INIT_WRAPPER_DEF
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
boost::system::error_code& ec_;
Initiation initiation_;
};
#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Initiation, typename RawCompletionToken, typename... Args>
static return_type initiate(
BOOST_ASIO_MOVE_ARG(Initiation) initiation,
BOOST_ASIO_MOVE_ARG(RawCompletionToken) token,
BOOST_ASIO_MOVE_ARG(Args)... args)
{
return async_initiate<CompletionToken,
typename detail::redirect_error_signature<Signature>::type>(
init_wrapper<typename decay<Initiation>::type>(
token.ec_, BOOST_ASIO_MOVE_CAST(Initiation)(initiation)),
token.token_, BOOST_ASIO_MOVE_CAST(Args)(args)...);
}
#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
template <typename Initiation, typename RawCompletionToken>
static return_type initiate(
BOOST_ASIO_MOVE_ARG(Initiation) initiation,
BOOST_ASIO_MOVE_ARG(RawCompletionToken) token)
{
return async_initiate<CompletionToken,
typename detail::redirect_error_signature<Signature>::type>(
init_wrapper<typename decay<Initiation>::type>(
token.ec_, BOOST_ASIO_MOVE_CAST(Initiation)(initiation)),
token.token_);
}
#define BOOST_ASIO_PRIVATE_INITIATE_DEF(n) \
template <typename Initiation, typename RawCompletionToken, \
BOOST_ASIO_VARIADIC_TPARAMS(n)> \
static return_type initiate( \
BOOST_ASIO_MOVE_ARG(Initiation) initiation, \
BOOST_ASIO_MOVE_ARG(RawCompletionToken) token, \
BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
{ \
return async_initiate<CompletionToken, \
typename detail::redirect_error_signature<Signature>::type>( \
init_wrapper<typename decay<Initiation>::type>( \
token.ec_, BOOST_ASIO_MOVE_CAST(Initiation)(initiation)), \
token.token_, BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
} \
/**/
BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_INITIATE_DEF)
#undef BOOST_ASIO_PRIVATE_INITIATE_DEF
#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
};
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,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
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

View File

@@ -0,0 +1,61 @@
//
// impl/serial_port_base.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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

View File

@@ -0,0 +1,556 @@
//
// impl/serial_port_base.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_IPP
#define BOOST_ASIO_IMPL_SERIAL_PORT_BASE_IPP
#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)
#include <stdexcept>
#include <boost/asio/error.hpp>
#include <boost/asio/serial_port_base.hpp>
#include <boost/asio/detail/throw_exception.hpp>
#if defined(GENERATING_DOCUMENTATION)
# define BOOST_ASIO_OPTION_STORAGE implementation_defined
#elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
# define BOOST_ASIO_OPTION_STORAGE DCB
#else
# define BOOST_ASIO_OPTION_STORAGE termios
#endif
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
BOOST_ASIO_SYNC_OP_VOID serial_port_base::baud_rate::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
storage.BaudRate = value_;
#else
speed_t baud;
switch (value_)
{
// Do POSIX-specified rates first.
case 0: baud = B0; break;
case 50: baud = B50; break;
case 75: baud = B75; break;
case 110: baud = B110; break;
case 134: baud = B134; break;
case 150: baud = B150; break;
case 200: baud = B200; break;
case 300: baud = B300; break;
case 600: baud = B600; break;
case 1200: baud = B1200; break;
case 1800: baud = B1800; break;
case 2400: baud = B2400; break;
case 4800: baud = B4800; break;
case 9600: baud = B9600; break;
case 19200: baud = B19200; break;
case 38400: baud = B38400; break;
// And now the extended ones conditionally.
# ifdef B7200
case 7200: baud = B7200; break;
# endif
# ifdef B14400
case 14400: baud = B14400; break;
# endif
# ifdef B57600
case 57600: baud = B57600; break;
# endif
# ifdef B115200
case 115200: baud = B115200; break;
# endif
# ifdef B230400
case 230400: baud = B230400; break;
# endif
# ifdef B460800
case 460800: baud = B460800; break;
# endif
# ifdef B500000
case 500000: baud = B500000; break;
# endif
# ifdef B576000
case 576000: baud = B576000; break;
# endif
# ifdef B921600
case 921600: baud = B921600; break;
# endif
# ifdef B1000000
case 1000000: baud = B1000000; break;
# endif
# ifdef B1152000
case 1152000: baud = B1152000; break;
# endif
# ifdef B2000000
case 2000000: baud = B2000000; break;
# endif
# ifdef B3000000
case 3000000: baud = B3000000; break;
# endif
# ifdef B3500000
case 3500000: baud = B3500000; break;
# endif
# ifdef B4000000
case 4000000: baud = B4000000; break;
# endif
default:
ec = boost::asio::error::invalid_argument;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
# if defined(_BSD_SOURCE) || defined(_DEFAULT_SOURCE)
::cfsetspeed(&storage, baud);
# else
::cfsetispeed(&storage, baud);
::cfsetospeed(&storage, baud);
# endif
#endif
ec = boost::system::error_code();
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
BOOST_ASIO_SYNC_OP_VOID serial_port_base::baud_rate::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
value_ = storage.BaudRate;
#else
speed_t baud = ::cfgetospeed(&storage);
switch (baud)
{
// First do those specified by POSIX.
case B0: value_ = 0; break;
case B50: value_ = 50; break;
case B75: value_ = 75; break;
case B110: value_ = 110; break;
case B134: value_ = 134; break;
case B150: value_ = 150; break;
case B200: value_ = 200; break;
case B300: value_ = 300; break;
case B600: value_ = 600; break;
case B1200: value_ = 1200; break;
case B1800: value_ = 1800; break;
case B2400: value_ = 2400; break;
case B4800: value_ = 4800; break;
case B9600: value_ = 9600; break;
case B19200: value_ = 19200; break;
case B38400: value_ = 38400; break;
// Now conditionally handle a bunch of extended rates.
# ifdef B7200
case B7200: value_ = 7200; break;
# endif
# ifdef B14400
case B14400: value_ = 14400; break;
# endif
# ifdef B57600
case B57600: value_ = 57600; break;
# endif
# ifdef B115200
case B115200: value_ = 115200; break;
# endif
# ifdef B230400
case B230400: value_ = 230400; break;
# endif
# ifdef B460800
case B460800: value_ = 460800; break;
# endif
# ifdef B500000
case B500000: value_ = 500000; break;
# endif
# ifdef B576000
case B576000: value_ = 576000; break;
# endif
# ifdef B921600
case B921600: value_ = 921600; break;
# endif
# ifdef B1000000
case B1000000: value_ = 1000000; break;
# endif
# ifdef B1152000
case B1152000: value_ = 1152000; break;
# endif
# ifdef B2000000
case B2000000: value_ = 2000000; break;
# endif
# ifdef B3000000
case B3000000: value_ = 3000000; break;
# endif
# ifdef B3500000
case B3500000: value_ = 3500000; break;
# endif
# ifdef B4000000
case B4000000: value_ = 4000000; break;
# endif
default:
value_ = 0;
ec = boost::asio::error::invalid_argument;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
#endif
ec = boost::system::error_code();
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
serial_port_base::flow_control::flow_control(
serial_port_base::flow_control::type t)
: value_(t)
{
if (t != none && t != software && t != hardware)
{
std::out_of_range ex("invalid flow_control value");
boost::asio::detail::throw_exception(ex);
}
}
BOOST_ASIO_SYNC_OP_VOID serial_port_base::flow_control::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
storage.fOutxCtsFlow = FALSE;
storage.fOutxDsrFlow = FALSE;
storage.fTXContinueOnXoff = TRUE;
storage.fDtrControl = DTR_CONTROL_ENABLE;
storage.fDsrSensitivity = FALSE;
storage.fOutX = FALSE;
storage.fInX = FALSE;
storage.fRtsControl = RTS_CONTROL_ENABLE;
switch (value_)
{
case none:
break;
case software:
storage.fOutX = TRUE;
storage.fInX = TRUE;
break;
case hardware:
storage.fOutxCtsFlow = TRUE;
storage.fRtsControl = RTS_CONTROL_HANDSHAKE;
break;
default:
break;
}
#else
switch (value_)
{
case none:
storage.c_iflag &= ~(IXOFF | IXON);
# if defined(_BSD_SOURCE) || defined(_DEFAULT_SOURCE)
storage.c_cflag &= ~CRTSCTS;
# elif defined(__QNXNTO__)
storage.c_cflag &= ~(IHFLOW | OHFLOW);
# endif
break;
case software:
storage.c_iflag |= IXOFF | IXON;
# if defined(_BSD_SOURCE) || defined(_DEFAULT_SOURCE)
storage.c_cflag &= ~CRTSCTS;
# elif defined(__QNXNTO__)
storage.c_cflag &= ~(IHFLOW | OHFLOW);
# endif
break;
case hardware:
# if defined(_BSD_SOURCE) || defined(_DEFAULT_SOURCE)
storage.c_iflag &= ~(IXOFF | IXON);
storage.c_cflag |= CRTSCTS;
break;
# elif defined(__QNXNTO__)
storage.c_iflag &= ~(IXOFF | IXON);
storage.c_cflag |= (IHFLOW | OHFLOW);
break;
# else
ec = boost::asio::error::operation_not_supported;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
# endif
default:
break;
}
#endif
ec = boost::system::error_code();
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
BOOST_ASIO_SYNC_OP_VOID serial_port_base::flow_control::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
if (storage.fOutX && storage.fInX)
{
value_ = software;
}
else if (storage.fOutxCtsFlow && storage.fRtsControl == RTS_CONTROL_HANDSHAKE)
{
value_ = hardware;
}
else
{
value_ = none;
}
#else
if (storage.c_iflag & (IXOFF | IXON))
{
value_ = software;
}
# if defined(_BSD_SOURCE) || defined(_DEFAULT_SOURCE)
else if (storage.c_cflag & CRTSCTS)
{
value_ = hardware;
}
# elif defined(__QNXNTO__)
else if (storage.c_cflag & IHFLOW && storage.c_cflag & OHFLOW)
{
value_ = hardware;
}
# endif
else
{
value_ = none;
}
#endif
ec = boost::system::error_code();
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
serial_port_base::parity::parity(serial_port_base::parity::type t)
: value_(t)
{
if (t != none && t != odd && t != even)
{
std::out_of_range ex("invalid parity value");
boost::asio::detail::throw_exception(ex);
}
}
BOOST_ASIO_SYNC_OP_VOID serial_port_base::parity::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
switch (value_)
{
case none:
storage.fParity = FALSE;
storage.Parity = NOPARITY;
break;
case odd:
storage.fParity = TRUE;
storage.Parity = ODDPARITY;
break;
case even:
storage.fParity = TRUE;
storage.Parity = EVENPARITY;
break;
default:
break;
}
#else
switch (value_)
{
case none:
storage.c_iflag |= IGNPAR;
storage.c_cflag &= ~(PARENB | PARODD);
break;
case even:
storage.c_iflag &= ~(IGNPAR | PARMRK);
storage.c_iflag |= INPCK;
storage.c_cflag |= PARENB;
storage.c_cflag &= ~PARODD;
break;
case odd:
storage.c_iflag &= ~(IGNPAR | PARMRK);
storage.c_iflag |= INPCK;
storage.c_cflag |= (PARENB | PARODD);
break;
default:
break;
}
#endif
ec = boost::system::error_code();
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
BOOST_ASIO_SYNC_OP_VOID serial_port_base::parity::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
if (storage.Parity == EVENPARITY)
{
value_ = even;
}
else if (storage.Parity == ODDPARITY)
{
value_ = odd;
}
else
{
value_ = none;
}
#else
if (storage.c_cflag & PARENB)
{
if (storage.c_cflag & PARODD)
{
value_ = odd;
}
else
{
value_ = even;
}
}
else
{
value_ = none;
}
#endif
ec = boost::system::error_code();
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
serial_port_base::stop_bits::stop_bits(
serial_port_base::stop_bits::type t)
: value_(t)
{
if (t != one && t != onepointfive && t != two)
{
std::out_of_range ex("invalid stop_bits value");
boost::asio::detail::throw_exception(ex);
}
}
BOOST_ASIO_SYNC_OP_VOID serial_port_base::stop_bits::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
switch (value_)
{
case one:
storage.StopBits = ONESTOPBIT;
break;
case onepointfive:
storage.StopBits = ONE5STOPBITS;
break;
case two:
storage.StopBits = TWOSTOPBITS;
break;
default:
break;
}
#else
switch (value_)
{
case one:
storage.c_cflag &= ~CSTOPB;
break;
case two:
storage.c_cflag |= CSTOPB;
break;
default:
ec = boost::asio::error::operation_not_supported;
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
#endif
ec = boost::system::error_code();
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
BOOST_ASIO_SYNC_OP_VOID serial_port_base::stop_bits::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
if (storage.StopBits == ONESTOPBIT)
{
value_ = one;
}
else if (storage.StopBits == ONE5STOPBITS)
{
value_ = onepointfive;
}
else if (storage.StopBits == TWOSTOPBITS)
{
value_ = two;
}
else
{
value_ = one;
}
#else
value_ = (storage.c_cflag & CSTOPB) ? two : one;
#endif
ec = boost::system::error_code();
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
serial_port_base::character_size::character_size(unsigned int t)
: value_(t)
{
if (t < 5 || t > 8)
{
std::out_of_range ex("invalid character_size value");
boost::asio::detail::throw_exception(ex);
}
}
BOOST_ASIO_SYNC_OP_VOID serial_port_base::character_size::store(
BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec) const
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
storage.ByteSize = value_;
#else
storage.c_cflag &= ~CSIZE;
switch (value_)
{
case 5: storage.c_cflag |= CS5; break;
case 6: storage.c_cflag |= CS6; break;
case 7: storage.c_cflag |= CS7; break;
case 8: storage.c_cflag |= CS8; break;
default: break;
}
#endif
ec = boost::system::error_code();
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
BOOST_ASIO_SYNC_OP_VOID serial_port_base::character_size::load(
const BOOST_ASIO_OPTION_STORAGE& storage, boost::system::error_code& ec)
{
#if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
value_ = storage.ByteSize;
#else
if ((storage.c_cflag & CSIZE) == CS5) { value_ = 5; }
else if ((storage.c_cflag & CSIZE) == CS6) { value_ = 6; }
else if ((storage.c_cflag & CSIZE) == CS7) { value_ = 7; }
else if ((storage.c_cflag & CSIZE) == CS8) { value_ = 8; }
else
{
// Hmmm, use 8 for now.
value_ = 8;
}
#endif
ec = boost::system::error_code();
BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#undef BOOST_ASIO_OPTION_STORAGE
#endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
#endif // BOOST_ASIO_IMPL_SERIAL_PORT_BASE_IPP

View File

@@ -0,0 +1,519 @@
//
// impl/spawn.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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 <boost/asio/associated_allocator.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/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
#include <boost/asio/detail/memory.hpp>
#include <boost/asio/detail/noncopyable.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 {
template <typename Handler, typename T>
class coro_handler
{
public:
coro_handler(basic_yield_context<Handler> ctx)
: coro_(ctx.coro_.lock()),
ca_(ctx.ca_),
handler_(ctx.handler_),
ready_(0),
ec_(ctx.ec_),
value_(0)
{
}
void operator()(T value)
{
*ec_ = boost::system::error_code();
*value_ = BOOST_ASIO_MOVE_CAST(T)(value);
if (--*ready_ == 0)
(*coro_)();
}
void operator()(boost::system::error_code ec, T value)
{
*ec_ = ec;
*value_ = BOOST_ASIO_MOVE_CAST(T)(value);
if (--*ready_ == 0)
(*coro_)();
}
//private:
shared_ptr<typename basic_yield_context<Handler>::callee_type> coro_;
typename basic_yield_context<Handler>::caller_type& ca_;
Handler handler_;
atomic_count* ready_;
boost::system::error_code* ec_;
T* value_;
};
template <typename Handler>
class coro_handler<Handler, void>
{
public:
coro_handler(basic_yield_context<Handler> ctx)
: coro_(ctx.coro_.lock()),
ca_(ctx.ca_),
handler_(ctx.handler_),
ready_(0),
ec_(ctx.ec_)
{
}
void operator()()
{
*ec_ = boost::system::error_code();
if (--*ready_ == 0)
(*coro_)();
}
void operator()(boost::system::error_code ec)
{
*ec_ = ec;
if (--*ready_ == 0)
(*coro_)();
}
//private:
shared_ptr<typename basic_yield_context<Handler>::callee_type> coro_;
typename basic_yield_context<Handler>::caller_type& ca_;
Handler handler_;
atomic_count* ready_;
boost::system::error_code* ec_;
};
template <typename Handler, typename T>
inline asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
coro_handler<Handler, T>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Handler, typename T>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
coro_handler<Handler, T>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Handler, typename T>
inline bool asio_handler_is_continuation(coro_handler<Handler, T>*)
{
return true;
}
template <typename Function, typename Handler, typename T>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
coro_handler<Handler, T>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename Handler, typename T>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
coro_handler<Handler, T>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Handler, typename T>
class coro_async_result
{
public:
typedef coro_handler<Handler, T> completion_handler_type;
typedef T return_type;
explicit coro_async_result(completion_handler_type& h)
: handler_(h),
ca_(h.ca_),
ready_(2)
{
h.ready_ = &ready_;
out_ec_ = h.ec_;
if (!out_ec_) h.ec_ = &ec_;
h.value_ = &value_;
}
return_type get()
{
// Must not hold shared_ptr to coro while suspended.
handler_.coro_.reset();
if (--ready_ != 0)
ca_();
if (!out_ec_ && ec_) throw boost::system::system_error(ec_);
return BOOST_ASIO_MOVE_CAST(return_type)(value_);
}
private:
completion_handler_type& handler_;
typename basic_yield_context<Handler>::caller_type& ca_;
atomic_count ready_;
boost::system::error_code* out_ec_;
boost::system::error_code ec_;
return_type value_;
};
template <typename Handler>
class coro_async_result<Handler, void>
{
public:
typedef coro_handler<Handler, void> completion_handler_type;
typedef void return_type;
explicit coro_async_result(completion_handler_type& h)
: handler_(h),
ca_(h.ca_),
ready_(2)
{
h.ready_ = &ready_;
out_ec_ = h.ec_;
if (!out_ec_) h.ec_ = &ec_;
}
void get()
{
// Must not hold shared_ptr to coro while suspended.
handler_.coro_.reset();
if (--ready_ != 0)
ca_();
if (!out_ec_ && ec_) throw boost::system::system_error(ec_);
}
private:
completion_handler_type& handler_;
typename basic_yield_context<Handler>::caller_type& ca_;
atomic_count ready_;
boost::system::error_code* out_ec_;
boost::system::error_code ec_;
};
} // namespace detail
#if !defined(GENERATING_DOCUMENTATION)
template <typename Handler, typename ReturnType>
class async_result<basic_yield_context<Handler>, ReturnType()>
: public detail::coro_async_result<Handler, void>
{
public:
explicit async_result(
typename detail::coro_async_result<Handler,
void>::completion_handler_type& h)
: detail::coro_async_result<Handler, void>(h)
{
}
};
template <typename Handler, typename ReturnType, typename Arg1>
class async_result<basic_yield_context<Handler>, ReturnType(Arg1)>
: public detail::coro_async_result<Handler, typename decay<Arg1>::type>
{
public:
explicit async_result(
typename detail::coro_async_result<Handler,
typename decay<Arg1>::type>::completion_handler_type& h)
: detail::coro_async_result<Handler, typename decay<Arg1>::type>(h)
{
}
};
template <typename Handler, typename ReturnType>
class async_result<basic_yield_context<Handler>,
ReturnType(boost::system::error_code)>
: public detail::coro_async_result<Handler, void>
{
public:
explicit async_result(
typename detail::coro_async_result<Handler,
void>::completion_handler_type& h)
: detail::coro_async_result<Handler, void>(h)
{
}
};
template <typename Handler, typename ReturnType, typename Arg2>
class async_result<basic_yield_context<Handler>,
ReturnType(boost::system::error_code, Arg2)>
: public detail::coro_async_result<Handler, typename decay<Arg2>::type>
{
public:
explicit async_result(
typename detail::coro_async_result<Handler,
typename decay<Arg2>::type>::completion_handler_type& h)
: detail::coro_async_result<Handler, typename decay<Arg2>::type>(h)
{
}
};
template <template <typename, typename> class Associator,
typename Handler, typename T, typename DefaultCandidate>
struct associator<Associator,
detail::coro_handler<Handler, T>,
DefaultCandidate>
: Associator<Handler, DefaultCandidate>
{
static typename Associator<Handler, DefaultCandidate>::type get(
const detail::coro_handler<Handler, T>& h,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
}
};
namespace detail {
template <typename Handler, typename Function>
struct spawn_data : private noncopyable
{
template <typename Hand, typename Func>
spawn_data(BOOST_ASIO_MOVE_ARG(Hand) handler,
bool call_handler, BOOST_ASIO_MOVE_ARG(Func) function)
: handler_(BOOST_ASIO_MOVE_CAST(Hand)(handler)),
call_handler_(call_handler),
function_(BOOST_ASIO_MOVE_CAST(Func)(function))
{
}
weak_ptr<typename basic_yield_context<Handler>::callee_type> coro_;
Handler handler_;
bool call_handler_;
Function function_;
};
template <typename Handler, typename Function>
struct coro_entry_point
{
void operator()(typename basic_yield_context<Handler>::caller_type& ca)
{
shared_ptr<spawn_data<Handler, Function> > data(data_);
#if !defined(BOOST_COROUTINES_UNIDIRECT) && !defined(BOOST_COROUTINES_V2)
ca(); // Yield until coroutine pointer has been initialised.
#endif // !defined(BOOST_COROUTINES_UNIDIRECT) && !defined(BOOST_COROUTINES_V2)
const basic_yield_context<Handler> yield(
data->coro_, ca, data->handler_);
(data->function_)(yield);
if (data->call_handler_)
BOOST_ASIO_MOVE_OR_LVALUE(Handler)(data->handler_)();
}
shared_ptr<spawn_data<Handler, Function> > data_;
};
template <typename Handler, typename Function>
struct spawn_helper
{
typedef typename associated_allocator<Handler>::type allocator_type;
allocator_type get_allocator() const BOOST_ASIO_NOEXCEPT
{
return (get_associated_allocator)(data_->handler_);
}
typedef typename associated_executor<Handler>::type executor_type;
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return (get_associated_executor)(data_->handler_);
}
void operator()()
{
typedef typename basic_yield_context<Handler>::callee_type callee_type;
coro_entry_point<Handler, Function> entry_point = { data_ };
shared_ptr<callee_type> coro(new callee_type(entry_point, attributes_));
data_->coro_ = coro;
(*coro)();
}
shared_ptr<spawn_data<Handler, Function> > data_;
boost::coroutines::attributes attributes_;
};
template <typename Function, typename Handler, typename Function1>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
spawn_helper<Handler, Function1>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->data_->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename Handler, typename Function1>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
spawn_helper<Handler, Function1>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->data_->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
inline void default_spawn_handler() {}
} // namespace detail
template <typename Function>
inline void spawn(BOOST_ASIO_MOVE_ARG(Function) function,
const boost::coroutines::attributes& attributes)
{
typedef typename decay<Function>::type function_type;
typename associated_executor<function_type>::type ex(
(get_associated_executor)(function));
boost::asio::spawn(ex, BOOST_ASIO_MOVE_CAST(Function)(function), attributes);
}
template <typename Handler, typename Function>
void spawn(BOOST_ASIO_MOVE_ARG(Handler) handler,
BOOST_ASIO_MOVE_ARG(Function) function,
const boost::coroutines::attributes& attributes,
typename constraint<
!is_executor<typename decay<Handler>::type>::value &&
!execution::is_executor<typename decay<Handler>::type>::value &&
!is_convertible<Handler&, execution_context&>::value>::type)
{
typedef typename decay<Handler>::type handler_type;
typedef typename decay<Function>::type function_type;
detail::spawn_helper<handler_type, function_type> helper;
helper.data_.reset(
new detail::spawn_data<handler_type, function_type>(
BOOST_ASIO_MOVE_CAST(Handler)(handler), true,
BOOST_ASIO_MOVE_CAST(Function)(function)));
helper.attributes_ = attributes;
boost::asio::dispatch(helper);
}
template <typename Handler, typename Function>
void spawn(basic_yield_context<Handler> ctx,
BOOST_ASIO_MOVE_ARG(Function) function,
const boost::coroutines::attributes& attributes)
{
typedef typename decay<Function>::type function_type;
Handler handler(ctx.handler_); // Explicit copy that might be moved from.
detail::spawn_helper<Handler, function_type> helper;
helper.data_.reset(
new detail::spawn_data<Handler, function_type>(
BOOST_ASIO_MOVE_CAST(Handler)(handler), false,
BOOST_ASIO_MOVE_CAST(Function)(function)));
helper.attributes_ = attributes;
boost::asio::dispatch(helper);
}
template <typename Function, typename Executor>
inline void spawn(const Executor& ex,
BOOST_ASIO_MOVE_ARG(Function) function,
const boost::coroutines::attributes& attributes,
typename constraint<
is_executor<Executor>::value || execution::is_executor<Executor>::value
>::type)
{
boost::asio::spawn(boost::asio::strand<Executor>(ex),
BOOST_ASIO_MOVE_CAST(Function)(function), attributes);
}
template <typename Function, typename Executor>
inline void spawn(const strand<Executor>& ex,
BOOST_ASIO_MOVE_ARG(Function) function,
const boost::coroutines::attributes& attributes)
{
boost::asio::spawn(boost::asio::bind_executor(
ex, &detail::default_spawn_handler),
BOOST_ASIO_MOVE_CAST(Function)(function), attributes);
}
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Function>
inline void spawn(const boost::asio::io_context::strand& s,
BOOST_ASIO_MOVE_ARG(Function) function,
const boost::coroutines::attributes& attributes)
{
boost::asio::spawn(boost::asio::bind_executor(
s, &detail::default_spawn_handler),
BOOST_ASIO_MOVE_CAST(Function)(function), attributes);
}
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
template <typename Function, typename ExecutionContext>
inline void spawn(ExecutionContext& ctx,
BOOST_ASIO_MOVE_ARG(Function) function,
const boost::coroutines::attributes& attributes,
typename constraint<is_convertible<
ExecutionContext&, execution_context&>::value>::type)
{
boost::asio::spawn(ctx.get_executor(),
BOOST_ASIO_MOVE_CAST(Function)(function), attributes);
}
#endif // !defined(GENERATING_DOCUMENTATION)
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_SPAWN_HPP

View File

@@ -0,0 +1,94 @@
//
// impl/src.hpp
// ~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_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/handler_alloc_hook.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/execution/impl/receiver_invocation_error.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

View File

@@ -0,0 +1,36 @@
//
// impl/system_context.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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() BOOST_ASIO_NOEXCEPT
{
return system_executor();
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_SYSTEM_CONTEXT_HPP

View File

@@ -0,0 +1,94 @@
//
// impl/system_context.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_IPP
#define BOOST_ASIO_IMPL_SYSTEM_CONTEXT_IPP
#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/system_context.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
struct system_context::thread_function
{
detail::scheduler* scheduler_;
void operator()()
{
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
{
#endif// !defined(BOOST_ASIO_NO_EXCEPTIONS)
boost::system::error_code ec;
scheduler_->run(ec);
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
catch (...)
{
std::terminate();
}
#endif// !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
};
system_context::system_context()
: scheduler_(add_scheduler(new detail::scheduler(*this, 0, false)))
{
scheduler_.work_started();
thread_function f = { &scheduler_ };
num_threads_ = detail::thread::hardware_concurrency() * 2;
num_threads_ = num_threads_ ? num_threads_ : 2;
threads_.create_threads(f, num_threads_);
}
system_context::~system_context()
{
scheduler_.work_finished();
scheduler_.stop();
threads_.join();
}
void system_context::stop()
{
scheduler_.stop();
}
bool system_context::stopped() const BOOST_ASIO_NOEXCEPT
{
return scheduler_.stopped();
}
void system_context::join()
{
scheduler_.work_finished();
threads_.join();
}
detail::scheduler& system_context::add_scheduler(detail::scheduler* s)
{
detail::scoped_ptr<detail::scheduler> scoped_impl(s);
boost::asio::add_service<detail::scheduler>(*this, scoped_impl.get());
return *scoped_impl.release();
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_SYSTEM_CONTEXT_IPP

View File

@@ -0,0 +1,187 @@
//
// impl/system_executor.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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) BOOST_ASIO_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 BOOST_ASIO_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(
BOOST_ASIO_MOVE_ARG(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);
boost_asio_handler_invoke_helpers::invoke(f2.value, 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(
BOOST_ASIO_MOVE_ARG(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);
boost_asio_handler_invoke_helpers::invoke(f2.value, 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(
BOOST_ASIO_MOVE_ARG(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 typename decay<Function>::type function_type;
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(BOOST_ASIO_MOVE_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 BOOST_ASIO_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(
BOOST_ASIO_MOVE_ARG(Function) f, const OtherAllocator&) const
{
typename decay<Function>::type tmp(BOOST_ASIO_MOVE_CAST(Function)(f));
boost_asio_handler_invoke_helpers::invoke(tmp, tmp);
}
template <typename Blocking, typename Relationship, typename Allocator>
template <typename Function, typename OtherAllocator>
void basic_system_executor<Blocking, Relationship, Allocator>::post(
BOOST_ASIO_MOVE_ARG(Function) f, const OtherAllocator& a) const
{
typedef typename decay<Function>::type function_type;
system_context& ctx = detail::global<system_context>();
// 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(BOOST_ASIO_MOVE_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(
BOOST_ASIO_MOVE_ARG(Function) f, const OtherAllocator& a) const
{
typedef typename decay<Function>::type function_type;
system_context& ctx = detail::global<system_context>();
// 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(BOOST_ASIO_MOVE_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

View File

@@ -0,0 +1,356 @@
//
// impl/thread_pool.hpp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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/bulk_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() BOOST_ASIO_NOEXCEPT
{
return executor_type(*this);
}
inline thread_pool::executor_type
thread_pool::executor() BOOST_ASIO_NOEXCEPT
{
return executor_type(*this);
}
inline thread_pool::scheduler_type
thread_pool::scheduler() BOOST_ASIO_NOEXCEPT
{
return scheduler_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) BOOST_ASIO_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;
}
#if defined(BOOST_ASIO_HAS_MOVE)
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) BOOST_ASIO_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;
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
template <typename Allocator, unsigned int Bits>
inline bool thread_pool::basic_executor_type<Allocator,
Bits>::running_in_this_thread() const BOOST_ASIO_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(BOOST_ASIO_MOVE_ARG(Function) f, false_type) const
{
typedef typename decay<Function>::type 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(BOOST_ASIO_MOVE_CAST(Function)(f));
#if defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR) \
&& !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
{
#endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
// && !defined(BOOST_ASIO_NO_EXCEPTIONS)
detail::fenced_block b(detail::fenced_block::full);
boost_asio_handler_invoke_helpers::invoke(tmp, tmp);
return;
#if defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR) \
&& !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
catch (...)
{
pool_->scheduler_.capture_current_exception();
return;
}
#endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
// && !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(BOOST_ASIO_MOVE_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(BOOST_ASIO_MOVE_ARG(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);
boost_asio_handler_invoke_helpers::invoke(f2.value, 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 typename decay<Function>::type 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();
}
template <typename Allocator, unsigned int Bits>
template <typename Function>
void thread_pool::basic_executor_type<Allocator, Bits>::do_bulk_execute(
BOOST_ASIO_MOVE_ARG(Function) f, std::size_t n, false_type) const
{
typedef typename decay<Function>::type function_type;
typedef detail::bulk_executor_op<function_type, Allocator> op;
// Allocate and construct operations to wrap the function.
detail::op_queue<detail::scheduler_operation> ops;
for (std::size_t i = 0; i < n; ++i)
{
typename op::ptr p = { detail::addressof(allocator_),
op::ptr::allocate(allocator_), 0 };
p.p = new (p.v) op(BOOST_ASIO_MOVE_CAST(Function)(f), allocator_, i);
ops.push(p.p);
if ((bits_ & relationship_continuation) != 0)
{
BOOST_ASIO_HANDLER_CREATION((*pool_, *p.p,
"thread_pool", pool_, 0, "bulk_execute(blk=never,rel=cont)"));
}
else
{
BOOST_ASIO_HANDLER_CREATION((*pool_, *p.p,
"thread_pool", pool_, 0, "bulk)execute(blk=never,rel=fork)"));
}
p.v = p.p = 0;
}
pool_->scheduler_.post_immediate_completions(n,
ops, (bits_ & relationship_continuation) != 0);
}
template <typename Function>
struct thread_pool_always_blocking_function_adapter
{
typename decay<Function>::type* f;
std::size_t n;
void operator()()
{
for (std::size_t i = 0; i < n; ++i)
{
(*f)(i);
}
}
};
template <typename Allocator, unsigned int Bits>
template <typename Function>
void thread_pool::basic_executor_type<Allocator, Bits>::do_bulk_execute(
BOOST_ASIO_MOVE_ARG(Function) f, std::size_t n, true_type) const
{
// Obtain a non-const instance of the function.
detail::non_const_lvalue<Function> f2(f);
thread_pool_always_blocking_function_adapter<Function>
adapter = { detail::addressof(f2.value), n };
this->do_execute(adapter, true_type());
}
#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 BOOST_ASIO_NOEXCEPT
{
return *pool_;
}
template <typename Allocator, unsigned int Bits>
inline void thread_pool::basic_executor_type<Allocator,
Bits>::on_work_started() const BOOST_ASIO_NOEXCEPT
{
pool_->scheduler_.work_started();
}
template <typename Allocator, unsigned int Bits>
inline void thread_pool::basic_executor_type<Allocator,
Bits>::on_work_finished() const BOOST_ASIO_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(
BOOST_ASIO_MOVE_ARG(Function) f, const OtherAllocator& a) const
{
typedef typename decay<Function>::type 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(BOOST_ASIO_MOVE_CAST(Function)(f));
detail::fenced_block b(detail::fenced_block::full);
boost_asio_handler_invoke_helpers::invoke(tmp, 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(BOOST_ASIO_MOVE_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(
BOOST_ASIO_MOVE_ARG(Function) f, const OtherAllocator& a) const
{
typedef typename decay<Function>::type 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(BOOST_ASIO_MOVE_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(
BOOST_ASIO_MOVE_ARG(Function) f, const OtherAllocator& a) const
{
typedef typename decay<Function>::type 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(BOOST_ASIO_MOVE_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

View File

@@ -0,0 +1,143 @@
//
// impl/thread_pool.ipp
// ~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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_IPP
#define BOOST_ASIO_IMPL_THREAD_POOL_IPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#include <stdexcept>
#include <boost/asio/thread_pool.hpp>
#include <boost/asio/detail/throw_exception.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
struct thread_pool::thread_function
{
detail::scheduler* scheduler_;
void operator()()
{
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
try
{
#endif// !defined(BOOST_ASIO_NO_EXCEPTIONS)
boost::system::error_code ec;
scheduler_->run(ec);
#if !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
catch (...)
{
std::terminate();
}
#endif// !defined(BOOST_ASIO_NO_EXCEPTIONS)
}
};
#if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
namespace detail {
inline long default_thread_pool_size()
{
std::size_t num_threads = thread::hardware_concurrency() * 2;
num_threads = num_threads == 0 ? 2 : num_threads;
return static_cast<long>(num_threads);
}
} // namespace detail
thread_pool::thread_pool()
: scheduler_(add_scheduler(new detail::scheduler(*this, 0, false))),
num_threads_(detail::default_thread_pool_size())
{
scheduler_.work_started();
thread_function f = { &scheduler_ };
threads_.create_threads(f, static_cast<std::size_t>(num_threads_));
}
#endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
namespace detail {
inline long clamp_thread_pool_size(std::size_t n)
{
if (n > 0x7FFFFFFF)
{
std::out_of_range ex("thread pool size");
boost::asio::detail::throw_exception(ex);
}
return static_cast<long>(n & 0x7FFFFFFF);
}
} // namespace detail
thread_pool::thread_pool(std::size_t num_threads)
: scheduler_(add_scheduler(new detail::scheduler(
*this, num_threads == 1 ? 1 : 0, false))),
num_threads_(detail::clamp_thread_pool_size(num_threads))
{
scheduler_.work_started();
thread_function f = { &scheduler_ };
threads_.create_threads(f, static_cast<std::size_t>(num_threads_));
}
thread_pool::~thread_pool()
{
stop();
join();
}
void thread_pool::stop()
{
scheduler_.stop();
}
void thread_pool::attach()
{
++num_threads_;
thread_function f = { &scheduler_ };
f();
}
void thread_pool::join()
{
if (!threads_.empty())
{
scheduler_.work_finished();
threads_.join();
}
}
detail::scheduler& thread_pool::add_scheduler(detail::scheduler* s)
{
detail::scoped_ptr<detail::scheduler> scoped_impl(s);
boost::asio::add_service<detail::scheduler>(*this, scoped_impl.get());
return *scoped_impl.release();
}
void thread_pool::wait()
{
scheduler_.work_finished();
threads_.join();
}
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // BOOST_ASIO_IMPL_THREAD_POOL_IPP

View File

@@ -0,0 +1,303 @@
//
// impl/use_awaitable.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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, typename decay<Args>::type...> 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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,646 @@
//
// impl/write_at.hpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 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/completion_condition.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_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_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),
BOOST_ASIO_MOVE_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,
BOOST_ASIO_MOVE_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(),
BOOST_ASIO_MOVE_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,
BOOST_ASIO_MOVE_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_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
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>(
BOOST_ASIO_MOVE_CAST(base_from_cancellation_state<
WriteHandler>)(other)),
base_from_completion_cond<CompletionCondition>(
BOOST_ASIO_MOVE_CAST(base_from_completion_cond<
CompletionCondition>)(other)),
device_(other.device_),
offset_(other.offset_),
buffers_(BOOST_ASIO_MOVE_CAST(buffers_type)(other.buffers_)),
start_(other.start_),
handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
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),
BOOST_ASIO_MOVE_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;
}
}
BOOST_ASIO_MOVE_OR_LVALUE(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 asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
ConstBufferIterator, CompletionCondition, WriteHandler>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename AsyncRandomAccessWriteDevice,
typename ConstBufferSequence, typename ConstBufferIterator,
typename CompletionCondition, typename WriteHandler>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
ConstBufferIterator, CompletionCondition, WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 Function, typename AsyncRandomAccessWriteDevice,
typename ConstBufferSequence, typename ConstBufferIterator,
typename CompletionCondition, typename WriteHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
ConstBufferIterator, CompletionCondition, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename AsyncRandomAccessWriteDevice,
typename ConstBufferSequence, typename ConstBufferIterator,
typename CompletionCondition, typename WriteHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
ConstBufferIterator, CompletionCondition, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename AsyncRandomAccessWriteDevice,
typename ConstBufferSequence, typename ConstBufferIterator,
typename CompletionCondition, typename WriteHandler>
inline void start_write_at_buffer_sequence_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_buffer_sequence
{
public:
typedef typename AsyncRandomAccessWriteDevice::executor_type executor_type;
explicit initiate_async_write_at_buffer_sequence(
AsyncRandomAccessWriteDevice& device)
: device_(device)
{
}
executor_type get_executor() const BOOST_ASIO_NOEXCEPT
{
return device_.get_executor();
}
template <typename WriteHandler, typename ConstBufferSequence,
typename CompletionCondition>
void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
uint64_t offset, const ConstBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(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_buffer_sequence_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,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
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 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
void (boost::system::error_code, std::size_t))
async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(WriteToken) token)
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_at_buffer_sequence<
AsyncRandomAccessWriteDevice>(d),
token, offset, buffers,
BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
}
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
void (boost::system::error_code, std::size_t))
async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, const ConstBufferSequence& buffers,
BOOST_ASIO_MOVE_ARG(WriteToken) token)
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_at_buffer_sequence<
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_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
{
}
#if defined(BOOST_ASIO_HAS_MOVE)
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_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
{
}
#endif // defined(BOOST_ASIO_HAS_MOVE)
void operator()(const boost::system::error_code& ec,
const std::size_t bytes_transferred)
{
streambuf_.consume(bytes_transferred);
BOOST_ASIO_MOVE_OR_LVALUE(WriteHandler)(handler_)(ec, bytes_transferred);
}
//private:
boost::asio::basic_streambuf<Allocator>& streambuf_;
WriteHandler handler_;
};
template <typename Allocator, typename WriteHandler>
inline asio_handler_allocate_is_deprecated
asio_handler_allocate(std::size_t size,
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
#if defined(BOOST_ASIO_NO_DEPRECATED)
boost_asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
return asio_handler_allocate_is_no_longer_used();
#else // defined(BOOST_ASIO_NO_DEPRECATED)
return boost_asio_handler_alloc_helpers::allocate(
size, this_handler->handler_);
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Allocator, typename WriteHandler>
inline asio_handler_deallocate_is_deprecated
asio_handler_deallocate(void* pointer, std::size_t size,
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
boost_asio_handler_alloc_helpers::deallocate(
pointer, size, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_deallocate_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 Function, typename Allocator, typename WriteHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(Function& function,
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
template <typename Function, typename Allocator, typename WriteHandler>
inline asio_handler_invoke_is_deprecated
asio_handler_invoke(const Function& function,
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
{
boost_asio_handler_invoke_helpers::invoke(
function, this_handler->handler_);
#if defined(BOOST_ASIO_NO_DEPRECATED)
return asio_handler_invoke_is_no_longer_used();
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
}
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 BOOST_ASIO_NOEXCEPT
{
return device_.get_executor();
}
template <typename WriteHandler,
typename Allocator, typename CompletionCondition>
void operator()(BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
uint64_t offset, basic_streambuf<Allocator>* b,
BOOST_ASIO_MOVE_ARG(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(),
BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition),
write_at_streambuf_op<Allocator, typename decay<WriteHandler>::type>(
*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,
const DefaultCandidate& c = DefaultCandidate()) BOOST_ASIO_NOEXCEPT
{
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 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
void (boost::system::error_code, std::size_t))
async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(WriteToken) token)
{
return async_initiate<WriteToken,
void (boost::system::error_code, std::size_t)>(
detail::initiate_async_write_at_streambuf<
AsyncRandomAccessWriteDevice>(d),
token, offset, &b,
BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
}
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
std::size_t)) WriteToken>
inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(WriteToken,
void (boost::system::error_code, std::size_t))
async_write_at(AsyncRandomAccessWriteDevice& d,
uint64_t offset, boost::asio::basic_streambuf<Allocator>& b,
BOOST_ASIO_MOVE_ARG(WriteToken) token)
{
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