Initial commit
This commit is contained in:
436
extern/asio-1.18.2/include/asio/impl/awaitable.hpp
vendored
Normal file
436
extern/asio-1.18.2/include/asio/impl/awaitable.hpp
vendored
Normal file
@@ -0,0 +1,436 @@
|
||||
//
|
||||
// impl/awaitable.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_AWAITABLE_HPP
|
||||
#define ASIO_IMPL_AWAITABLE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <exception>
|
||||
#include <new>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include "asio/detail/thread_context.hpp"
|
||||
#include "asio/detail/thread_info_base.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/post.hpp"
|
||||
#include "asio/system_error.hpp"
|
||||
#include "asio/this_coro.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
// 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(ASIO_DISABLE_AWAITABLE_FRAME_RECYCLING)
|
||||
void* operator new(std::size_t size)
|
||||
{
|
||||
return asio::detail::thread_info_base::allocate(
|
||||
asio::detail::thread_info_base::awaitable_frame_tag(),
|
||||
asio::detail::thread_context::top_of_thread_call_stack(),
|
||||
size);
|
||||
}
|
||||
|
||||
void operator delete(void* pointer, std::size_t size)
|
||||
{
|
||||
asio::detail::thread_info_base::deallocate(
|
||||
asio::detail::thread_info_base::awaitable_frame_tag(),
|
||||
asio::detail::thread_context::top_of_thread_call_stack(),
|
||||
pointer, size);
|
||||
}
|
||||
#endif // !defined(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 asio::error_code& ec)
|
||||
{
|
||||
this->set_except(std::make_exception_ptr(asio::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);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto await_transform(awaitable<T, Executor> a) const
|
||||
{
|
||||
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 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* = 0)
|
||||
{
|
||||
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};
|
||||
}
|
||||
|
||||
void attach_thread(awaitable_thread<Executor>* handler) noexcept
|
||||
{
|
||||
attached_thread_ = handler;
|
||||
}
|
||||
|
||||
awaitable_thread<Executor>* detach_thread() noexcept
|
||||
{
|
||||
return std::exchange(attached_thread_, nullptr);
|
||||
}
|
||||
|
||||
void push_frame(awaitable_frame_base<Executor>* caller) noexcept
|
||||
{
|
||||
caller_ = caller;
|
||||
attached_thread_ = caller_->attached_thread_;
|
||||
attached_thread_->top_of_stack_ = this;
|
||||
caller_->attached_thread_ = nullptr;
|
||||
}
|
||||
|
||||
void pop_frame() noexcept
|
||||
{
|
||||
if (caller_)
|
||||
caller_->attached_thread_ = attached_thread_;
|
||||
attached_thread_->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();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Executor>
|
||||
class awaitable_thread
|
||||
{
|
||||
public:
|
||||
typedef Executor executor_type;
|
||||
|
||||
// Construct from the entry point of a new thread of execution.
|
||||
awaitable_thread(awaitable<void, Executor> p, const Executor& ex)
|
||||
: bottom_of_stack_(std::move(p)),
|
||||
top_of_stack_(bottom_of_stack_.frame_),
|
||||
executor_(ex)
|
||||
{
|
||||
}
|
||||
|
||||
// Transfer ownership from another awaitable_thread.
|
||||
awaitable_thread(awaitable_thread&& other) noexcept
|
||||
: bottom_of_stack_(std::move(other.bottom_of_stack_)),
|
||||
top_of_stack_(std::exchange(other.top_of_stack_, nullptr)),
|
||||
executor_(std::move(other.executor_))
|
||||
{
|
||||
}
|
||||
|
||||
// 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.
|
||||
(post)(executor_,
|
||||
[a = std::move(bottom_of_stack_)]() mutable
|
||||
{
|
||||
awaitable<void, Executor>(std::move(a));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
executor_type get_executor() const noexcept
|
||||
{
|
||||
return executor_;
|
||||
}
|
||||
|
||||
// Launch a new thread of execution.
|
||||
void launch()
|
||||
{
|
||||
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 top_of_stack_->resume(); while (top_of_stack_);
|
||||
if (bottom_of_stack_.valid())
|
||||
{
|
||||
awaitable<void, Executor> a(std::move(bottom_of_stack_));
|
||||
a.frame_->rethrow_exception();
|
||||
}
|
||||
}
|
||||
|
||||
awaitable<void, Executor> bottom_of_stack_;
|
||||
awaitable_frame_base<Executor>* top_of_stack_;
|
||||
executor_type executor_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace asio
|
||||
|
||||
#if !defined(GENERATING_DOCUMENTATION)
|
||||
# if defined(ASIO_HAS_STD_COROUTINE)
|
||||
|
||||
namespace std {
|
||||
|
||||
template <typename T, typename Executor, typename... Args>
|
||||
struct coroutine_traits<asio::awaitable<T, Executor>, Args...>
|
||||
{
|
||||
typedef asio::detail::awaitable_frame<T, Executor> promise_type;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
# else // defined(ASIO_HAS_STD_COROUTINE)
|
||||
|
||||
namespace std { namespace experimental {
|
||||
|
||||
template <typename T, typename Executor, typename... Args>
|
||||
struct coroutine_traits<asio::awaitable<T, Executor>, Args...>
|
||||
{
|
||||
typedef asio::detail::awaitable_frame<T, Executor> promise_type;
|
||||
};
|
||||
|
||||
}} // namespace std::experimental
|
||||
|
||||
# endif // defined(ASIO_HAS_STD_COROUTINE)
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_AWAITABLE_HPP
|
||||
529
extern/asio-1.18.2/include/asio/impl/buffered_read_stream.hpp
vendored
Normal file
529
extern/asio-1.18.2/include/asio/impl/buffered_read_stream.hpp
vendored
Normal file
@@ -0,0 +1,529 @@
|
||||
//
|
||||
// impl/buffered_read_stream.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_BUFFERED_READ_STREAM_HPP
|
||||
#define ASIO_IMPL_BUFFERED_READ_STREAM_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_cont_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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(asio::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_(ASIO_MOVE_CAST(ReadHandler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(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_(ASIO_MOVE_CAST(ReadHandler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()(const asio::error_code& ec,
|
||||
const std::size_t bytes_transferred)
|
||||
{
|
||||
storage_.resize(previous_size_ + bytes_transferred);
|
||||
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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
template <typename ReadHandler>
|
||||
inline bool asio_handler_is_continuation(
|
||||
buffered_fill_handler<ReadHandler>* this_handler)
|
||||
{
|
||||
return 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return next_layer_.lowest_layer().get_executor();
|
||||
}
|
||||
|
||||
template <typename ReadHandler>
|
||||
void operator()(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.
|
||||
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 <typename ReadHandler, typename Allocator>
|
||||
struct associated_allocator<
|
||||
detail::buffered_fill_handler<ReadHandler>, Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<ReadHandler, Allocator>::type type;
|
||||
|
||||
static type get(const detail::buffered_fill_handler<ReadHandler>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<ReadHandler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ReadHandler, typename Executor>
|
||||
struct associated_executor<
|
||||
detail::buffered_fill_handler<ReadHandler>, Executor>
|
||||
: detail::associated_executor_forwarding_base<ReadHandler, Executor>
|
||||
{
|
||||
typedef typename associated_executor<ReadHandler, Executor>::type type;
|
||||
|
||||
static type get(const detail::buffered_fill_handler<ReadHandler>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<ReadHandler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename Stream>
|
||||
template <
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
buffered_read_stream<Stream>::async_fill(
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::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 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, asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
|
||||
using 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_(ASIO_MOVE_CAST(ReadHandler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(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_(ASIO_MOVE_CAST(ReadHandler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()(const asio::error_code& ec, std::size_t)
|
||||
{
|
||||
if (ec || storage_.empty())
|
||||
{
|
||||
const std::size_t length = 0;
|
||||
handler_(ec, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::size_t bytes_copied = asio::buffer_copy(
|
||||
buffers_, storage_.data(), storage_.size());
|
||||
storage_.consume(bytes_copied);
|
||||
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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
inline bool asio_handler_is_continuation(
|
||||
buffered_read_some_handler<
|
||||
MutableBufferSequence, ReadHandler>* this_handler)
|
||||
{
|
||||
return 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return next_layer_.lowest_layer().get_executor();
|
||||
}
|
||||
|
||||
template <typename ReadHandler, typename MutableBufferSequence>
|
||||
void operator()(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.
|
||||
ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
|
||||
|
||||
using asio::buffer_size;
|
||||
non_const_lvalue<ReadHandler> handler2(handler);
|
||||
if (buffer_size(buffers) == 0 || !storage->empty())
|
||||
{
|
||||
next_layer_.async_read_some(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 <typename MutableBufferSequence,
|
||||
typename ReadHandler, typename Allocator>
|
||||
struct associated_allocator<
|
||||
detail::buffered_read_some_handler<MutableBufferSequence, ReadHandler>,
|
||||
Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<ReadHandler, Allocator>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::buffered_read_some_handler<
|
||||
MutableBufferSequence, ReadHandler>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<ReadHandler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename MutableBufferSequence,
|
||||
typename ReadHandler, typename Executor>
|
||||
struct associated_executor<
|
||||
detail::buffered_read_some_handler<MutableBufferSequence, ReadHandler>,
|
||||
Executor>
|
||||
: detail::associated_executor_forwarding_base<ReadHandler, Executor>
|
||||
{
|
||||
typedef typename associated_executor<ReadHandler, Executor>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::buffered_read_some_handler<
|
||||
MutableBufferSequence, ReadHandler>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<ReadHandler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename Stream>
|
||||
template <typename MutableBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
buffered_read_stream<Stream>::async_read_some(
|
||||
const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::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, asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
if (storage_.empty() && !this->fill(ec))
|
||||
return 0;
|
||||
return this->peek_copy(buffers);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_BUFFERED_READ_STREAM_HPP
|
||||
509
extern/asio-1.18.2/include/asio/impl/buffered_write_stream.hpp
vendored
Normal file
509
extern/asio-1.18.2/include/asio/impl/buffered_write_stream.hpp
vendored
Normal file
@@ -0,0 +1,509 @@
|
||||
//
|
||||
// impl/buffered_write_stream.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_BUFFERED_WRITE_STREAM_HPP
|
||||
#define ASIO_IMPL_BUFFERED_WRITE_STREAM_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_cont_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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(asio::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_(ASIO_MOVE_CAST(WriteHandler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(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_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()(const asio::error_code& ec,
|
||||
const std::size_t bytes_written)
|
||||
{
|
||||
storage_.consume(bytes_written);
|
||||
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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
template <typename WriteHandler>
|
||||
inline bool asio_handler_is_continuation(
|
||||
buffered_flush_handler<WriteHandler>* this_handler)
|
||||
{
|
||||
return 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return next_layer_.lowest_layer().get_executor();
|
||||
}
|
||||
|
||||
template <typename WriteHandler>
|
||||
void operator()(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.
|
||||
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 <typename WriteHandler, typename Allocator>
|
||||
struct associated_allocator<
|
||||
detail::buffered_flush_handler<WriteHandler>, Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<WriteHandler, Allocator>::type type;
|
||||
|
||||
static type get(const detail::buffered_flush_handler<WriteHandler>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<WriteHandler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename WriteHandler, typename Executor>
|
||||
struct associated_executor<
|
||||
detail::buffered_flush_handler<WriteHandler>, Executor>
|
||||
: detail::associated_executor_forwarding_base<WriteHandler, Executor>
|
||||
{
|
||||
typedef typename associated_executor<WriteHandler, Executor>::type type;
|
||||
|
||||
static type get(const detail::buffered_flush_handler<WriteHandler>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<WriteHandler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename Stream>
|
||||
template <
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
buffered_write_stream<Stream>::async_flush(
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::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 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, asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
|
||||
using 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_(ASIO_MOVE_CAST(WriteHandler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(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_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()(const asio::error_code& ec, std::size_t)
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
const std::size_t length = 0;
|
||||
handler_(ec, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
using 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 = asio::buffer_copy(
|
||||
storage_.data() + orig_size, buffers_, length);
|
||||
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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
inline bool asio_handler_is_continuation(
|
||||
buffered_write_some_handler<
|
||||
ConstBufferSequence, WriteHandler>* this_handler)
|
||||
{
|
||||
return 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return next_layer_.lowest_layer().get_executor();
|
||||
}
|
||||
|
||||
template <typename WriteHandler, typename ConstBufferSequence>
|
||||
void operator()(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.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
using asio::buffer_size;
|
||||
non_const_lvalue<WriteHandler> handler2(handler);
|
||||
if (buffer_size(buffers) == 0 || storage->size() < storage->capacity())
|
||||
{
|
||||
next_layer_.async_write_some(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 <typename ConstBufferSequence,
|
||||
typename WriteHandler, typename Allocator>
|
||||
struct associated_allocator<
|
||||
detail::buffered_write_some_handler<ConstBufferSequence, WriteHandler>,
|
||||
Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<WriteHandler, Allocator>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::buffered_write_some_handler<
|
||||
ConstBufferSequence, WriteHandler>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<WriteHandler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ConstBufferSequence,
|
||||
typename WriteHandler, typename Executor>
|
||||
struct associated_executor<
|
||||
detail::buffered_write_some_handler<ConstBufferSequence, WriteHandler>,
|
||||
Executor>
|
||||
: detail::associated_executor_forwarding_base<WriteHandler, Executor>
|
||||
{
|
||||
typedef typename associated_executor<WriteHandler, Executor>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::buffered_write_some_handler<
|
||||
ConstBufferSequence, WriteHandler>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<WriteHandler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename Stream>
|
||||
template <typename ConstBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
buffered_write_stream<Stream>::async_write_some(
|
||||
const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::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 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 asio::buffer_copy(
|
||||
storage_.data() + orig_size, buffers, length);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_BUFFERED_WRITE_STREAM_HPP
|
||||
298
extern/asio-1.18.2/include/asio/impl/co_spawn.hpp
vendored
Normal file
298
extern/asio-1.18.2/include/asio/impl/co_spawn.hpp
vendored
Normal file
@@ -0,0 +1,298 @@
|
||||
//
|
||||
// impl/co_spawn.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_CO_SPAWN_HPP
|
||||
#define ASIO_IMPL_CO_SPAWN_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/awaitable.hpp"
|
||||
#include "asio/dispatch.hpp"
|
||||
#include "asio/execution/outstanding_work.hpp"
|
||||
#include "asio/post.hpp"
|
||||
#include "asio/prefer.hpp"
|
||||
#include "asio/use_awaitable.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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_(asio::prefer(ex, execution::outstanding_work.tracked))
|
||||
{
|
||||
}
|
||||
|
||||
executor_type get_executor() const ASIO_NOEXCEPT
|
||||
{
|
||||
return executor_;
|
||||
}
|
||||
|
||||
private:
|
||||
executor_type executor_;
|
||||
};
|
||||
|
||||
#if !defined(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(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<void, 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(
|
||||
asio::get_associated_executor(handler, ex));
|
||||
|
||||
(void) co_await (post)(spawn_work.get_executor(),
|
||||
use_awaitable_t<Executor>{});
|
||||
|
||||
bool done = false;
|
||||
try
|
||||
{
|
||||
T t = co_await f();
|
||||
|
||||
done = true;
|
||||
|
||||
(dispatch)(handler_work.get_executor(),
|
||||
[handler = std::move(handler), t = std::move(t)]() mutable
|
||||
{
|
||||
handler(std::exception_ptr(), std::move(t));
|
||||
});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
if (done)
|
||||
throw;
|
||||
|
||||
(dispatch)(handler_work.get_executor(),
|
||||
[handler = std::move(handler), e = std::current_exception()]() mutable
|
||||
{
|
||||
handler(e, T());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Executor, typename F, typename Handler>
|
||||
awaitable<void, 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(
|
||||
asio::get_associated_executor(handler, ex));
|
||||
|
||||
(void) co_await (post)(spawn_work.get_executor(),
|
||||
use_awaitable_t<Executor>{__FILE__, __LINE__, "co_spawn_entry_point"});
|
||||
|
||||
std::exception_ptr e = nullptr;
|
||||
try
|
||||
{
|
||||
co_await f();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
e = std::current_exception();
|
||||
}
|
||||
|
||||
(dispatch)(handler_work.get_executor(),
|
||||
[handler = std::move(handler), e]() mutable
|
||||
{
|
||||
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 ASIO_NOEXCEPT
|
||||
{
|
||||
return ex_;
|
||||
}
|
||||
|
||||
template <typename Handler, typename F>
|
||||
void operator()(Handler&& handler, F&& f) const
|
||||
{
|
||||
typedef typename result_of<F()>::type awaitable_type;
|
||||
|
||||
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_).launch();
|
||||
}
|
||||
|
||||
private:
|
||||
Executor ex_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename Executor, typename T, typename AwaitableExecutor,
|
||||
ASIO_COMPLETION_TOKEN_FOR(
|
||||
void(std::exception_ptr, T)) CompletionToken>
|
||||
inline 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,
|
||||
ASIO_COMPLETION_TOKEN_FOR(
|
||||
void(std::exception_ptr)) CompletionToken>
|
||||
inline 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,
|
||||
ASIO_COMPLETION_TOKEN_FOR(
|
||||
void(std::exception_ptr, T)) CompletionToken>
|
||||
inline 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,
|
||||
ASIO_COMPLETION_TOKEN_FOR(
|
||||
void(std::exception_ptr)) CompletionToken>
|
||||
inline 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,
|
||||
ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
|
||||
typename result_of<F()>::type>::type) CompletionToken>
|
||||
inline 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,
|
||||
ASIO_COMPLETION_TOKEN_FOR(typename detail::awaitable_signature<
|
||||
typename result_of<F()>::type>::type) CompletionToken>
|
||||
inline 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
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_CO_SPAWN_HPP
|
||||
637
extern/asio-1.18.2/include/asio/impl/compose.hpp
vendored
Normal file
637
extern/asio-1.18.2/include/asio/impl/compose.hpp
vendored
Normal file
@@ -0,0 +1,637 @@
|
||||
//
|
||||
// impl/compose.hpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_COMPOSE_HPP
|
||||
#define ASIO_IMPL_COMPOSE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_cont_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/detail/variadic_templates.hpp"
|
||||
#include "asio/execution/executor.hpp"
|
||||
#include "asio/execution/outstanding_work.hpp"
|
||||
#include "asio/executor_work_guard.hpp"
|
||||
#include "asio/is_executor.hpp"
|
||||
#include "asio/system_executor.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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_(asio::prefer(ex, execution::outstanding_work.tracked))
|
||||
{
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
}
|
||||
|
||||
executor_type get_executor() const ASIO_NOEXCEPT
|
||||
{
|
||||
return executor_;
|
||||
}
|
||||
|
||||
private:
|
||||
executor_type executor_;
|
||||
};
|
||||
|
||||
#if !defined(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(ASIO_NO_TS_EXECUTORS)
|
||||
|
||||
template <typename>
|
||||
struct composed_io_executors;
|
||||
|
||||
template <>
|
||||
struct composed_io_executors<void()>
|
||||
{
|
||||
composed_io_executors() 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) 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(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) 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(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#define ASIO_PRIVATE_COMPOSED_IO_EXECUTORS_DEF(n) \
|
||||
template <typename Head, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
struct composed_io_executors<void(Head, ASIO_VARIADIC_TARGS(n))> \
|
||||
{ \
|
||||
explicit composed_io_executors(const Head& head, \
|
||||
ASIO_VARIADIC_CONSTREF_PARAMS(n)) ASIO_NOEXCEPT \
|
||||
: head_(head), \
|
||||
tail_(ASIO_VARIADIC_BYVAL_ARGS(n)) \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
void reset() \
|
||||
{ \
|
||||
head_.reset(); \
|
||||
tail_.reset(); \
|
||||
} \
|
||||
\
|
||||
typedef Head head_type; \
|
||||
Head head_; \
|
||||
composed_io_executors<void(ASIO_VARIADIC_TARGS(n))> tail_; \
|
||||
}; \
|
||||
\
|
||||
template <typename Head, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
inline composed_io_executors<void(Head, ASIO_VARIADIC_TARGS(n))> \
|
||||
make_composed_io_executors(const Head& head, \
|
||||
ASIO_VARIADIC_CONSTREF_PARAMS(n)) \
|
||||
{ \
|
||||
return composed_io_executors< \
|
||||
void(Head, ASIO_VARIADIC_TARGS(n))>( \
|
||||
head, ASIO_VARIADIC_BYVAL_ARGS(n)); \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_COMPOSED_IO_EXECUTORS_DEF)
|
||||
#undef ASIO_PRIVATE_COMPOSED_IO_EXECUTORS_DEF
|
||||
|
||||
#endif // defined(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&) 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) ASIO_NOEXCEPT
|
||||
: head_(ex.head_)
|
||||
{
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
head_.reset();
|
||||
}
|
||||
|
||||
typedef Head head_type;
|
||||
composed_work_guard<Head> head_;
|
||||
};
|
||||
|
||||
#if defined(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) 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(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#define ASIO_PRIVATE_COMPOSED_WORK_DEF(n) \
|
||||
template <typename Head, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
struct composed_work<void(Head, ASIO_VARIADIC_TARGS(n))> \
|
||||
{ \
|
||||
typedef composed_io_executors<void(Head, \
|
||||
ASIO_VARIADIC_TARGS(n))> executors_type; \
|
||||
\
|
||||
explicit composed_work(const executors_type& ex) 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(ASIO_VARIADIC_TARGS(n))> tail_; \
|
||||
}; \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_COMPOSED_WORK_DEF)
|
||||
#undef ASIO_PRIVATE_COMPOSED_WORK_DEF
|
||||
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
#if defined(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(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
template <typename Impl, typename Work, typename Handler, typename Signature>
|
||||
class composed_op
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
{
|
||||
public:
|
||||
template <typename I, typename W, typename H>
|
||||
composed_op(ASIO_MOVE_ARG(I) impl,
|
||||
ASIO_MOVE_ARG(W) work,
|
||||
ASIO_MOVE_ARG(H) handler)
|
||||
: impl_(ASIO_MOVE_CAST(I)(impl)),
|
||||
work_(ASIO_MOVE_CAST(W)(work)),
|
||||
handler_(ASIO_MOVE_CAST(H)(handler)),
|
||||
invocations_(0)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
composed_op(composed_op&& other)
|
||||
: impl_(ASIO_MOVE_CAST(Impl)(other.impl_)),
|
||||
work_(ASIO_MOVE_CAST(Work)(other.work_)),
|
||||
handler_(ASIO_MOVE_CAST(Handler)(other.handler_)),
|
||||
invocations_(other.invocations_)
|
||||
{
|
||||
}
|
||||
#endif // defined(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 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 ASIO_NOEXCEPT
|
||||
{
|
||||
return (get_associated_allocator)(handler_, std::allocator<void>());
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template<typename... T>
|
||||
void operator()(ASIO_MOVE_ARG(T)... t)
|
||||
{
|
||||
if (invocations_ < ~0u)
|
||||
++invocations_;
|
||||
impl_(*this, ASIO_MOVE_CAST(T)(t)...);
|
||||
}
|
||||
|
||||
void complete(Args... args)
|
||||
{
|
||||
this->work_.reset();
|
||||
this->handler_(ASIO_MOVE_CAST(Args)(args)...);
|
||||
}
|
||||
|
||||
#else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
void operator()()
|
||||
{
|
||||
if (invocations_ < ~0u)
|
||||
++invocations_;
|
||||
impl_(*this);
|
||||
}
|
||||
|
||||
void complete()
|
||||
{
|
||||
this->work_.reset();
|
||||
this->handler_();
|
||||
}
|
||||
|
||||
#define ASIO_PRIVATE_COMPOSED_OP_DEF(n) \
|
||||
template<ASIO_VARIADIC_TPARAMS(n)> \
|
||||
void operator()(ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
if (invocations_ < ~0u) \
|
||||
++invocations_; \
|
||||
impl_(*this, ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
\
|
||||
template<ASIO_VARIADIC_TPARAMS(n)> \
|
||||
void complete(ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
this->work_.reset(); \
|
||||
this->handler_(ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_COMPOSED_OP_DEF)
|
||||
#undef ASIO_PRIVATE_COMPOSED_OP_DEF
|
||||
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
//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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(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
|
||||
: 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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, ASIO_MOVE_ARG(T) executors)
|
||||
: executors_(ASIO_MOVE_CAST(T)(executors))
|
||||
{
|
||||
}
|
||||
|
||||
executor_type get_executor() const ASIO_NOEXCEPT
|
||||
{
|
||||
return executors_.head_;
|
||||
}
|
||||
|
||||
template <typename Handler, typename Impl>
|
||||
void operator()(ASIO_MOVE_ARG(Handler) handler,
|
||||
ASIO_MOVE_ARG(Impl) impl) const
|
||||
{
|
||||
composed_op<typename decay<Impl>::type, composed_work<Executors>,
|
||||
typename decay<Handler>::type, Signature>(
|
||||
ASIO_MOVE_CAST(Impl)(impl),
|
||||
composed_work<Executors>(executors_),
|
||||
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(
|
||||
ASIO_MOVE_ARG(composed_io_executors<Executors>) executors)
|
||||
{
|
||||
return initiate_composed_op<Signature, Executors>(0,
|
||||
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)
|
||||
#if defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename CompletionToken, typename Signature,
|
||||
typename Implementation, typename... IoObjectsOrExecutors>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, Signature)
|
||||
async_compose(ASIO_MOVE_ARG(Implementation) implementation,
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token,
|
||||
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(
|
||||
ASIO_MOVE_CAST(IoObjectsOrExecutors)(
|
||||
io_objects_or_executors))...)),
|
||||
token, ASIO_MOVE_CAST(Implementation)(implementation));
|
||||
}
|
||||
|
||||
#else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename CompletionToken, typename Signature, typename Implementation>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, Signature)
|
||||
async_compose(ASIO_MOVE_ARG(Implementation) implementation,
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
return async_initiate<CompletionToken, Signature>(
|
||||
detail::make_initiate_composed_op<Signature>(
|
||||
detail::make_composed_io_executors()),
|
||||
token, ASIO_MOVE_CAST(Implementation)(implementation));
|
||||
}
|
||||
|
||||
# define ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR(n) \
|
||||
ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_##n
|
||||
|
||||
# define ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_1 \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T1)(x1))
|
||||
# define ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_2 \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T1)(x1)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T2)(x2))
|
||||
# define ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_3 \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T1)(x1)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T2)(x2)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T3)(x3))
|
||||
# define ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_4 \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T1)(x1)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T2)(x2)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T3)(x3)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T4)(x4))
|
||||
# define ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_5 \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T1)(x1)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T2)(x2)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T3)(x3)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T4)(x4)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T5)(x5))
|
||||
# define ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_6 \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T1)(x1)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T2)(x2)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T3)(x3)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T4)(x4)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T5)(x5)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T6)(x6))
|
||||
# define ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_7 \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T1)(x1)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T2)(x2)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T3)(x3)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T4)(x4)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T5)(x5)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T6)(x6)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T7)(x7))
|
||||
# define ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_8 \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T1)(x1)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T2)(x2)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T3)(x3)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T4)(x4)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T5)(x5)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T6)(x6)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T7)(x7)), \
|
||||
detail::get_composed_io_executor(ASIO_MOVE_CAST(T8)(x8))
|
||||
|
||||
#define ASIO_PRIVATE_ASYNC_COMPOSE_DEF(n) \
|
||||
template <typename CompletionToken, typename Signature, \
|
||||
typename Implementation, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, Signature) \
|
||||
async_compose(ASIO_MOVE_ARG(Implementation) implementation, \
|
||||
ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
return async_initiate<CompletionToken, Signature>( \
|
||||
detail::make_initiate_composed_op<Signature>( \
|
||||
detail::make_composed_io_executors( \
|
||||
ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR(n))), \
|
||||
token, ASIO_MOVE_CAST(Implementation)(implementation)); \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_ASYNC_COMPOSE_DEF)
|
||||
#undef ASIO_PRIVATE_ASYNC_COMPOSE_DEF
|
||||
|
||||
#undef ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR
|
||||
#undef ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_1
|
||||
#undef ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_2
|
||||
#undef ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_3
|
||||
#undef ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_4
|
||||
#undef ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_5
|
||||
#undef ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_6
|
||||
#undef ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_7
|
||||
#undef ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR_8
|
||||
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_COMPOSE_HPP
|
||||
916
extern/asio-1.18.2/include/asio/impl/connect.hpp
vendored
Normal file
916
extern/asio-1.18.2/include/asio/impl/connect.hpp
vendored
Normal file
@@ -0,0 +1,916 @@
|
||||
//
|
||||
// impl/connect.hpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_CONNECT_HPP
|
||||
#define ASIO_IMPL_CONNECT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <algorithm>
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/detail/bind_handler.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_cont_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/handler_tracking.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/post.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct default_connect_condition
|
||||
{
|
||||
template <typename Endpoint>
|
||||
bool operator()(const asio::error_code&, const Endpoint&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Protocol, typename Iterator>
|
||||
inline typename Protocol::endpoint deref_connect_result(
|
||||
Iterator iter, asio::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(
|
||||
(*static_cast<legacy_connect_condition_helper<T, Iterator>*>(0))(
|
||||
*static_cast<const asio::error_code*>(0),
|
||||
*static_cast<const Iterator*>(0)))) != 1;
|
||||
};
|
||||
|
||||
template <typename ConnectCondition, typename Iterator>
|
||||
inline Iterator call_connect_condition(ConnectCondition& connect_condition,
|
||||
const asio::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 asio::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)
|
||||
{
|
||||
asio::error_code ec;
|
||||
typename Protocol::endpoint result = connect(s, endpoints, ec);
|
||||
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, asio::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(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)
|
||||
{
|
||||
asio::error_code ec;
|
||||
Iterator result = connect(s, begin, ec);
|
||||
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, asio::error_code& ec,
|
||||
typename constraint<!is_endpoint_sequence<Iterator>::value>::type)
|
||||
{
|
||||
return connect(s, begin, Iterator(), detail::default_connect_condition(), ec);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename Protocol, typename Executor, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol, Executor>& s,
|
||||
Iterator begin, Iterator end)
|
||||
{
|
||||
asio::error_code ec;
|
||||
Iterator result = connect(s, begin, end, ec);
|
||||
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, asio::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)
|
||||
{
|
||||
asio::error_code ec;
|
||||
typename Protocol::endpoint result = connect(
|
||||
s, endpoints, connect_condition, ec);
|
||||
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,
|
||||
asio::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(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)
|
||||
{
|
||||
asio::error_code ec;
|
||||
Iterator result = connect(s, begin, connect_condition, ec);
|
||||
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,
|
||||
asio::error_code& ec,
|
||||
typename constraint<!is_endpoint_sequence<Iterator>::value>::type)
|
||||
{
|
||||
return connect(s, begin, Iterator(), connect_condition, ec);
|
||||
}
|
||||
#endif // !defined(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)
|
||||
{
|
||||
asio::error_code ec;
|
||||
Iterator result = connect(s, begin, end, connect_condition, ec);
|
||||
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,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
ec = asio::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 = 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 asio::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 asio::error_code&, Iterator&, Iterator&)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Protocol, typename Executor, typename EndpointSequence,
|
||||
typename ConnectCondition, typename RangeConnectHandler>
|
||||
class range_connect_op : 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_connect_condition<ConnectCondition>(connect_condition),
|
||||
socket_(sock),
|
||||
endpoints_(endpoints),
|
||||
index_(0),
|
||||
start_(0),
|
||||
handler_(ASIO_MOVE_CAST(RangeConnectHandler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
range_connect_op(const range_connect_op& 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_connect_condition<ConnectCondition>(other),
|
||||
socket_(other.socket_),
|
||||
endpoints_(other.endpoints_),
|
||||
index_(other.index_),
|
||||
start_(other.start_),
|
||||
handler_(ASIO_MOVE_CAST(RangeConnectHandler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()(asio::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(asio::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);
|
||||
ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_connect"));
|
||||
socket_.async_connect(*iter,
|
||||
ASIO_MOVE_CAST(range_connect_op)(*this));
|
||||
return;
|
||||
}
|
||||
|
||||
if (start)
|
||||
{
|
||||
ec = asio::error::not_found;
|
||||
ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_connect"));
|
||||
asio::post(socket_.get_executor(),
|
||||
detail::bind_handler(
|
||||
ASIO_MOVE_CAST(range_connect_op)(*this), ec));
|
||||
return;
|
||||
}
|
||||
|
||||
/* fall-through */ default:
|
||||
|
||||
if (iter == end)
|
||||
break;
|
||||
|
||||
if (!socket_.is_open())
|
||||
{
|
||||
ec = asio::error::operation_aborted;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ec)
|
||||
break;
|
||||
|
||||
++iter;
|
||||
++index_;
|
||||
}
|
||||
|
||||
handler_(static_cast<const asio::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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(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 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return socket_.get_executor();
|
||||
}
|
||||
|
||||
template <typename RangeConnectHandler,
|
||||
typename EndpointSequence, typename ConnectCondition>
|
||||
void operator()(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.
|
||||
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)(asio::error_code(), 1);
|
||||
}
|
||||
|
||||
private:
|
||||
basic_socket<Protocol, Executor>& socket_;
|
||||
};
|
||||
|
||||
template <typename Protocol, typename Executor, typename Iterator,
|
||||
typename ConnectCondition, typename IteratorConnectHandler>
|
||||
class iterator_connect_op : 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_connect_condition<ConnectCondition>(connect_condition),
|
||||
socket_(sock),
|
||||
iter_(begin),
|
||||
end_(end),
|
||||
start_(0),
|
||||
handler_(ASIO_MOVE_CAST(IteratorConnectHandler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
iterator_connect_op(const iterator_connect_op& 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_connect_condition<ConnectCondition>(other),
|
||||
socket_(other.socket_),
|
||||
iter_(other.iter_),
|
||||
end_(other.end_),
|
||||
start_(other.start_),
|
||||
handler_(ASIO_MOVE_CAST(IteratorConnectHandler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()(asio::error_code ec, int start = 0)
|
||||
{
|
||||
switch (start_ = start)
|
||||
{
|
||||
case 1:
|
||||
for (;;)
|
||||
{
|
||||
this->check_condition(ec, iter_, end_);
|
||||
|
||||
if (iter_ != end_)
|
||||
{
|
||||
socket_.close(ec);
|
||||
ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_connect"));
|
||||
socket_.async_connect(*iter_,
|
||||
ASIO_MOVE_CAST(iterator_connect_op)(*this));
|
||||
return;
|
||||
}
|
||||
|
||||
if (start)
|
||||
{
|
||||
ec = asio::error::not_found;
|
||||
ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_connect"));
|
||||
asio::post(socket_.get_executor(),
|
||||
detail::bind_handler(
|
||||
ASIO_MOVE_CAST(iterator_connect_op)(*this), ec));
|
||||
return;
|
||||
}
|
||||
|
||||
/* fall-through */ default:
|
||||
|
||||
if (iter_ == end_)
|
||||
break;
|
||||
|
||||
if (!socket_.is_open())
|
||||
{
|
||||
ec = asio::error::operation_aborted;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ec)
|
||||
break;
|
||||
|
||||
++iter_;
|
||||
}
|
||||
|
||||
handler_(static_cast<const asio::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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(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 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return socket_.get_executor();
|
||||
}
|
||||
|
||||
template <typename IteratorConnectHandler,
|
||||
typename Iterator, typename ConnectCondition>
|
||||
void operator()(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.
|
||||
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)(asio::error_code(), 1);
|
||||
}
|
||||
|
||||
private:
|
||||
basic_socket<Protocol, Executor>& socket_;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
#if !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename Protocol, typename Executor, typename EndpointSequence,
|
||||
typename ConnectCondition, typename RangeConnectHandler, typename Allocator>
|
||||
struct associated_allocator<
|
||||
detail::range_connect_op<Protocol, Executor, EndpointSequence,
|
||||
ConnectCondition, RangeConnectHandler>, Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<
|
||||
RangeConnectHandler, Allocator>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::range_connect_op<Protocol, Executor, EndpointSequence,
|
||||
ConnectCondition, RangeConnectHandler>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<RangeConnectHandler,
|
||||
Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Protocol, typename Executor, typename EndpointSequence,
|
||||
typename ConnectCondition, typename RangeConnectHandler, typename Executor1>
|
||||
struct associated_executor<
|
||||
detail::range_connect_op<Protocol, Executor, EndpointSequence,
|
||||
ConnectCondition, RangeConnectHandler>, Executor1>
|
||||
: detail::associated_executor_forwarding_base<RangeConnectHandler, Executor1>
|
||||
{
|
||||
typedef typename associated_executor<
|
||||
RangeConnectHandler, Executor1>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::range_connect_op<Protocol, Executor, EndpointSequence,
|
||||
ConnectCondition, RangeConnectHandler>& h,
|
||||
const Executor1& ex = Executor1()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<RangeConnectHandler,
|
||||
Executor1>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Protocol, typename Executor, typename Iterator,
|
||||
typename ConnectCondition, typename IteratorConnectHandler,
|
||||
typename Allocator>
|
||||
struct associated_allocator<
|
||||
detail::iterator_connect_op<Protocol, Executor,
|
||||
Iterator, ConnectCondition, IteratorConnectHandler>,
|
||||
Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<
|
||||
IteratorConnectHandler, Allocator>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::iterator_connect_op<Protocol, Executor,
|
||||
Iterator, ConnectCondition, IteratorConnectHandler>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<IteratorConnectHandler,
|
||||
Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Protocol, typename Executor, typename Iterator,
|
||||
typename ConnectCondition, typename IteratorConnectHandler,
|
||||
typename Executor1>
|
||||
struct associated_executor<
|
||||
detail::iterator_connect_op<Protocol, Executor,
|
||||
Iterator, ConnectCondition, IteratorConnectHandler>,
|
||||
Executor1>
|
||||
: detail::associated_executor_forwarding_base<
|
||||
IteratorConnectHandler, Executor1>
|
||||
{
|
||||
typedef typename associated_executor<
|
||||
IteratorConnectHandler, Executor1>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::iterator_connect_op<Protocol, Executor,
|
||||
Iterator, ConnectCondition, IteratorConnectHandler>& h,
|
||||
const Executor1& ex = Executor1()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<IteratorConnectHandler,
|
||||
Executor1>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename Protocol, typename Executor, typename EndpointSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
typename Protocol::endpoint)) RangeConnectHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(RangeConnectHandler,
|
||||
void (asio::error_code, typename Protocol::endpoint))
|
||||
async_connect(basic_socket<Protocol, Executor>& s,
|
||||
const EndpointSequence& endpoints,
|
||||
ASIO_MOVE_ARG(RangeConnectHandler) handler,
|
||||
typename constraint<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type)
|
||||
{
|
||||
return async_initiate<RangeConnectHandler,
|
||||
void (asio::error_code, typename Protocol::endpoint)>(
|
||||
detail::initiate_async_range_connect<Protocol, Executor>(s),
|
||||
handler, endpoints, detail::default_connect_condition());
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
template <typename Protocol, typename Executor, typename Iterator,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
Iterator)) IteratorConnectHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin,
|
||||
ASIO_MOVE_ARG(IteratorConnectHandler) handler,
|
||||
typename constraint<!is_endpoint_sequence<Iterator>::value>::type)
|
||||
{
|
||||
return async_initiate<IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator)>(
|
||||
detail::initiate_async_iterator_connect<Protocol, Executor>(s),
|
||||
handler, begin, Iterator(), detail::default_connect_condition());
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename Protocol, typename Executor, typename Iterator,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
Iterator)) IteratorConnectHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin, Iterator end,
|
||||
ASIO_MOVE_ARG(IteratorConnectHandler) handler)
|
||||
{
|
||||
return async_initiate<IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator)>(
|
||||
detail::initiate_async_iterator_connect<Protocol, Executor>(s),
|
||||
handler, begin, end, detail::default_connect_condition());
|
||||
}
|
||||
|
||||
template <typename Protocol, typename Executor,
|
||||
typename EndpointSequence, typename ConnectCondition,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
typename Protocol::endpoint)) RangeConnectHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(RangeConnectHandler,
|
||||
void (asio::error_code, typename Protocol::endpoint))
|
||||
async_connect(basic_socket<Protocol, Executor>& s,
|
||||
const EndpointSequence& endpoints, ConnectCondition connect_condition,
|
||||
ASIO_MOVE_ARG(RangeConnectHandler) handler,
|
||||
typename constraint<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type)
|
||||
{
|
||||
return async_initiate<RangeConnectHandler,
|
||||
void (asio::error_code, typename Protocol::endpoint)>(
|
||||
detail::initiate_async_range_connect<Protocol, Executor>(s),
|
||||
handler, endpoints, connect_condition);
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
template <typename Protocol, typename Executor,
|
||||
typename Iterator, typename ConnectCondition,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
Iterator)) IteratorConnectHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin,
|
||||
ConnectCondition connect_condition,
|
||||
ASIO_MOVE_ARG(IteratorConnectHandler) handler,
|
||||
typename constraint<!is_endpoint_sequence<Iterator>::value>::type)
|
||||
{
|
||||
return async_initiate<IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator)>(
|
||||
detail::initiate_async_iterator_connect<Protocol, Executor>(s),
|
||||
handler, begin, Iterator(), connect_condition);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename Protocol, typename Executor,
|
||||
typename Iterator, typename ConnectCondition,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
Iterator)) IteratorConnectHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator))
|
||||
async_connect(basic_socket<Protocol, Executor>& s, Iterator begin,
|
||||
Iterator end, ConnectCondition connect_condition,
|
||||
ASIO_MOVE_ARG(IteratorConnectHandler) handler)
|
||||
{
|
||||
return async_initiate<IteratorConnectHandler,
|
||||
void (asio::error_code, Iterator)>(
|
||||
detail::initiate_async_iterator_connect<Protocol, Executor>(s),
|
||||
handler, begin, end, connect_condition);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_CONNECT_HPP
|
||||
252
extern/asio-1.18.2/include/asio/impl/defer.hpp
vendored
Normal file
252
extern/asio-1.18.2/include/asio/impl/defer.hpp
vendored
Normal file
@@ -0,0 +1,252 @@
|
||||
//
|
||||
// impl/defer.hpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_DEFER_HPP
|
||||
#define ASIO_IMPL_DEFER_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/detail/work_dispatcher.hpp"
|
||||
#include "asio/execution/allocator.hpp"
|
||||
#include "asio/execution/blocking.hpp"
|
||||
#include "asio/execution/relationship.hpp"
|
||||
#include "asio/prefer.hpp"
|
||||
#include "asio/require.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class initiate_defer
|
||||
{
|
||||
public:
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(
|
||||
asio::prefer(
|
||||
asio::require(ex, execution::blocking.never),
|
||||
execution::relationship.continuation,
|
||||
execution::allocator(alloc)),
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler));
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return ex_;
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(
|
||||
asio::prefer(
|
||||
asio::require(ex_, execution::blocking.never),
|
||||
execution::relationship.continuation,
|
||||
execution::allocator(alloc)),
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler));
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(
|
||||
asio::prefer(
|
||||
asio::require(ex_, execution::blocking.never),
|
||||
execution::relationship.continuation,
|
||||
execution::allocator(alloc)),
|
||||
detail::work_dispatcher<handler_t, handler_ex_t>(
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler), handler_ex));
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(ASIO_MOVE_CAST(CompletionHandler)(handler), alloc);
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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>(
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler),
|
||||
handler_ex), alloc);
|
||||
}
|
||||
|
||||
private:
|
||||
Executor ex_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) defer(
|
||||
ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
return async_initiate<CompletionToken, void()>(
|
||||
detail::initiate_defer(), token);
|
||||
}
|
||||
|
||||
template <typename Executor,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) defer(
|
||||
const Executor& ex, ASIO_MOVE_ARG(CompletionToken) token,
|
||||
typename constraint<
|
||||
execution::is_executor<Executor>::value || is_executor<Executor>::value
|
||||
>::type)
|
||||
{
|
||||
return async_initiate<CompletionToken, void()>(
|
||||
detail::initiate_defer_with_executor<Executor>(ex), token);
|
||||
}
|
||||
|
||||
template <typename ExecutionContext,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) defer(
|
||||
ExecutionContext& ctx, ASIO_MOVE_ARG(CompletionToken) token,
|
||||
typename constraint<is_convertible<
|
||||
ExecutionContext&, execution_context&>::value>::type)
|
||||
{
|
||||
return async_initiate<CompletionToken, void()>(
|
||||
detail::initiate_defer_with_executor<
|
||||
typename ExecutionContext::executor_type>(
|
||||
ctx.get_executor()), token);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_DEFER_HPP
|
||||
130
extern/asio-1.18.2/include/asio/impl/detached.hpp
vendored
Normal file
130
extern/asio-1.18.2/include/asio/impl/detached.hpp
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// impl/detached.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_DETACHED_HPP
|
||||
#define ASIO_IMPL_DETACHED_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/detail/variadic_templates.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename... Args>
|
||||
void operator()(Args...)
|
||||
{
|
||||
}
|
||||
|
||||
#else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
void operator()()
|
||||
{
|
||||
}
|
||||
|
||||
#define ASIO_PRIVATE_DETACHED_DEF(n) \
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
void operator()(ASIO_VARIADIC_TARGS(n)) \
|
||||
{ \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_DETACHED_DEF)
|
||||
#undef ASIO_PRIVATE_DETACHED_DEF
|
||||
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#if !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename Signature>
|
||||
struct async_result<detached_t, Signature>
|
||||
{
|
||||
typedef asio::detail::detached_handler completion_handler_type;
|
||||
|
||||
typedef void return_type;
|
||||
|
||||
explicit async_result(completion_handler_type&)
|
||||
{
|
||||
}
|
||||
|
||||
void get()
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename Initiation, typename RawCompletionToken, typename... Args>
|
||||
static return_type initiate(
|
||||
ASIO_MOVE_ARG(Initiation) initiation,
|
||||
ASIO_MOVE_ARG(RawCompletionToken),
|
||||
ASIO_MOVE_ARG(Args)... args)
|
||||
{
|
||||
ASIO_MOVE_CAST(Initiation)(initiation)(
|
||||
detail::detached_handler(detached_t()),
|
||||
ASIO_MOVE_CAST(Args)(args)...);
|
||||
}
|
||||
|
||||
#else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename Initiation, typename RawCompletionToken>
|
||||
static return_type initiate(
|
||||
ASIO_MOVE_ARG(Initiation) initiation,
|
||||
ASIO_MOVE_ARG(RawCompletionToken))
|
||||
{
|
||||
ASIO_MOVE_CAST(Initiation)(initiation)(
|
||||
detail::detached_handler(detached_t()));
|
||||
}
|
||||
|
||||
#define ASIO_PRIVATE_INITIATE_DEF(n) \
|
||||
template <typename Initiation, typename RawCompletionToken, \
|
||||
ASIO_VARIADIC_TPARAMS(n)> \
|
||||
static return_type initiate( \
|
||||
ASIO_MOVE_ARG(Initiation) initiation, \
|
||||
ASIO_MOVE_ARG(RawCompletionToken), \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
ASIO_MOVE_CAST(Initiation)(initiation)( \
|
||||
detail::detached_handler(detached_t()), \
|
||||
ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_INITIATE_DEF)
|
||||
#undef ASIO_PRIVATE_INITIATE_DEF
|
||||
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_DETACHED_HPP
|
||||
247
extern/asio-1.18.2/include/asio/impl/dispatch.hpp
vendored
Normal file
247
extern/asio-1.18.2/include/asio/impl/dispatch.hpp
vendored
Normal file
@@ -0,0 +1,247 @@
|
||||
//
|
||||
// impl/dispatch.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_DISPATCH_HPP
|
||||
#define ASIO_IMPL_DISPATCH_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/detail/work_dispatcher.hpp"
|
||||
#include "asio/execution/allocator.hpp"
|
||||
#include "asio/execution/blocking.hpp"
|
||||
#include "asio/prefer.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class initiate_dispatch
|
||||
{
|
||||
public:
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(
|
||||
asio::prefer(ex,
|
||||
execution::blocking.possibly,
|
||||
execution::allocator(alloc)),
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler));
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return ex_;
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(
|
||||
asio::prefer(ex_,
|
||||
execution::blocking.possibly,
|
||||
execution::allocator(alloc)),
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler));
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(
|
||||
asio::prefer(ex_,
|
||||
execution::blocking.possibly,
|
||||
execution::allocator(alloc)),
|
||||
detail::work_dispatcher<handler_t, handler_ex_t>(
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler), handler_ex));
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(ASIO_MOVE_CAST(CompletionHandler)(handler), alloc);
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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>(
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler),
|
||||
handler_ex), alloc);
|
||||
}
|
||||
|
||||
private:
|
||||
Executor ex_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) dispatch(
|
||||
ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
return async_initiate<CompletionToken, void()>(
|
||||
detail::initiate_dispatch(), token);
|
||||
}
|
||||
|
||||
template <typename Executor,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) dispatch(
|
||||
const Executor& ex, ASIO_MOVE_ARG(CompletionToken) token,
|
||||
typename constraint<
|
||||
execution::is_executor<Executor>::value || is_executor<Executor>::value
|
||||
>::type)
|
||||
{
|
||||
return async_initiate<CompletionToken, void()>(
|
||||
detail::initiate_dispatch_with_executor<Executor>(ex), token);
|
||||
}
|
||||
|
||||
template <typename ExecutionContext,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) dispatch(
|
||||
ExecutionContext& ctx, ASIO_MOVE_ARG(CompletionToken) token,
|
||||
typename constraint<is_convertible<
|
||||
ExecutionContext&, execution_context&>::value>::type)
|
||||
{
|
||||
return async_initiate<CompletionToken, void()>(
|
||||
detail::initiate_dispatch_with_executor<
|
||||
typename ExecutionContext::executor_type>(
|
||||
ctx.get_executor()), token);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_DISPATCH_HPP
|
||||
128
extern/asio-1.18.2/include/asio/impl/error.ipp
vendored
Normal file
128
extern/asio-1.18.2/include/asio/impl/error.ipp
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// impl/error.ipp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_ERROR_IPP
|
||||
#define ASIO_IMPL_ERROR_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <string>
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace error {
|
||||
|
||||
#if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
|
||||
|
||||
namespace detail {
|
||||
|
||||
class netdb_category : public asio::error_category
|
||||
{
|
||||
public:
|
||||
const char* name() const 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 asio::error_category& get_netdb_category()
|
||||
{
|
||||
static detail::netdb_category instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
class addrinfo_category : public asio::error_category
|
||||
{
|
||||
public:
|
||||
const char* name() const 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 asio::error_category& get_addrinfo_category()
|
||||
{
|
||||
static detail::addrinfo_category instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
#endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
|
||||
|
||||
namespace detail {
|
||||
|
||||
class misc_category : public asio::error_category
|
||||
{
|
||||
public:
|
||||
const char* name() const 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 asio::error_category& get_misc_category()
|
||||
{
|
||||
static detail::misc_category instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
} // namespace error
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_ERROR_IPP
|
||||
206
extern/asio-1.18.2/include/asio/impl/error_code.ipp
vendored
Normal file
206
extern/asio-1.18.2/include/asio/impl/error_code.ipp
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
//
|
||||
// impl/error_code.ipp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_ERROR_CODE_IPP
|
||||
#define ASIO_IMPL_ERROR_CODE_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
# include <winerror.h>
|
||||
#elif defined(ASIO_WINDOWS_RUNTIME)
|
||||
# include <windows.h>
|
||||
#else
|
||||
# include <cerrno>
|
||||
# include <cstring>
|
||||
# include <string>
|
||||
#endif
|
||||
#include "asio/detail/local_free_on_block_exit.hpp"
|
||||
#include "asio/detail/socket_types.hpp"
|
||||
#include "asio/error_code.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class system_category : public error_category
|
||||
{
|
||||
public:
|
||||
const char* name() const ASIO_ERROR_CATEGORY_NOEXCEPT
|
||||
{
|
||||
return "asio.system";
|
||||
}
|
||||
|
||||
std::string message(int value) const
|
||||
{
|
||||
#if defined(ASIO_WINDOWS_RUNTIME) || defined(ASIO_WINDOWS_APP)
|
||||
std::wstring wmsg(128, wchar_t());
|
||||
for (;;)
|
||||
{
|
||||
DWORD wlength = ::FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| FORMAT_MESSAGE_IGNORE_INSERTS, 0, value,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
&wmsg[0], static_cast<DWORD>(wmsg.size()), 0);
|
||||
if (wlength == 0 && ::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
wmsg.resize(wmsg.size() + wmsg.size() / 2);
|
||||
continue;
|
||||
}
|
||||
if (wlength && wmsg[wlength - 1] == '\n')
|
||||
--wlength;
|
||||
if (wlength && wmsg[wlength - 1] == '\r')
|
||||
--wlength;
|
||||
if (wlength)
|
||||
{
|
||||
std::string msg(wlength * 2, char());
|
||||
int length = ::WideCharToMultiByte(CP_ACP, 0,
|
||||
wmsg.c_str(), static_cast<int>(wlength),
|
||||
&msg[0], static_cast<int>(wlength * 2), 0, 0);
|
||||
if (length <= 0)
|
||||
return "asio.system error";
|
||||
msg.resize(static_cast<std::size_t>(length));
|
||||
return msg;
|
||||
}
|
||||
else
|
||||
return "asio.system error";
|
||||
}
|
||||
#elif defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
char* msg = 0;
|
||||
DWORD length = ::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
||||
| FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| FORMAT_MESSAGE_IGNORE_INSERTS, 0, value,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char*)&msg, 0, 0);
|
||||
detail::local_free_on_block_exit local_free_obj(msg);
|
||||
if (length && msg[length - 1] == '\n')
|
||||
msg[--length] = '\0';
|
||||
if (length && msg[length - 1] == '\r')
|
||||
msg[--length] = '\0';
|
||||
if (length)
|
||||
return msg;
|
||||
else
|
||||
return "asio.system error";
|
||||
#else // defined(ASIO_WINDOWS_DESKTOP) || defined(__CYGWIN__)
|
||||
#if !defined(__sun)
|
||||
if (value == ECANCELED)
|
||||
return "Operation aborted.";
|
||||
#endif // !defined(__sun)
|
||||
#if defined(__sun) || defined(__QNX__) || defined(__SYMBIAN32__)
|
||||
using namespace std;
|
||||
return strerror(value);
|
||||
#else
|
||||
char buf[256] = "";
|
||||
using namespace std;
|
||||
return strerror_result(strerror_r(value, buf, sizeof(buf)), buf);
|
||||
#endif
|
||||
#endif // defined(ASIO_WINDOWS_DESKTOP) || defined(__CYGWIN__)
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_STD_ERROR_CODE)
|
||||
std::error_condition default_error_condition(
|
||||
int ev) const ASIO_ERROR_CATEGORY_NOEXCEPT
|
||||
{
|
||||
switch (ev)
|
||||
{
|
||||
case access_denied:
|
||||
return std::errc::permission_denied;
|
||||
case address_family_not_supported:
|
||||
return std::errc::address_family_not_supported;
|
||||
case address_in_use:
|
||||
return std::errc::address_in_use;
|
||||
case already_connected:
|
||||
return std::errc::already_connected;
|
||||
case already_started:
|
||||
return std::errc::connection_already_in_progress;
|
||||
case broken_pipe:
|
||||
return std::errc::broken_pipe;
|
||||
case connection_aborted:
|
||||
return std::errc::connection_aborted;
|
||||
case connection_refused:
|
||||
return std::errc::connection_refused;
|
||||
case connection_reset:
|
||||
return std::errc::connection_reset;
|
||||
case bad_descriptor:
|
||||
return std::errc::bad_file_descriptor;
|
||||
case fault:
|
||||
return std::errc::bad_address;
|
||||
case host_unreachable:
|
||||
return std::errc::host_unreachable;
|
||||
case in_progress:
|
||||
return std::errc::operation_in_progress;
|
||||
case interrupted:
|
||||
return std::errc::interrupted;
|
||||
case invalid_argument:
|
||||
return std::errc::invalid_argument;
|
||||
case message_size:
|
||||
return std::errc::message_size;
|
||||
case name_too_long:
|
||||
return std::errc::filename_too_long;
|
||||
case network_down:
|
||||
return std::errc::network_down;
|
||||
case network_reset:
|
||||
return std::errc::network_reset;
|
||||
case network_unreachable:
|
||||
return std::errc::network_unreachable;
|
||||
case no_descriptors:
|
||||
return std::errc::too_many_files_open;
|
||||
case no_buffer_space:
|
||||
return std::errc::no_buffer_space;
|
||||
case no_memory:
|
||||
return std::errc::not_enough_memory;
|
||||
case no_permission:
|
||||
return std::errc::operation_not_permitted;
|
||||
case no_protocol_option:
|
||||
return std::errc::no_protocol_option;
|
||||
case no_such_device:
|
||||
return std::errc::no_such_device;
|
||||
case not_connected:
|
||||
return std::errc::not_connected;
|
||||
case not_socket:
|
||||
return std::errc::not_a_socket;
|
||||
case operation_aborted:
|
||||
return std::errc::operation_canceled;
|
||||
case operation_not_supported:
|
||||
return std::errc::operation_not_supported;
|
||||
case shut_down:
|
||||
return std::make_error_condition(ev, *this);
|
||||
case timed_out:
|
||||
return std::errc::timed_out;
|
||||
case try_again:
|
||||
return std::errc::resource_unavailable_try_again;
|
||||
case would_block:
|
||||
return std::errc::operation_would_block;
|
||||
default:
|
||||
return std::make_error_condition(ev, *this);
|
||||
}
|
||||
#endif // defined(ASIO_HAS_STD_ERROR_CODE)
|
||||
|
||||
private:
|
||||
// Helper function to adapt the result from glibc's variant of strerror_r.
|
||||
static const char* strerror_result(int, const char* s) { return s; }
|
||||
static const char* strerror_result(const char* s, const char*) { return s; }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
const error_category& system_category()
|
||||
{
|
||||
static detail::system_category instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_ERROR_CODE_IPP
|
||||
109
extern/asio-1.18.2/include/asio/impl/execution_context.hpp
vendored
Normal file
109
extern/asio-1.18.2/include/asio/impl/execution_context.hpp
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
//
|
||||
// impl/execution_context.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_EXECUTION_CONTEXT_HPP
|
||||
#define ASIO_IMPL_EXECUTION_CONTEXT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/scoped_ptr.hpp"
|
||||
#include "asio/detail/service_registry.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename Service, typename... Args>
|
||||
Service& make_service(execution_context& e, ASIO_MOVE_ARG(Args)... args)
|
||||
{
|
||||
detail::scoped_ptr<Service> svc(
|
||||
new Service(e, ASIO_MOVE_CAST(Args)(args)...));
|
||||
e.service_registry_->template add_service<Service>(svc.get());
|
||||
Service& result = *svc;
|
||||
svc.release();
|
||||
return result;
|
||||
}
|
||||
|
||||
#else // defined(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 ASIO_PRIVATE_MAKE_SERVICE_DEF(n) \
|
||||
template <typename Service, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
Service& make_service(execution_context& e, \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
detail::scoped_ptr<Service> svc( \
|
||||
new Service(e, ASIO_VARIADIC_MOVE_ARGS(n))); \
|
||||
e.service_registry_->template add_service<Service>(svc.get()); \
|
||||
Service& result = *svc; \
|
||||
svc.release(); \
|
||||
return result; \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_MAKE_SERVICE_DEF)
|
||||
#undef ASIO_PRIVATE_MAKE_SERVICE_DEF
|
||||
|
||||
#endif // defined(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
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_EXECUTION_CONTEXT_HPP
|
||||
82
extern/asio-1.18.2/include/asio/impl/execution_context.ipp
vendored
Normal file
82
extern/asio-1.18.2/include/asio/impl/execution_context.ipp
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// impl/execution_context.ipp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_EXECUTION_CONTEXT_IPP
|
||||
#define ASIO_IMPL_EXECUTION_CONTEXT_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/execution_context.hpp"
|
||||
#include "asio/detail/service_registry.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
execution_context::execution_context()
|
||||
: service_registry_(new 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(
|
||||
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
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_EXECUTION_CONTEXT_IPP
|
||||
300
extern/asio-1.18.2/include/asio/impl/executor.hpp
vendored
Normal file
300
extern/asio-1.18.2/include/asio/impl/executor.hpp
vendored
Normal file
@@ -0,0 +1,300 @@
|
||||
//
|
||||
// impl/executor.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_EXECUTOR_HPP
|
||||
#define ASIO_IMPL_EXECUTOR_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if !defined(ASIO_NO_TS_EXECUTORS)
|
||||
|
||||
#include "asio/detail/atomic_count.hpp"
|
||||
#include "asio/detail/global.hpp"
|
||||
#include "asio/detail/memory.hpp"
|
||||
#include "asio/executor.hpp"
|
||||
#include "asio/system_executor.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
// Default polymorphic executor implementation.
|
||||
template <typename Executor, typename Allocator>
|
||||
class executor::impl
|
||||
: public executor::impl_base
|
||||
{
|
||||
public:
|
||||
typedef 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) ASIO_NOEXCEPT
|
||||
: impl_base(false),
|
||||
ref_count_(1),
|
||||
executor_(e),
|
||||
allocator_(a)
|
||||
{
|
||||
}
|
||||
|
||||
impl_base* clone() const ASIO_NOEXCEPT
|
||||
{
|
||||
detail::ref_count_up(ref_count_);
|
||||
return const_cast<impl_base*>(static_cast<const impl_base*>(this));
|
||||
}
|
||||
|
||||
void destroy() 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() ASIO_NOEXCEPT
|
||||
{
|
||||
executor_.on_work_started();
|
||||
}
|
||||
|
||||
void on_work_finished() ASIO_NOEXCEPT
|
||||
{
|
||||
executor_.on_work_finished();
|
||||
}
|
||||
|
||||
execution_context& context() ASIO_NOEXCEPT
|
||||
{
|
||||
return executor_.context();
|
||||
}
|
||||
|
||||
void dispatch(ASIO_MOVE_ARG(function) f)
|
||||
{
|
||||
executor_.dispatch(ASIO_MOVE_CAST(function)(f), allocator_);
|
||||
}
|
||||
|
||||
void post(ASIO_MOVE_ARG(function) f)
|
||||
{
|
||||
executor_.post(ASIO_MOVE_CAST(function)(f), allocator_);
|
||||
}
|
||||
|
||||
void defer(ASIO_MOVE_ARG(function) f)
|
||||
{
|
||||
executor_.defer(ASIO_MOVE_CAST(function)(f), allocator_);
|
||||
}
|
||||
|
||||
type_id_result_type target_type() const ASIO_NOEXCEPT
|
||||
{
|
||||
return type_id<Executor>();
|
||||
}
|
||||
|
||||
void* target() ASIO_NOEXCEPT
|
||||
{
|
||||
return &executor_;
|
||||
}
|
||||
|
||||
const void* target() const ASIO_NOEXCEPT
|
||||
{
|
||||
return &executor_;
|
||||
}
|
||||
|
||||
bool equals(const impl_base* e) const 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 ASIO_NOEXCEPT
|
||||
{
|
||||
return const_cast<impl_base*>(static_cast<const impl_base*>(this));
|
||||
}
|
||||
|
||||
void destroy() ASIO_NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
void on_work_started() ASIO_NOEXCEPT
|
||||
{
|
||||
executor_.on_work_started();
|
||||
}
|
||||
|
||||
void on_work_finished() ASIO_NOEXCEPT
|
||||
{
|
||||
executor_.on_work_finished();
|
||||
}
|
||||
|
||||
execution_context& context() ASIO_NOEXCEPT
|
||||
{
|
||||
return executor_.context();
|
||||
}
|
||||
|
||||
void dispatch(ASIO_MOVE_ARG(function) f)
|
||||
{
|
||||
executor_.dispatch(ASIO_MOVE_CAST(function)(f),
|
||||
std::allocator<void>());
|
||||
}
|
||||
|
||||
void post(ASIO_MOVE_ARG(function) f)
|
||||
{
|
||||
executor_.post(ASIO_MOVE_CAST(function)(f),
|
||||
std::allocator<void>());
|
||||
}
|
||||
|
||||
void defer(ASIO_MOVE_ARG(function) f)
|
||||
{
|
||||
executor_.defer(ASIO_MOVE_CAST(function)(f),
|
||||
std::allocator<void>());
|
||||
}
|
||||
|
||||
type_id_result_type target_type() const ASIO_NOEXCEPT
|
||||
{
|
||||
return type_id<system_executor>();
|
||||
}
|
||||
|
||||
void* target() ASIO_NOEXCEPT
|
||||
{
|
||||
return &executor_;
|
||||
}
|
||||
|
||||
const void* target() const ASIO_NOEXCEPT
|
||||
{
|
||||
return &executor_;
|
||||
}
|
||||
|
||||
bool equals(const impl_base* e) const 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(ASIO_MOVE_ARG(Function) f,
|
||||
const Allocator& a) const
|
||||
{
|
||||
impl_base* i = get_impl();
|
||||
if (i->fast_dispatch_)
|
||||
system_executor().dispatch(ASIO_MOVE_CAST(Function)(f), a);
|
||||
else
|
||||
i->dispatch(function(ASIO_MOVE_CAST(Function)(f), a));
|
||||
}
|
||||
|
||||
template <typename Function, typename Allocator>
|
||||
void executor::post(ASIO_MOVE_ARG(Function) f,
|
||||
const Allocator& a) const
|
||||
{
|
||||
get_impl()->post(function(ASIO_MOVE_CAST(Function)(f), a));
|
||||
}
|
||||
|
||||
template <typename Function, typename Allocator>
|
||||
void executor::defer(ASIO_MOVE_ARG(Function) f,
|
||||
const Allocator& a) const
|
||||
{
|
||||
get_impl()->defer(function(ASIO_MOVE_CAST(Function)(f), a));
|
||||
}
|
||||
|
||||
template <typename Executor>
|
||||
Executor* executor::target() ASIO_NOEXCEPT
|
||||
{
|
||||
return impl_ && impl_->target_type() == type_id<Executor>()
|
||||
? static_cast<Executor*>(impl_->target()) : 0;
|
||||
}
|
||||
|
||||
template <typename Executor>
|
||||
const Executor* executor::target() const ASIO_NOEXCEPT
|
||||
{
|
||||
return impl_ && impl_->target_type() == type_id<Executor>()
|
||||
? static_cast<Executor*>(impl_->target()) : 0;
|
||||
}
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // !defined(ASIO_NO_TS_EXECUTORS)
|
||||
|
||||
#endif // ASIO_IMPL_EXECUTOR_HPP
|
||||
43
extern/asio-1.18.2/include/asio/impl/executor.ipp
vendored
Normal file
43
extern/asio-1.18.2/include/asio/impl/executor.ipp
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// impl/executor.ipp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_EXECUTOR_IPP
|
||||
#define ASIO_IMPL_EXECUTOR_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if !defined(ASIO_NO_TS_EXECUTORS)
|
||||
|
||||
#include "asio/executor.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
bad_executor::bad_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
const char* bad_executor::what() const ASIO_NOEXCEPT_OR_NOTHROW
|
||||
{
|
||||
return "bad executor";
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // !defined(ASIO_NO_TS_EXECUTORS)
|
||||
|
||||
#endif // ASIO_IMPL_EXECUTOR_IPP
|
||||
61
extern/asio-1.18.2/include/asio/impl/handler_alloc_hook.ipp
vendored
Normal file
61
extern/asio-1.18.2/include/asio/impl/handler_alloc_hook.ipp
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// impl/handler_alloc_hook.ipp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
|
||||
#define ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/detail/thread_context.hpp"
|
||||
#include "asio/detail/thread_info_base.hpp"
|
||||
#include "asio/handler_alloc_hook.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
asio_handler_allocate_is_deprecated
|
||||
asio_handler_allocate(std::size_t size, ...)
|
||||
{
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
(void)size;
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#elif !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
|
||||
return detail::thread_info_base::allocate(
|
||||
detail::thread_context::top_of_thread_call_stack(), size);
|
||||
#else // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
|
||||
return ::operator new(size);
|
||||
#endif // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
|
||||
}
|
||||
|
||||
asio_handler_deallocate_is_deprecated
|
||||
asio_handler_deallocate(void* pointer, std::size_t size, ...)
|
||||
{
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
(void)pointer;
|
||||
(void)size;
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#elif !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
|
||||
detail::thread_info_base::deallocate(
|
||||
detail::thread_context::top_of_thread_call_stack(), pointer, size);
|
||||
#else // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
|
||||
(void)size;
|
||||
::operator delete(pointer);
|
||||
#endif // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
|
||||
444
extern/asio-1.18.2/include/asio/impl/io_context.hpp
vendored
Normal file
444
extern/asio-1.18.2/include/asio/impl/io_context.hpp
vendored
Normal file
@@ -0,0 +1,444 @@
|
||||
//
|
||||
// impl/io_context.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_IO_CONTEXT_HPP
|
||||
#define ASIO_IMPL_IO_CONTEXT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/completion_handler.hpp"
|
||||
#include "asio/detail/executor_op.hpp"
|
||||
#include "asio/detail/fenced_block.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/service_registry.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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() ASIO_NOEXCEPT
|
||||
{
|
||||
return executor_type(*this);
|
||||
}
|
||||
|
||||
#if defined(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);
|
||||
|
||||
asio::error_code ec;
|
||||
std::size_t s = impl_.wait_one(
|
||||
static_cast<long>(chrono::duration_cast<
|
||||
chrono::microseconds>(rel_time).count()), ec);
|
||||
asio::detail::throw_error(ec);
|
||||
|
||||
if (s || impl_.stopped())
|
||||
return s;
|
||||
|
||||
now = Clock::now();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // defined(ASIO_HAS_CHRONO)
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
inline void io_context::reset()
|
||||
{
|
||||
restart();
|
||||
}
|
||||
|
||||
struct io_context::initiate_dispatch
|
||||
{
|
||||
template <typename LegacyCompletionHandler>
|
||||
void operator()(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.
|
||||
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);
|
||||
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());
|
||||
|
||||
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>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(LegacyCompletionHandler, void ())
|
||||
io_context::dispatch(ASIO_MOVE_ARG(LegacyCompletionHandler) handler)
|
||||
{
|
||||
return async_initiate<LegacyCompletionHandler, void ()>(
|
||||
initiate_dispatch(), handler, this);
|
||||
}
|
||||
|
||||
struct io_context::initiate_post
|
||||
{
|
||||
template <typename LegacyCompletionHandler>
|
||||
void operator()(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.
|
||||
ASIO_LEGACY_COMPLETION_HANDLER_CHECK(
|
||||
LegacyCompletionHandler, handler) type_check;
|
||||
|
||||
detail::non_const_lvalue<LegacyCompletionHandler> handler2(handler);
|
||||
|
||||
bool is_continuation =
|
||||
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());
|
||||
|
||||
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>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(LegacyCompletionHandler, void ())
|
||||
io_context::post(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(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
io_context::basic_executor_type<Allocator, Bits>&
|
||||
io_context::basic_executor_type<Allocator, Bits>::operator=(
|
||||
const basic_executor_type& other) ASIO_NOEXCEPT
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
io_context* old_io_context = io_context_;
|
||||
io_context_ = other.io_context_;
|
||||
allocator_ = other.allocator_;
|
||||
bits_ = other.bits_;
|
||||
if (Bits & outstanding_work_tracked)
|
||||
{
|
||||
if (io_context_)
|
||||
io_context_->impl_.work_started();
|
||||
if (old_io_context)
|
||||
old_io_context->impl_.work_finished();
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
io_context::basic_executor_type<Allocator, Bits>&
|
||||
io_context::basic_executor_type<Allocator, Bits>::operator=(
|
||||
basic_executor_type&& other) ASIO_NOEXCEPT
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
io_context* old_io_context = io_context_;
|
||||
io_context_ = other.io_context_;
|
||||
allocator_ = std::move(other.allocator_);
|
||||
bits_ = other.bits_;
|
||||
if (Bits & outstanding_work_tracked)
|
||||
{
|
||||
other.io_context_ = 0;
|
||||
if (old_io_context)
|
||||
old_io_context->impl_.work_finished();
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
inline bool io_context::basic_executor_type<Allocator,
|
||||
Bits>::running_in_this_thread() const ASIO_NOEXCEPT
|
||||
{
|
||||
return io_context_->impl_.can_dispatch();
|
||||
}
|
||||
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
template <typename Function>
|
||||
void io_context::basic_executor_type<Allocator, Bits>::execute(
|
||||
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 && io_context_->impl_.can_dispatch())
|
||||
{
|
||||
// Make a local, non-const copy of the function.
|
||||
function_type tmp(ASIO_MOVE_CAST(Function)(f));
|
||||
|
||||
#if defined(ASIO_HAS_STD_EXCEPTION_PTR) \
|
||||
&& !defined(ASIO_NO_EXCEPTIONS)
|
||||
try
|
||||
{
|
||||
#endif // defined(ASIO_HAS_STD_EXCEPTION_PTR)
|
||||
// && !defined(ASIO_NO_EXCEPTIONS)
|
||||
detail::fenced_block b(detail::fenced_block::full);
|
||||
asio_handler_invoke_helpers::invoke(tmp, tmp);
|
||||
return;
|
||||
#if defined(ASIO_HAS_STD_EXCEPTION_PTR) \
|
||||
&& !defined(ASIO_NO_EXCEPTIONS)
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
io_context_->impl_.capture_current_exception();
|
||||
return;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_STD_EXCEPTION_PTR)
|
||||
// && !defined(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(allocator_),
|
||||
op::ptr::allocate(allocator_), 0 };
|
||||
p.p = new (p.v) op(ASIO_MOVE_CAST(Function)(f), allocator_);
|
||||
|
||||
ASIO_HANDLER_CREATION((*io_context_, *p.p,
|
||||
"io_context", io_context_, 0, "execute"));
|
||||
|
||||
io_context_->impl_.post_immediate_completion(p.p,
|
||||
(bits_ & relationship_continuation) != 0);
|
||||
p.v = p.p = 0;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_TS_EXECUTORS)
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
inline io_context& io_context::basic_executor_type<
|
||||
Allocator, Bits>::context() const ASIO_NOEXCEPT
|
||||
{
|
||||
return *io_context_;
|
||||
}
|
||||
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
inline void io_context::basic_executor_type<Allocator,
|
||||
Bits>::on_work_started() const ASIO_NOEXCEPT
|
||||
{
|
||||
io_context_->impl_.work_started();
|
||||
}
|
||||
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
inline void io_context::basic_executor_type<Allocator,
|
||||
Bits>::on_work_finished() const ASIO_NOEXCEPT
|
||||
{
|
||||
io_context_->impl_.work_finished();
|
||||
}
|
||||
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
template <typename Function, typename OtherAllocator>
|
||||
void io_context::basic_executor_type<Allocator, Bits>::dispatch(
|
||||
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 (io_context_->impl_.can_dispatch())
|
||||
{
|
||||
// Make a local, non-const copy of the function.
|
||||
function_type tmp(ASIO_MOVE_CAST(Function)(f));
|
||||
|
||||
detail::fenced_block b(detail::fenced_block::full);
|
||||
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(ASIO_MOVE_CAST(Function)(f), a);
|
||||
|
||||
ASIO_HANDLER_CREATION((*io_context_, *p.p,
|
||||
"io_context", io_context_, 0, "dispatch"));
|
||||
|
||||
io_context_->impl_.post_immediate_completion(p.p, false);
|
||||
p.v = p.p = 0;
|
||||
}
|
||||
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
template <typename Function, typename OtherAllocator>
|
||||
void io_context::basic_executor_type<Allocator, Bits>::post(
|
||||
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(ASIO_MOVE_CAST(Function)(f), a);
|
||||
|
||||
ASIO_HANDLER_CREATION((*io_context_, *p.p,
|
||||
"io_context", io_context_, 0, "post"));
|
||||
|
||||
io_context_->impl_.post_immediate_completion(p.p, false);
|
||||
p.v = p.p = 0;
|
||||
}
|
||||
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
template <typename Function, typename OtherAllocator>
|
||||
void io_context::basic_executor_type<Allocator, Bits>::defer(
|
||||
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(ASIO_MOVE_CAST(Function)(f), a);
|
||||
|
||||
ASIO_HANDLER_CREATION((*io_context_, *p.p,
|
||||
"io_context", io_context_, 0, "defer"));
|
||||
|
||||
io_context_->impl_.post_immediate_completion(p.p, true);
|
||||
p.v = p.p = 0;
|
||||
}
|
||||
#endif // !defined(ASIO_NO_TS_EXECUTORS)
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
inline io_context::work::work(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 asio::io_context& io_context::work::get_io_context()
|
||||
{
|
||||
return static_cast<asio::io_context&>(io_context_impl_.context());
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
inline asio::io_context& io_context::service::get_io_context()
|
||||
{
|
||||
return static_cast<asio::io_context&>(context());
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_IO_CONTEXT_HPP
|
||||
175
extern/asio-1.18.2/include/asio/impl/io_context.ipp
vendored
Normal file
175
extern/asio-1.18.2/include/asio/impl/io_context.ipp
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
//
|
||||
// impl/io_context.ipp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_IO_CONTEXT_IPP
|
||||
#define ASIO_IMPL_IO_CONTEXT_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/io_context.hpp"
|
||||
#include "asio/detail/concurrency_hint.hpp"
|
||||
#include "asio/detail/limits.hpp"
|
||||
#include "asio/detail/scoped_ptr.hpp"
|
||||
#include "asio/detail/service_registry.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_IOCP)
|
||||
# include "asio/detail/win_iocp_io_context.hpp"
|
||||
#else
|
||||
# include "asio/detail/scheduler.hpp"
|
||||
#endif
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
io_context::io_context()
|
||||
: impl_(add_impl(new impl_type(*this,
|
||||
ASIO_CONCURRENCY_HINT_DEFAULT, false)))
|
||||
{
|
||||
}
|
||||
|
||||
io_context::io_context(int concurrency_hint)
|
||||
: impl_(add_impl(new impl_type(*this, concurrency_hint == 1
|
||||
? ASIO_CONCURRENCY_HINT_1 : concurrency_hint, false)))
|
||||
{
|
||||
}
|
||||
|
||||
io_context::impl_type& io_context::add_impl(io_context::impl_type* impl)
|
||||
{
|
||||
asio::detail::scoped_ptr<impl_type> scoped_impl(impl);
|
||||
asio::add_service<impl_type>(*this, scoped_impl.get());
|
||||
return *scoped_impl.release();
|
||||
}
|
||||
|
||||
io_context::~io_context()
|
||||
{
|
||||
}
|
||||
|
||||
io_context::count_type io_context::run()
|
||||
{
|
||||
asio::error_code ec;
|
||||
count_type s = impl_.run(ec);
|
||||
asio::detail::throw_error(ec);
|
||||
return s;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
io_context::count_type io_context::run(asio::error_code& ec)
|
||||
{
|
||||
return impl_.run(ec);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
io_context::count_type io_context::run_one()
|
||||
{
|
||||
asio::error_code ec;
|
||||
count_type s = impl_.run_one(ec);
|
||||
asio::detail::throw_error(ec);
|
||||
return s;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
io_context::count_type io_context::run_one(asio::error_code& ec)
|
||||
{
|
||||
return impl_.run_one(ec);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
io_context::count_type io_context::poll()
|
||||
{
|
||||
asio::error_code ec;
|
||||
count_type s = impl_.poll(ec);
|
||||
asio::detail::throw_error(ec);
|
||||
return s;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
io_context::count_type io_context::poll(asio::error_code& ec)
|
||||
{
|
||||
return impl_.poll(ec);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
io_context::count_type io_context::poll_one()
|
||||
{
|
||||
asio::error_code ec;
|
||||
count_type s = impl_.poll_one(ec);
|
||||
asio::detail::throw_error(ec);
|
||||
return s;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
io_context::count_type io_context::poll_one(asio::error_code& ec)
|
||||
{
|
||||
return impl_.poll_one(ec);
|
||||
}
|
||||
#endif // !defined(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(asio::io_context& owner)
|
||||
: execution_context::service(owner)
|
||||
{
|
||||
}
|
||||
|
||||
io_context::service::~service()
|
||||
{
|
||||
}
|
||||
|
||||
void io_context::service::shutdown()
|
||||
{
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
shutdown_service();
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
void io_context::service::shutdown_service()
|
||||
{
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
void io_context::service::notify_fork(io_context::fork_event ev)
|
||||
{
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
fork_service(ev);
|
||||
#else // !defined(ASIO_NO_DEPRECATED)
|
||||
(void)ev;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
void io_context::service::fork_service(io_context::fork_event)
|
||||
{
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_IO_CONTEXT_IPP
|
||||
49
extern/asio-1.18.2/include/asio/impl/multiple_exceptions.ipp
vendored
Normal file
49
extern/asio-1.18.2/include/asio/impl/multiple_exceptions.ipp
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// impl/multiple_exceptions.ipp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_MULTIPLE_EXCEPTIONS_IPP
|
||||
#define ASIO_IMPL_MULTIPLE_EXCEPTIONS_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/multiple_exceptions.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
#if defined(ASIO_HAS_STD_EXCEPTION_PTR)
|
||||
|
||||
multiple_exceptions::multiple_exceptions(
|
||||
std::exception_ptr first) ASIO_NOEXCEPT
|
||||
: first_(ASIO_MOVE_CAST(std::exception_ptr)(first))
|
||||
{
|
||||
}
|
||||
|
||||
const char* multiple_exceptions::what() const ASIO_NOEXCEPT_OR_NOTHROW
|
||||
{
|
||||
return "multiple exceptions";
|
||||
}
|
||||
|
||||
std::exception_ptr multiple_exceptions::first_exception() const
|
||||
{
|
||||
return first_;
|
||||
}
|
||||
|
||||
#endif // defined(ASIO_HAS_STD_EXCEPTION_PTR)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_MULTIPLE_EXCEPTIONS_IPP
|
||||
252
extern/asio-1.18.2/include/asio/impl/post.hpp
vendored
Normal file
252
extern/asio-1.18.2/include/asio/impl/post.hpp
vendored
Normal file
@@ -0,0 +1,252 @@
|
||||
//
|
||||
// impl/post.hpp
|
||||
// ~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_POST_HPP
|
||||
#define ASIO_IMPL_POST_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/detail/work_dispatcher.hpp"
|
||||
#include "asio/execution/allocator.hpp"
|
||||
#include "asio/execution/blocking.hpp"
|
||||
#include "asio/execution/relationship.hpp"
|
||||
#include "asio/prefer.hpp"
|
||||
#include "asio/require.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
namespace detail {
|
||||
|
||||
class initiate_post
|
||||
{
|
||||
public:
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(
|
||||
asio::prefer(
|
||||
asio::require(ex, execution::blocking.never),
|
||||
execution::relationship.fork,
|
||||
execution::allocator(alloc)),
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler));
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return ex_;
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(
|
||||
asio::prefer(
|
||||
asio::require(ex_, execution::blocking.never),
|
||||
execution::relationship.fork,
|
||||
execution::allocator(alloc)),
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler));
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(
|
||||
asio::prefer(
|
||||
asio::require(ex_, execution::blocking.never),
|
||||
execution::relationship.fork,
|
||||
execution::allocator(alloc)),
|
||||
detail::work_dispatcher<handler_t, handler_ex_t>(
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler), handler_ex));
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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(ASIO_MOVE_CAST(CompletionHandler)(handler), alloc);
|
||||
}
|
||||
|
||||
template <typename CompletionHandler>
|
||||
void operator()(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>(
|
||||
ASIO_MOVE_CAST(CompletionHandler)(handler),
|
||||
handler_ex), alloc);
|
||||
}
|
||||
|
||||
private:
|
||||
Executor ex_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) post(
|
||||
ASIO_MOVE_ARG(CompletionToken) token)
|
||||
{
|
||||
return async_initiate<CompletionToken, void()>(
|
||||
detail::initiate_post(), token);
|
||||
}
|
||||
|
||||
template <typename Executor,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
|
||||
ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) post(
|
||||
const Executor& ex, ASIO_MOVE_ARG(CompletionToken) token,
|
||||
typename constraint<
|
||||
execution::is_executor<Executor>::value || is_executor<Executor>::value
|
||||
>::type)
|
||||
{
|
||||
return async_initiate<CompletionToken, void()>(
|
||||
detail::initiate_post_with_executor<Executor>(ex), token);
|
||||
}
|
||||
|
||||
template <typename ExecutionContext,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) post(
|
||||
ExecutionContext& ctx, ASIO_MOVE_ARG(CompletionToken) token,
|
||||
typename constraint<is_convertible<
|
||||
ExecutionContext&, execution_context&>::value>::type)
|
||||
{
|
||||
return async_initiate<CompletionToken, void()>(
|
||||
detail::initiate_post_with_executor<
|
||||
typename ExecutionContext::executor_type>(
|
||||
ctx.get_executor()), token);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_POST_HPP
|
||||
1214
extern/asio-1.18.2/include/asio/impl/read.hpp
vendored
Normal file
1214
extern/asio-1.18.2/include/asio/impl/read.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
744
extern/asio-1.18.2/include/asio/impl/read_at.hpp
vendored
Normal file
744
extern/asio-1.18.2/include/asio/impl/read_at.hpp
vendored
Normal file
@@ -0,0 +1,744 @@
|
||||
//
|
||||
// impl/read_at.hpp
|
||||
// ~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_READ_AT_HPP
|
||||
#define ASIO_IMPL_READ_AT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include <algorithm>
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/completion_condition.hpp"
|
||||
#include "asio/detail/array_fwd.hpp"
|
||||
#include "asio/detail/base_from_completion_cond.hpp"
|
||||
#include "asio/detail/bind_handler.hpp"
|
||||
#include "asio/detail/consuming_buffers.hpp"
|
||||
#include "asio/detail/dependent_type.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_cont_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/handler_tracking.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
#include "asio/error.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
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, asio::error_code& ec)
|
||||
{
|
||||
return detail::read_at_buffer_sequence(d, offset, buffers,
|
||||
asio::buffer_sequence_begin(buffers),
|
||||
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)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t bytes_transferred = read_at(
|
||||
d, offset, buffers, transfer_all(), ec);
|
||||
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,
|
||||
asio::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)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t bytes_transferred = read_at(d, offset, buffers,
|
||||
ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
|
||||
asio::detail::throw_error(ec, "read_at");
|
||||
return bytes_transferred;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_EXTENSIONS)
|
||||
#if !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
template <typename SyncRandomAccessReadDevice, typename Allocator,
|
||||
typename CompletionCondition>
|
||||
std::size_t read_at(SyncRandomAccessReadDevice& d,
|
||||
uint64_t offset, asio::basic_streambuf<Allocator>& b,
|
||||
CompletionCondition completion_condition, asio::error_code& ec)
|
||||
{
|
||||
ec = asio::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, asio::basic_streambuf<Allocator>& b)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t bytes_transferred = read_at(
|
||||
d, offset, b, transfer_all(), ec);
|
||||
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, asio::basic_streambuf<Allocator>& b,
|
||||
asio::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, asio::basic_streambuf<Allocator>& b,
|
||||
CompletionCondition completion_condition)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t bytes_transferred = read_at(d, offset, b,
|
||||
ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
|
||||
asio::detail::throw_error(ec, "read_at");
|
||||
return bytes_transferred;
|
||||
}
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
#endif // !defined(ASIO_NO_EXTENSIONS)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename AsyncRandomAccessReadDevice,
|
||||
typename MutableBufferSequence, typename MutableBufferIterator,
|
||||
typename CompletionCondition, typename ReadHandler>
|
||||
class read_at_op
|
||||
: detail::base_from_completion_cond<CompletionCondition>
|
||||
{
|
||||
public:
|
||||
read_at_op(AsyncRandomAccessReadDevice& device,
|
||||
uint64_t offset, const MutableBufferSequence& buffers,
|
||||
CompletionCondition& completion_condition, ReadHandler& handler)
|
||||
: detail::base_from_completion_cond<
|
||||
CompletionCondition>(completion_condition),
|
||||
device_(device),
|
||||
offset_(offset),
|
||||
buffers_(buffers),
|
||||
start_(0),
|
||||
handler_(ASIO_MOVE_CAST(ReadHandler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
read_at_op(const read_at_op& other)
|
||||
: detail::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)
|
||||
: detail::base_from_completion_cond<CompletionCondition>(
|
||||
ASIO_MOVE_CAST(detail::base_from_completion_cond<
|
||||
CompletionCondition>)(other)),
|
||||
device_(other.device_),
|
||||
offset_(other.offset_),
|
||||
buffers_(ASIO_MOVE_CAST(buffers_type)(other.buffers_)),
|
||||
start_(other.start_),
|
||||
handler_(ASIO_MOVE_CAST(ReadHandler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()(const asio::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());
|
||||
do
|
||||
{
|
||||
{
|
||||
ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_read_at"));
|
||||
device_.async_read_some_at(
|
||||
offset_ + buffers_.total_consumed(), buffers_.prepare(max_size),
|
||||
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());
|
||||
} while (max_size > 0);
|
||||
|
||||
handler_(ec, buffers_.total_consumed());
|
||||
}
|
||||
}
|
||||
|
||||
//private:
|
||||
typedef 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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(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
|
||||
: 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)(
|
||||
asio::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 ASIO_NOEXCEPT
|
||||
{
|
||||
return device_.get_executor();
|
||||
}
|
||||
|
||||
template <typename ReadHandler, typename MutableBufferSequence,
|
||||
typename CompletionCondition>
|
||||
void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
|
||||
uint64_t offset, const MutableBufferSequence& buffers,
|
||||
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.
|
||||
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,
|
||||
asio::buffer_sequence_begin(buffers),
|
||||
completion_cond2.value, handler2.value);
|
||||
}
|
||||
|
||||
private:
|
||||
AsyncRandomAccessReadDevice& device_;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
#if !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename AsyncRandomAccessReadDevice,
|
||||
typename MutableBufferSequence, typename MutableBufferIterator,
|
||||
typename CompletionCondition, typename ReadHandler, typename Allocator>
|
||||
struct associated_allocator<
|
||||
detail::read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
|
||||
MutableBufferIterator, CompletionCondition, ReadHandler>,
|
||||
Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<ReadHandler, Allocator>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::read_at_op<AsyncRandomAccessReadDevice,
|
||||
MutableBufferSequence, MutableBufferIterator,
|
||||
CompletionCondition, ReadHandler>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<ReadHandler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename AsyncRandomAccessReadDevice,
|
||||
typename MutableBufferSequence, typename MutableBufferIterator,
|
||||
typename CompletionCondition, typename ReadHandler, typename Executor>
|
||||
struct associated_executor<
|
||||
detail::read_at_op<AsyncRandomAccessReadDevice, MutableBufferSequence,
|
||||
MutableBufferIterator, CompletionCondition, ReadHandler>,
|
||||
Executor>
|
||||
: detail::associated_executor_forwarding_base<ReadHandler, Executor>
|
||||
{
|
||||
typedef typename associated_executor<ReadHandler, Executor>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::read_at_op<AsyncRandomAccessReadDevice,
|
||||
MutableBufferSequence, MutableBufferIterator,
|
||||
CompletionCondition, ReadHandler>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<ReadHandler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename AsyncRandomAccessReadDevice,
|
||||
typename MutableBufferSequence, typename CompletionCondition,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_at(AsyncRandomAccessReadDevice& d,
|
||||
uint64_t offset, const MutableBufferSequence& buffers,
|
||||
CompletionCondition completion_condition,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
detail::initiate_async_read_at_buffer_sequence<
|
||||
AsyncRandomAccessReadDevice>(d),
|
||||
handler, offset, buffers,
|
||||
ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
|
||||
}
|
||||
|
||||
template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_at(AsyncRandomAccessReadDevice& d,
|
||||
uint64_t offset, const MutableBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
detail::initiate_async_read_at_buffer_sequence<
|
||||
AsyncRandomAccessReadDevice>(d),
|
||||
handler, offset, buffers, transfer_all());
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_EXTENSIONS)
|
||||
#if !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename AsyncRandomAccessReadDevice, typename Allocator,
|
||||
typename CompletionCondition, typename ReadHandler>
|
||||
class read_at_streambuf_op
|
||||
: detail::base_from_completion_cond<CompletionCondition>
|
||||
{
|
||||
public:
|
||||
read_at_streambuf_op(AsyncRandomAccessReadDevice& device,
|
||||
uint64_t offset, basic_streambuf<Allocator>& streambuf,
|
||||
CompletionCondition& completion_condition, ReadHandler& handler)
|
||||
: detail::base_from_completion_cond<
|
||||
CompletionCondition>(completion_condition),
|
||||
device_(device),
|
||||
offset_(offset),
|
||||
streambuf_(streambuf),
|
||||
start_(0),
|
||||
total_transferred_(0),
|
||||
handler_(ASIO_MOVE_CAST(ReadHandler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
read_at_streambuf_op(const read_at_streambuf_op& other)
|
||||
: detail::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)
|
||||
: detail::base_from_completion_cond<CompletionCondition>(
|
||||
ASIO_MOVE_CAST(detail::base_from_completion_cond<
|
||||
CompletionCondition>)(other)),
|
||||
device_(other.device_),
|
||||
offset_(other.offset_),
|
||||
streambuf_(other.streambuf_),
|
||||
start_(other.start_),
|
||||
total_transferred_(other.total_transferred_),
|
||||
handler_(ASIO_MOVE_CAST(ReadHandler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()(const asio::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 (;;)
|
||||
{
|
||||
{
|
||||
ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_read_at"));
|
||||
device_.async_read_some_at(offset_ + total_transferred_,
|
||||
streambuf_.prepare(bytes_available),
|
||||
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;
|
||||
}
|
||||
|
||||
handler_(ec, static_cast<const std::size_t&>(total_transferred_));
|
||||
}
|
||||
}
|
||||
|
||||
//private:
|
||||
AsyncRandomAccessReadDevice& device_;
|
||||
uint64_t offset_;
|
||||
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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(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
|
||||
: 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return device_.get_executor();
|
||||
}
|
||||
|
||||
template <typename ReadHandler,
|
||||
typename Allocator, typename CompletionCondition>
|
||||
void operator()(ASIO_MOVE_ARG(ReadHandler) handler,
|
||||
uint64_t offset, basic_streambuf<Allocator>* b,
|
||||
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.
|
||||
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)(
|
||||
asio::error_code(), 0, 1);
|
||||
}
|
||||
|
||||
private:
|
||||
AsyncRandomAccessReadDevice& device_;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
#if !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename AsyncRandomAccessReadDevice, typename Allocator,
|
||||
typename CompletionCondition, typename ReadHandler, typename Allocator1>
|
||||
struct associated_allocator<
|
||||
detail::read_at_streambuf_op<AsyncRandomAccessReadDevice,
|
||||
Allocator, CompletionCondition, ReadHandler>,
|
||||
Allocator1>
|
||||
{
|
||||
typedef typename associated_allocator<ReadHandler, Allocator1>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::read_at_streambuf_op<AsyncRandomAccessReadDevice,
|
||||
Allocator, CompletionCondition, ReadHandler>& h,
|
||||
const Allocator1& a = Allocator1()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<ReadHandler, Allocator1>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename AsyncRandomAccessReadDevice, typename Executor,
|
||||
typename CompletionCondition, typename ReadHandler, typename Executor1>
|
||||
struct associated_executor<
|
||||
detail::read_at_streambuf_op<AsyncRandomAccessReadDevice,
|
||||
Executor, CompletionCondition, ReadHandler>,
|
||||
Executor1>
|
||||
: detail::associated_executor_forwarding_base<ReadHandler, Executor>
|
||||
{
|
||||
typedef typename associated_executor<ReadHandler, Executor1>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::read_at_streambuf_op<AsyncRandomAccessReadDevice,
|
||||
Executor, CompletionCondition, ReadHandler>& h,
|
||||
const Executor1& ex = Executor1()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<ReadHandler, Executor1>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename AsyncRandomAccessReadDevice,
|
||||
typename Allocator, typename CompletionCondition,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_at(AsyncRandomAccessReadDevice& d,
|
||||
uint64_t offset, asio::basic_streambuf<Allocator>& b,
|
||||
CompletionCondition completion_condition,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
detail::initiate_async_read_at_streambuf<AsyncRandomAccessReadDevice>(d),
|
||||
handler, offset, &b,
|
||||
ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
|
||||
}
|
||||
|
||||
template <typename AsyncRandomAccessReadDevice, typename Allocator,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) ReadHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(ReadHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_read_at(AsyncRandomAccessReadDevice& d,
|
||||
uint64_t offset, asio::basic_streambuf<Allocator>& b,
|
||||
ASIO_MOVE_ARG(ReadHandler) handler)
|
||||
{
|
||||
return async_initiate<ReadHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
detail::initiate_async_read_at_streambuf<AsyncRandomAccessReadDevice>(d),
|
||||
handler, offset, &b, transfer_all());
|
||||
}
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
#endif // !defined(ASIO_NO_EXTENSIONS)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_READ_AT_HPP
|
||||
3371
extern/asio-1.18.2/include/asio/impl/read_until.hpp
vendored
Normal file
3371
extern/asio-1.18.2/include/asio/impl/read_until.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
391
extern/asio-1.18.2/include/asio/impl/redirect_error.hpp
vendored
Normal file
391
extern/asio-1.18.2/include/asio/impl/redirect_error.hpp
vendored
Normal file
@@ -0,0 +1,391 @@
|
||||
|
||||
// impl/redirect_error.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_REDIRECT_ERROR_HPP
|
||||
#define ASIO_IMPL_REDIRECT_ERROR_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_cont_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/detail/variadic_templates.hpp"
|
||||
#include "asio/system_error.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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_(ASIO_MOVE_CAST(CompletionToken)(e.token_))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename RedirectedHandler>
|
||||
redirect_error_handler(asio::error_code& ec,
|
||||
ASIO_MOVE_ARG(RedirectedHandler) h)
|
||||
: ec_(ec),
|
||||
handler_(ASIO_MOVE_CAST(RedirectedHandler)(h))
|
||||
{
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
handler_();
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename Arg, typename... Args>
|
||||
typename enable_if<
|
||||
!is_same<typename decay<Arg>::type, asio::error_code>::value
|
||||
>::type
|
||||
operator()(ASIO_MOVE_ARG(Arg) arg, ASIO_MOVE_ARG(Args)... args)
|
||||
{
|
||||
handler_(ASIO_MOVE_CAST(Arg)(arg),
|
||||
ASIO_MOVE_CAST(Args)(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void operator()(const asio::error_code& ec,
|
||||
ASIO_MOVE_ARG(Args)... args)
|
||||
{
|
||||
ec_ = ec;
|
||||
handler_(ASIO_MOVE_CAST(Args)(args)...);
|
||||
}
|
||||
|
||||
#else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename Arg>
|
||||
typename enable_if<
|
||||
!is_same<typename decay<Arg>::type, asio::error_code>::value
|
||||
>::type
|
||||
operator()(ASIO_MOVE_ARG(Arg) arg)
|
||||
{
|
||||
handler_(ASIO_MOVE_CAST(Arg)(arg));
|
||||
}
|
||||
|
||||
void operator()(const asio::error_code& ec)
|
||||
{
|
||||
ec_ = ec;
|
||||
handler_();
|
||||
}
|
||||
|
||||
#define ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \
|
||||
template <typename Arg, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
typename enable_if< \
|
||||
!is_same<typename decay<Arg>::type, asio::error_code>::value \
|
||||
>::type \
|
||||
operator()(ASIO_MOVE_ARG(Arg) arg, ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
handler_(ASIO_MOVE_CAST(Arg)(arg), \
|
||||
ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
\
|
||||
template <ASIO_VARIADIC_TPARAMS(n)> \
|
||||
void operator()(const asio::error_code& ec, \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
ec_ = ec; \
|
||||
handler_(ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_REDIRECT_ERROR_DEF)
|
||||
#undef ASIO_PRIVATE_REDIRECT_ERROR_DEF
|
||||
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
//private:
|
||||
asio::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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
template <typename Handler>
|
||||
inline bool asio_handler_is_continuation(
|
||||
redirect_error_handler<Handler>* this_handler)
|
||||
{
|
||||
return 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
template <typename Signature>
|
||||
struct redirect_error_signature
|
||||
{
|
||||
typedef Signature type;
|
||||
};
|
||||
|
||||
#if defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename R, typename... Args>
|
||||
struct redirect_error_signature<R(asio::error_code, Args...)>
|
||||
{
|
||||
typedef R type(Args...);
|
||||
};
|
||||
|
||||
template <typename R, typename... Args>
|
||||
struct redirect_error_signature<R(const asio::error_code&, Args...)>
|
||||
{
|
||||
typedef R type(Args...);
|
||||
};
|
||||
|
||||
#else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename R>
|
||||
struct redirect_error_signature<R(asio::error_code)>
|
||||
{
|
||||
typedef R type();
|
||||
};
|
||||
|
||||
template <typename R>
|
||||
struct redirect_error_signature<R(const asio::error_code&)>
|
||||
{
|
||||
typedef R type();
|
||||
};
|
||||
|
||||
#define ASIO_PRIVATE_REDIRECT_ERROR_DEF(n) \
|
||||
template <typename R, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
struct redirect_error_signature< \
|
||||
R(asio::error_code, ASIO_VARIADIC_TARGS(n))> \
|
||||
{ \
|
||||
typedef R type(ASIO_VARIADIC_TARGS(n)); \
|
||||
}; \
|
||||
\
|
||||
template <typename R, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
struct redirect_error_signature< \
|
||||
R(const asio::error_code&, ASIO_VARIADIC_TARGS(n))> \
|
||||
{ \
|
||||
typedef R type(ASIO_VARIADIC_TARGS(n)); \
|
||||
}; \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_REDIRECT_ERROR_DEF)
|
||||
#undef ASIO_PRIVATE_REDIRECT_ERROR_DEF
|
||||
|
||||
#endif // defined(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(asio::error_code& ec, ASIO_MOVE_ARG(Init) init)
|
||||
: ec_(ec),
|
||||
initiation_(ASIO_MOVE_CAST(Init)(init))
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename Handler, typename... Args>
|
||||
void operator()(
|
||||
ASIO_MOVE_ARG(Handler) handler,
|
||||
ASIO_MOVE_ARG(Args)... args)
|
||||
{
|
||||
ASIO_MOVE_CAST(Initiation)(initiation_)(
|
||||
detail::redirect_error_handler<
|
||||
typename decay<Handler>::type>(
|
||||
ec_, ASIO_MOVE_CAST(Handler)(handler)),
|
||||
ASIO_MOVE_CAST(Args)(args)...);
|
||||
}
|
||||
|
||||
#else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename Handler>
|
||||
void operator()(
|
||||
ASIO_MOVE_ARG(Handler) handler)
|
||||
{
|
||||
ASIO_MOVE_CAST(Initiation)(initiation_)(
|
||||
detail::redirect_error_handler<
|
||||
typename decay<Handler>::type>(
|
||||
ec_, ASIO_MOVE_CAST(Handler)(handler)));
|
||||
}
|
||||
|
||||
#define ASIO_PRIVATE_INIT_WRAPPER_DEF(n) \
|
||||
template <typename Handler, ASIO_VARIADIC_TPARAMS(n)> \
|
||||
void operator()( \
|
||||
ASIO_MOVE_ARG(Handler) handler, \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
ASIO_MOVE_CAST(Initiation)(initiation_)( \
|
||||
detail::redirect_error_handler< \
|
||||
typename decay<Handler>::type>( \
|
||||
ec_, ASIO_MOVE_CAST(Handler)(handler)), \
|
||||
ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_INIT_WRAPPER_DEF)
|
||||
#undef ASIO_PRIVATE_INIT_WRAPPER_DEF
|
||||
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
asio::error_code& ec_;
|
||||
Initiation initiation_;
|
||||
};
|
||||
|
||||
#if defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename Initiation, typename RawCompletionToken, typename... Args>
|
||||
static return_type initiate(
|
||||
ASIO_MOVE_ARG(Initiation) initiation,
|
||||
ASIO_MOVE_ARG(RawCompletionToken) token,
|
||||
ASIO_MOVE_ARG(Args)... args)
|
||||
{
|
||||
return async_initiate<CompletionToken,
|
||||
typename detail::redirect_error_signature<Signature>::type>(
|
||||
init_wrapper<typename decay<Initiation>::type>(
|
||||
token.ec_, ASIO_MOVE_CAST(Initiation)(initiation)),
|
||||
token.token_, ASIO_MOVE_CAST(Args)(args)...);
|
||||
}
|
||||
|
||||
#else // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
|
||||
template <typename Initiation, typename RawCompletionToken>
|
||||
static return_type initiate(
|
||||
ASIO_MOVE_ARG(Initiation) initiation,
|
||||
ASIO_MOVE_ARG(RawCompletionToken) token)
|
||||
{
|
||||
return async_initiate<CompletionToken,
|
||||
typename detail::redirect_error_signature<Signature>::type>(
|
||||
init_wrapper<typename decay<Initiation>::type>(
|
||||
token.ec_, ASIO_MOVE_CAST(Initiation)(initiation)),
|
||||
token.token_);
|
||||
}
|
||||
|
||||
#define ASIO_PRIVATE_INITIATE_DEF(n) \
|
||||
template <typename Initiation, typename RawCompletionToken, \
|
||||
ASIO_VARIADIC_TPARAMS(n)> \
|
||||
static return_type initiate( \
|
||||
ASIO_MOVE_ARG(Initiation) initiation, \
|
||||
ASIO_MOVE_ARG(RawCompletionToken) token, \
|
||||
ASIO_VARIADIC_MOVE_PARAMS(n)) \
|
||||
{ \
|
||||
return async_initiate<CompletionToken, \
|
||||
typename detail::redirect_error_signature<Signature>::type>( \
|
||||
init_wrapper<typename decay<Initiation>::type>( \
|
||||
token.ec_, ASIO_MOVE_CAST(Initiation)(initiation)), \
|
||||
token.token_, ASIO_VARIADIC_MOVE_ARGS(n)); \
|
||||
} \
|
||||
/**/
|
||||
ASIO_VARIADIC_GENERATE(ASIO_PRIVATE_INITIATE_DEF)
|
||||
#undef ASIO_PRIVATE_INITIATE_DEF
|
||||
|
||||
#endif // defined(ASIO_HAS_VARIADIC_TEMPLATES)
|
||||
};
|
||||
|
||||
template <typename Handler, typename Executor>
|
||||
struct associated_executor<detail::redirect_error_handler<Handler>, Executor>
|
||||
: detail::associated_executor_forwarding_base<Handler, Executor>
|
||||
{
|
||||
typedef typename associated_executor<Handler, Executor>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::redirect_error_handler<Handler>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<Handler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Handler, typename Allocator>
|
||||
struct associated_allocator<detail::redirect_error_handler<Handler>, Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<Handler, Allocator>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::redirect_error_handler<Handler>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<Handler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_REDIRECT_ERROR_HPP
|
||||
59
extern/asio-1.18.2/include/asio/impl/serial_port_base.hpp
vendored
Normal file
59
extern/asio-1.18.2/include/asio/impl/serial_port_base.hpp
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// impl/serial_port_base.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 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 ASIO_IMPL_SERIAL_PORT_BASE_HPP
|
||||
#define ASIO_IMPL_SERIAL_PORT_BASE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_SERIAL_PORT_BASE_HPP
|
||||
554
extern/asio-1.18.2/include/asio/impl/serial_port_base.ipp
vendored
Normal file
554
extern/asio-1.18.2/include/asio/impl/serial_port_base.ipp
vendored
Normal file
@@ -0,0 +1,554 @@
|
||||
//
|
||||
// impl/serial_port_base.ipp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 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 ASIO_IMPL_SERIAL_PORT_BASE_IPP
|
||||
#define ASIO_IMPL_SERIAL_PORT_BASE_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HAS_SERIAL_PORT)
|
||||
|
||||
#include <stdexcept>
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/serial_port_base.hpp"
|
||||
#include "asio/detail/throw_exception.hpp"
|
||||
|
||||
#if defined(GENERATING_DOCUMENTATION)
|
||||
# define ASIO_OPTION_STORAGE implementation_defined
|
||||
#elif defined(ASIO_WINDOWS) || defined(__CYGWIN__)
|
||||
# define ASIO_OPTION_STORAGE DCB
|
||||
#else
|
||||
# define ASIO_OPTION_STORAGE termios
|
||||
#endif
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
ASIO_SYNC_OP_VOID serial_port_base::baud_rate::store(
|
||||
ASIO_OPTION_STORAGE& storage, asio::error_code& ec) const
|
||||
{
|
||||
#if defined(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 = asio::error::invalid_argument;
|
||||
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 = asio::error_code();
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
ASIO_SYNC_OP_VOID serial_port_base::baud_rate::load(
|
||||
const ASIO_OPTION_STORAGE& storage, asio::error_code& ec)
|
||||
{
|
||||
#if defined(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 = asio::error::invalid_argument;
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
#endif
|
||||
ec = asio::error_code();
|
||||
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");
|
||||
asio::detail::throw_exception(ex);
|
||||
}
|
||||
}
|
||||
|
||||
ASIO_SYNC_OP_VOID serial_port_base::flow_control::store(
|
||||
ASIO_OPTION_STORAGE& storage, asio::error_code& ec) const
|
||||
{
|
||||
#if defined(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 = asio::error::operation_not_supported;
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
# endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
ec = asio::error_code();
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
ASIO_SYNC_OP_VOID serial_port_base::flow_control::load(
|
||||
const ASIO_OPTION_STORAGE& storage, asio::error_code& ec)
|
||||
{
|
||||
#if defined(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 = asio::error_code();
|
||||
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");
|
||||
asio::detail::throw_exception(ex);
|
||||
}
|
||||
}
|
||||
|
||||
ASIO_SYNC_OP_VOID serial_port_base::parity::store(
|
||||
ASIO_OPTION_STORAGE& storage, asio::error_code& ec) const
|
||||
{
|
||||
#if defined(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 = asio::error_code();
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
ASIO_SYNC_OP_VOID serial_port_base::parity::load(
|
||||
const ASIO_OPTION_STORAGE& storage, asio::error_code& ec)
|
||||
{
|
||||
#if defined(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 = asio::error_code();
|
||||
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");
|
||||
asio::detail::throw_exception(ex);
|
||||
}
|
||||
}
|
||||
|
||||
ASIO_SYNC_OP_VOID serial_port_base::stop_bits::store(
|
||||
ASIO_OPTION_STORAGE& storage, asio::error_code& ec) const
|
||||
{
|
||||
#if defined(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 = asio::error::operation_not_supported;
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
#endif
|
||||
ec = asio::error_code();
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
ASIO_SYNC_OP_VOID serial_port_base::stop_bits::load(
|
||||
const ASIO_OPTION_STORAGE& storage, asio::error_code& ec)
|
||||
{
|
||||
#if defined(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 = asio::error_code();
|
||||
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");
|
||||
asio::detail::throw_exception(ex);
|
||||
}
|
||||
}
|
||||
|
||||
ASIO_SYNC_OP_VOID serial_port_base::character_size::store(
|
||||
ASIO_OPTION_STORAGE& storage, asio::error_code& ec) const
|
||||
{
|
||||
#if defined(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 = asio::error_code();
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
ASIO_SYNC_OP_VOID serial_port_base::character_size::load(
|
||||
const ASIO_OPTION_STORAGE& storage, asio::error_code& ec)
|
||||
{
|
||||
#if defined(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 = asio::error_code();
|
||||
ASIO_SYNC_OP_VOID_RETURN(ec);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#undef ASIO_OPTION_STORAGE
|
||||
|
||||
#endif // defined(ASIO_HAS_SERIAL_PORT)
|
||||
|
||||
#endif // ASIO_IMPL_SERIAL_PORT_BASE_IPP
|
||||
527
extern/asio-1.18.2/include/asio/impl/spawn.hpp
vendored
Normal file
527
extern/asio-1.18.2/include/asio/impl/spawn.hpp
vendored
Normal file
@@ -0,0 +1,527 @@
|
||||
//
|
||||
// impl/spawn.hpp
|
||||
// ~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_SPAWN_HPP
|
||||
#define ASIO_IMPL_SPAWN_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/async_result.hpp"
|
||||
#include "asio/bind_executor.hpp"
|
||||
#include "asio/detail/atomic_count.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_cont_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/memory.hpp"
|
||||
#include "asio/detail/noncopyable.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/system_error.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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_ = asio::error_code();
|
||||
*value_ = ASIO_MOVE_CAST(T)(value);
|
||||
if (--*ready_ == 0)
|
||||
(*coro_)();
|
||||
}
|
||||
|
||||
void operator()(asio::error_code ec, T value)
|
||||
{
|
||||
*ec_ = ec;
|
||||
*value_ = 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_;
|
||||
asio::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_ = asio::error_code();
|
||||
if (--*ready_ == 0)
|
||||
(*coro_)();
|
||||
}
|
||||
|
||||
void operator()(asio::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_;
|
||||
asio::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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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 asio::system_error(ec_);
|
||||
return ASIO_MOVE_CAST(return_type)(value_);
|
||||
}
|
||||
|
||||
private:
|
||||
completion_handler_type& handler_;
|
||||
typename basic_yield_context<Handler>::caller_type& ca_;
|
||||
atomic_count ready_;
|
||||
asio::error_code* out_ec_;
|
||||
asio::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 asio::system_error(ec_);
|
||||
}
|
||||
|
||||
private:
|
||||
completion_handler_type& handler_;
|
||||
typename basic_yield_context<Handler>::caller_type& ca_;
|
||||
atomic_count ready_;
|
||||
asio::error_code* out_ec_;
|
||||
asio::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(asio::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(asio::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 <typename Handler, typename T, typename Allocator>
|
||||
struct associated_allocator<detail::coro_handler<Handler, T>, Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<Handler, Allocator>::type type;
|
||||
|
||||
static type get(const detail::coro_handler<Handler, T>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<Handler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Handler, typename T, typename Executor>
|
||||
struct associated_executor<detail::coro_handler<Handler, T>, Executor>
|
||||
: detail::associated_executor_forwarding_base<Handler, Executor>
|
||||
{
|
||||
typedef typename associated_executor<Handler, Executor>::type type;
|
||||
|
||||
static type get(const detail::coro_handler<Handler, T>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<Handler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename Handler, typename Function>
|
||||
struct spawn_data : private noncopyable
|
||||
{
|
||||
template <typename Hand, typename Func>
|
||||
spawn_data(ASIO_MOVE_ARG(Hand) handler,
|
||||
bool call_handler, ASIO_MOVE_ARG(Func) function)
|
||||
: handler_(ASIO_MOVE_CAST(Hand)(handler)),
|
||||
call_handler_(call_handler),
|
||||
function_(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_)
|
||||
(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return (get_associated_allocator)(data_->handler_);
|
||||
}
|
||||
|
||||
typedef typename associated_executor<Handler>::type executor_type;
|
||||
|
||||
executor_type get_executor() const 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->data_->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->data_->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
inline void default_spawn_handler() {}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename Function>
|
||||
inline void spawn(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));
|
||||
|
||||
asio::spawn(ex, ASIO_MOVE_CAST(Function)(function), attributes);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Function>
|
||||
void spawn(ASIO_MOVE_ARG(Handler) handler,
|
||||
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>(
|
||||
ASIO_MOVE_CAST(Handler)(handler), true,
|
||||
ASIO_MOVE_CAST(Function)(function)));
|
||||
helper.attributes_ = attributes;
|
||||
|
||||
asio::dispatch(helper);
|
||||
}
|
||||
|
||||
template <typename Handler, typename Function>
|
||||
void spawn(basic_yield_context<Handler> ctx,
|
||||
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>(
|
||||
ASIO_MOVE_CAST(Handler)(handler), false,
|
||||
ASIO_MOVE_CAST(Function)(function)));
|
||||
helper.attributes_ = attributes;
|
||||
|
||||
asio::dispatch(helper);
|
||||
}
|
||||
|
||||
template <typename Function, typename Executor>
|
||||
inline void spawn(const Executor& ex,
|
||||
ASIO_MOVE_ARG(Function) function,
|
||||
const boost::coroutines::attributes& attributes,
|
||||
typename constraint<
|
||||
is_executor<Executor>::value || execution::is_executor<Executor>::value
|
||||
>::type)
|
||||
{
|
||||
asio::spawn(asio::strand<Executor>(ex),
|
||||
ASIO_MOVE_CAST(Function)(function), attributes);
|
||||
}
|
||||
|
||||
template <typename Function, typename Executor>
|
||||
inline void spawn(const strand<Executor>& ex,
|
||||
ASIO_MOVE_ARG(Function) function,
|
||||
const boost::coroutines::attributes& attributes)
|
||||
{
|
||||
asio::spawn(asio::bind_executor(
|
||||
ex, &detail::default_spawn_handler),
|
||||
ASIO_MOVE_CAST(Function)(function), attributes);
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_TS_EXECUTORS)
|
||||
|
||||
template <typename Function>
|
||||
inline void spawn(const asio::io_context::strand& s,
|
||||
ASIO_MOVE_ARG(Function) function,
|
||||
const boost::coroutines::attributes& attributes)
|
||||
{
|
||||
asio::spawn(asio::bind_executor(
|
||||
s, &detail::default_spawn_handler),
|
||||
ASIO_MOVE_CAST(Function)(function), attributes);
|
||||
}
|
||||
|
||||
#endif // !defined(ASIO_NO_TS_EXECUTORS)
|
||||
|
||||
template <typename Function, typename ExecutionContext>
|
||||
inline void spawn(ExecutionContext& ctx,
|
||||
ASIO_MOVE_ARG(Function) function,
|
||||
const boost::coroutines::attributes& attributes,
|
||||
typename constraint<is_convertible<
|
||||
ExecutionContext&, execution_context&>::value>::type)
|
||||
{
|
||||
asio::spawn(ctx.get_executor(),
|
||||
ASIO_MOVE_CAST(Function)(function), attributes);
|
||||
}
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_SPAWN_HPP
|
||||
86
extern/asio-1.18.2/include/asio/impl/src.hpp
vendored
Normal file
86
extern/asio-1.18.2/include/asio/impl/src.hpp
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// impl/src.hpp
|
||||
// ~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_SRC_HPP
|
||||
#define ASIO_IMPL_SRC_HPP
|
||||
|
||||
#define ASIO_SOURCE
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
|
||||
#if defined(ASIO_HEADER_ONLY)
|
||||
# error Do not compile Asio library source with ASIO_HEADER_ONLY defined
|
||||
#endif
|
||||
|
||||
#include "asio/impl/error.ipp"
|
||||
#include "asio/impl/error_code.ipp"
|
||||
#include "asio/impl/execution_context.ipp"
|
||||
#include "asio/impl/executor.ipp"
|
||||
#include "asio/impl/handler_alloc_hook.ipp"
|
||||
#include "asio/impl/io_context.ipp"
|
||||
#include "asio/impl/multiple_exceptions.ipp"
|
||||
#include "asio/impl/serial_port_base.ipp"
|
||||
#include "asio/impl/system_context.ipp"
|
||||
#include "asio/impl/thread_pool.ipp"
|
||||
#include "asio/detail/impl/buffer_sequence_adapter.ipp"
|
||||
#include "asio/detail/impl/descriptor_ops.ipp"
|
||||
#include "asio/detail/impl/dev_poll_reactor.ipp"
|
||||
#include "asio/detail/impl/epoll_reactor.ipp"
|
||||
#include "asio/detail/impl/eventfd_select_interrupter.ipp"
|
||||
#include "asio/detail/impl/handler_tracking.ipp"
|
||||
#include "asio/detail/impl/kqueue_reactor.ipp"
|
||||
#include "asio/detail/impl/null_event.ipp"
|
||||
#include "asio/detail/impl/pipe_select_interrupter.ipp"
|
||||
#include "asio/detail/impl/posix_event.ipp"
|
||||
#include "asio/detail/impl/posix_mutex.ipp"
|
||||
#include "asio/detail/impl/posix_thread.ipp"
|
||||
#include "asio/detail/impl/posix_tss_ptr.ipp"
|
||||
#include "asio/detail/impl/reactive_descriptor_service.ipp"
|
||||
#include "asio/detail/impl/reactive_serial_port_service.ipp"
|
||||
#include "asio/detail/impl/reactive_socket_service_base.ipp"
|
||||
#include "asio/detail/impl/resolver_service_base.ipp"
|
||||
#include "asio/detail/impl/scheduler.ipp"
|
||||
#include "asio/detail/impl/select_reactor.ipp"
|
||||
#include "asio/detail/impl/service_registry.ipp"
|
||||
#include "asio/detail/impl/signal_set_service.ipp"
|
||||
#include "asio/detail/impl/socket_ops.ipp"
|
||||
#include "asio/detail/impl/socket_select_interrupter.ipp"
|
||||
#include "asio/detail/impl/strand_executor_service.ipp"
|
||||
#include "asio/detail/impl/strand_service.ipp"
|
||||
#include "asio/detail/impl/thread_context.ipp"
|
||||
#include "asio/detail/impl/throw_error.ipp"
|
||||
#include "asio/detail/impl/timer_queue_ptime.ipp"
|
||||
#include "asio/detail/impl/timer_queue_set.ipp"
|
||||
#include "asio/detail/impl/win_iocp_handle_service.ipp"
|
||||
#include "asio/detail/impl/win_iocp_io_context.ipp"
|
||||
#include "asio/detail/impl/win_iocp_serial_port_service.ipp"
|
||||
#include "asio/detail/impl/win_iocp_socket_service_base.ipp"
|
||||
#include "asio/detail/impl/win_event.ipp"
|
||||
#include "asio/detail/impl/win_mutex.ipp"
|
||||
#include "asio/detail/impl/win_object_handle_service.ipp"
|
||||
#include "asio/detail/impl/win_static_mutex.ipp"
|
||||
#include "asio/detail/impl/win_thread.ipp"
|
||||
#include "asio/detail/impl/win_tss_ptr.ipp"
|
||||
#include "asio/detail/impl/winrt_ssocket_service_base.ipp"
|
||||
#include "asio/detail/impl/winrt_timer_scheduler.ipp"
|
||||
#include "asio/detail/impl/winsock_init.ipp"
|
||||
#include "asio/execution/impl/bad_executor.ipp"
|
||||
#include "asio/execution/impl/receiver_invocation_error.ipp"
|
||||
#include "asio/generic/detail/impl/endpoint.ipp"
|
||||
#include "asio/ip/impl/address.ipp"
|
||||
#include "asio/ip/impl/address_v4.ipp"
|
||||
#include "asio/ip/impl/address_v6.ipp"
|
||||
#include "asio/ip/impl/host_name.ipp"
|
||||
#include "asio/ip/impl/network_v4.ipp"
|
||||
#include "asio/ip/impl/network_v6.ipp"
|
||||
#include "asio/ip/detail/impl/endpoint.ipp"
|
||||
#include "asio/local/detail/impl/endpoint.ipp"
|
||||
|
||||
#endif // ASIO_IMPL_SRC_HPP
|
||||
34
extern/asio-1.18.2/include/asio/impl/system_context.hpp
vendored
Normal file
34
extern/asio-1.18.2/include/asio/impl/system_context.hpp
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// impl/system_context.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_SYSTEM_CONTEXT_HPP
|
||||
#define ASIO_IMPL_SYSTEM_CONTEXT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/system_executor.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
inline system_context::executor_type
|
||||
system_context::get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return system_executor();
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_SYSTEM_CONTEXT_HPP
|
||||
92
extern/asio-1.18.2/include/asio/impl/system_context.ipp
vendored
Normal file
92
extern/asio-1.18.2/include/asio/impl/system_context.ipp
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// impl/system_context.ipp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_SYSTEM_CONTEXT_IPP
|
||||
#define ASIO_IMPL_SYSTEM_CONTEXT_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/system_context.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
struct system_context::thread_function
|
||||
{
|
||||
detail::scheduler* scheduler_;
|
||||
|
||||
void operator()()
|
||||
{
|
||||
#if !defined(ASIO_NO_EXCEPTIONS)
|
||||
try
|
||||
{
|
||||
#endif// !defined(ASIO_NO_EXCEPTIONS)
|
||||
asio::error_code ec;
|
||||
scheduler_->run(ec);
|
||||
#if !defined(ASIO_NO_EXCEPTIONS)
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
#endif// !defined(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 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);
|
||||
asio::add_service<detail::scheduler>(*this, scoped_impl.get());
|
||||
return *scoped_impl.release();
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_SYSTEM_CONTEXT_IPP
|
||||
185
extern/asio-1.18.2/include/asio/impl/system_executor.hpp
vendored
Normal file
185
extern/asio-1.18.2/include/asio/impl/system_executor.hpp
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
//
|
||||
// impl/system_executor.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_SYSTEM_EXECUTOR_HPP
|
||||
#define ASIO_IMPL_SYSTEM_EXECUTOR_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/executor_op.hpp"
|
||||
#include "asio/detail/global.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/system_context.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
template <typename Blocking, typename Relationship, typename Allocator>
|
||||
inline system_context&
|
||||
basic_system_executor<Blocking, Relationship, Allocator>::query(
|
||||
execution::context_t) 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 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(
|
||||
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(ASIO_NO_EXCEPTIONS)
|
||||
try
|
||||
{
|
||||
#endif// !defined(ASIO_NO_EXCEPTIONS)
|
||||
detail::fenced_block b(detail::fenced_block::full);
|
||||
asio_handler_invoke_helpers::invoke(f2.value, f2.value);
|
||||
#if !defined(ASIO_NO_EXCEPTIONS)
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
#endif// !defined(ASIO_NO_EXCEPTIONS)
|
||||
}
|
||||
|
||||
template <typename Blocking, typename Relationship, typename Allocator>
|
||||
template <typename Function>
|
||||
inline void
|
||||
basic_system_executor<Blocking, Relationship, Allocator>::do_execute(
|
||||
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(ASIO_NO_EXCEPTIONS)
|
||||
try
|
||||
{
|
||||
#endif// !defined(ASIO_NO_EXCEPTIONS)
|
||||
detail::fenced_block b(detail::fenced_block::full);
|
||||
asio_handler_invoke_helpers::invoke(f2.value, f2.value);
|
||||
#if !defined(ASIO_NO_EXCEPTIONS)
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
#endif// !defined(ASIO_NO_EXCEPTIONS)
|
||||
}
|
||||
|
||||
template <typename Blocking, typename Relationship, typename Allocator>
|
||||
template <typename Function>
|
||||
void basic_system_executor<Blocking, Relationship, Allocator>::do_execute(
|
||||
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(ASIO_MOVE_CAST(Function)(f), allocator_);
|
||||
|
||||
if (is_same<Relationship, execution::relationship_t::continuation_t>::value)
|
||||
{
|
||||
ASIO_HANDLER_CREATION((ctx, *p.p,
|
||||
"system_executor", &ctx, 0, "execute(blk=never,rel=cont)"));
|
||||
}
|
||||
else
|
||||
{
|
||||
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(ASIO_NO_TS_EXECUTORS)
|
||||
template <typename Blocking, typename Relationship, typename Allocator>
|
||||
inline system_context& basic_system_executor<
|
||||
Blocking, Relationship, Allocator>::context() const 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(
|
||||
ASIO_MOVE_ARG(Function) f, const OtherAllocator&) const
|
||||
{
|
||||
typename decay<Function>::type tmp(ASIO_MOVE_CAST(Function)(f));
|
||||
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(
|
||||
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(ASIO_MOVE_CAST(Function)(f), a);
|
||||
|
||||
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(
|
||||
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(ASIO_MOVE_CAST(Function)(f), a);
|
||||
|
||||
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(ASIO_NO_TS_EXECUTORS)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_SYSTEM_EXECUTOR_HPP
|
||||
354
extern/asio-1.18.2/include/asio/impl/thread_pool.hpp
vendored
Normal file
354
extern/asio-1.18.2/include/asio/impl/thread_pool.hpp
vendored
Normal file
@@ -0,0 +1,354 @@
|
||||
//
|
||||
// impl/thread_pool.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_THREAD_POOL_HPP
|
||||
#define ASIO_IMPL_THREAD_POOL_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/blocking_executor_op.hpp"
|
||||
#include "asio/detail/bulk_executor_op.hpp"
|
||||
#include "asio/detail/executor_op.hpp"
|
||||
#include "asio/detail/fenced_block.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/type_traits.hpp"
|
||||
#include "asio/execution_context.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
inline thread_pool::executor_type
|
||||
thread_pool::get_executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return executor_type(*this);
|
||||
}
|
||||
|
||||
inline thread_pool::executor_type
|
||||
thread_pool::executor() ASIO_NOEXCEPT
|
||||
{
|
||||
return executor_type(*this);
|
||||
}
|
||||
|
||||
inline thread_pool::scheduler_type
|
||||
thread_pool::scheduler() 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) 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(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) 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(ASIO_HAS_MOVE)
|
||||
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
inline bool thread_pool::basic_executor_type<Allocator,
|
||||
Bits>::running_in_this_thread() const 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(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(ASIO_MOVE_CAST(Function)(f));
|
||||
|
||||
#if defined(ASIO_HAS_STD_EXCEPTION_PTR) \
|
||||
&& !defined(ASIO_NO_EXCEPTIONS)
|
||||
try
|
||||
{
|
||||
#endif // defined(ASIO_HAS_STD_EXCEPTION_PTR)
|
||||
// && !defined(ASIO_NO_EXCEPTIONS)
|
||||
detail::fenced_block b(detail::fenced_block::full);
|
||||
asio_handler_invoke_helpers::invoke(tmp, tmp);
|
||||
return;
|
||||
#if defined(ASIO_HAS_STD_EXCEPTION_PTR) \
|
||||
&& !defined(ASIO_NO_EXCEPTIONS)
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
pool_->scheduler_.capture_current_exception();
|
||||
return;
|
||||
}
|
||||
#endif // defined(ASIO_HAS_STD_EXCEPTION_PTR)
|
||||
// && !defined(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(ASIO_MOVE_CAST(Function)(f), allocator_);
|
||||
|
||||
if ((bits_ & relationship_continuation) != 0)
|
||||
{
|
||||
ASIO_HANDLER_CREATION((*pool_, *p.p,
|
||||
"thread_pool", pool_, 0, "execute(blk=never,rel=cont)"));
|
||||
}
|
||||
else
|
||||
{
|
||||
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(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(ASIO_NO_EXCEPTIONS)
|
||||
try
|
||||
{
|
||||
#endif // !defined(ASIO_NO_EXCEPTIONS)
|
||||
detail::fenced_block b(detail::fenced_block::full);
|
||||
asio_handler_invoke_helpers::invoke(f2.value, f2.value);
|
||||
return;
|
||||
#if !defined(ASIO_NO_EXCEPTIONS)
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
#endif // !defined(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);
|
||||
|
||||
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(
|
||||
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(ASIO_MOVE_CAST(Function)(f), allocator_, i);
|
||||
ops.push(p.p);
|
||||
|
||||
if ((bits_ & relationship_continuation) != 0)
|
||||
{
|
||||
ASIO_HANDLER_CREATION((*pool_, *p.p,
|
||||
"thread_pool", pool_, 0, "bulk_execute(blk=never,rel=cont)"));
|
||||
}
|
||||
else
|
||||
{
|
||||
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(
|
||||
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(ASIO_NO_TS_EXECUTORS)
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
inline thread_pool& thread_pool::basic_executor_type<
|
||||
Allocator, Bits>::context() const ASIO_NOEXCEPT
|
||||
{
|
||||
return *pool_;
|
||||
}
|
||||
|
||||
template <typename Allocator, unsigned int Bits>
|
||||
inline void thread_pool::basic_executor_type<Allocator,
|
||||
Bits>::on_work_started() const 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 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(
|
||||
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(ASIO_MOVE_CAST(Function)(f));
|
||||
|
||||
detail::fenced_block b(detail::fenced_block::full);
|
||||
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(ASIO_MOVE_CAST(Function)(f), a);
|
||||
|
||||
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(
|
||||
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(ASIO_MOVE_CAST(Function)(f), a);
|
||||
|
||||
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(
|
||||
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(ASIO_MOVE_CAST(Function)(f), a);
|
||||
|
||||
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(ASIO_NO_TS_EXECUTORS)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_THREAD_POOL_HPP
|
||||
141
extern/asio-1.18.2/include/asio/impl/thread_pool.ipp
vendored
Normal file
141
extern/asio-1.18.2/include/asio/impl/thread_pool.ipp
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// impl/thread_pool.ipp
|
||||
// ~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_THREAD_POOL_IPP
|
||||
#define ASIO_IMPL_THREAD_POOL_IPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include <stdexcept>
|
||||
#include "asio/thread_pool.hpp"
|
||||
#include "asio/detail/throw_exception.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
struct thread_pool::thread_function
|
||||
{
|
||||
detail::scheduler* scheduler_;
|
||||
|
||||
void operator()()
|
||||
{
|
||||
#if !defined(ASIO_NO_EXCEPTIONS)
|
||||
try
|
||||
{
|
||||
#endif// !defined(ASIO_NO_EXCEPTIONS)
|
||||
asio::error_code ec;
|
||||
scheduler_->run(ec);
|
||||
#if !defined(ASIO_NO_EXCEPTIONS)
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
#endif// !defined(ASIO_NO_EXCEPTIONS)
|
||||
}
|
||||
};
|
||||
|
||||
#if !defined(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(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");
|
||||
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);
|
||||
asio::add_service<detail::scheduler>(*this, scoped_impl.get());
|
||||
return *scoped_impl.release();
|
||||
}
|
||||
|
||||
void thread_pool::wait()
|
||||
{
|
||||
scheduler_.work_finished();
|
||||
threads_.join();
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_THREAD_POOL_IPP
|
||||
279
extern/asio-1.18.2/include/asio/impl/use_awaitable.hpp
vendored
Normal file
279
extern/asio-1.18.2/include/asio/impl/use_awaitable.hpp
vendored
Normal file
@@ -0,0 +1,279 @@
|
||||
//
|
||||
// impl/use_awaitable.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_USE_AWAITABLE_HPP
|
||||
#define ASIO_IMPL_USE_AWAITABLE_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/config.hpp"
|
||||
#include "asio/async_result.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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<void, Executor> a, const Executor& ex)
|
||||
: awaitable_thread<Executor>(std::move(a), ex)
|
||||
{
|
||||
}
|
||||
|
||||
// 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->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()->pop_frame();
|
||||
this->pump();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Executor>
|
||||
class awaitable_handler<Executor, asio::error_code>
|
||||
: public awaitable_handler_base<Executor, void>
|
||||
{
|
||||
public:
|
||||
using awaitable_handler_base<Executor, void>::awaitable_handler_base;
|
||||
|
||||
void operator()(const asio::error_code& ec)
|
||||
{
|
||||
this->frame()->attach_thread(this);
|
||||
if (ec)
|
||||
this->frame()->set_error(ec);
|
||||
else
|
||||
this->frame()->return_void();
|
||||
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()->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()->pop_frame();
|
||||
this->pump();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Executor, typename T>
|
||||
class awaitable_handler<Executor, asio::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 asio::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()->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()->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()->pop_frame();
|
||||
this->pump();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Executor, typename... Ts>
|
||||
class awaitable_handler<Executor, asio::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 asio::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()->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()->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>
|
||||
static return_type initiate(Initiation initiation,
|
||||
use_awaitable_t<Executor> u, InitArgs... args)
|
||||
{
|
||||
(void)u;
|
||||
|
||||
co_await [&](auto* frame)
|
||||
{
|
||||
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 static_cast<handler_type*>(nullptr);
|
||||
};
|
||||
|
||||
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
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_USE_AWAITABLE_HPP
|
||||
1028
extern/asio-1.18.2/include/asio/impl/use_future.hpp
vendored
Normal file
1028
extern/asio-1.18.2/include/asio/impl/use_future.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1116
extern/asio-1.18.2/include/asio/impl/write.hpp
vendored
Normal file
1116
extern/asio-1.18.2/include/asio/impl/write.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
666
extern/asio-1.18.2/include/asio/impl/write_at.hpp
vendored
Normal file
666
extern/asio-1.18.2/include/asio/impl/write_at.hpp
vendored
Normal file
@@ -0,0 +1,666 @@
|
||||
//
|
||||
// impl/write_at.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_IMPL_WRITE_AT_HPP
|
||||
#define ASIO_IMPL_WRITE_AT_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/associated_allocator.hpp"
|
||||
#include "asio/associated_executor.hpp"
|
||||
#include "asio/buffer.hpp"
|
||||
#include "asio/completion_condition.hpp"
|
||||
#include "asio/detail/array_fwd.hpp"
|
||||
#include "asio/detail/base_from_completion_cond.hpp"
|
||||
#include "asio/detail/bind_handler.hpp"
|
||||
#include "asio/detail/consuming_buffers.hpp"
|
||||
#include "asio/detail/dependent_type.hpp"
|
||||
#include "asio/detail/handler_alloc_helpers.hpp"
|
||||
#include "asio/detail/handler_cont_helpers.hpp"
|
||||
#include "asio/detail/handler_invoke_helpers.hpp"
|
||||
#include "asio/detail/handler_tracking.hpp"
|
||||
#include "asio/detail/handler_type_requirements.hpp"
|
||||
#include "asio/detail/non_const_lvalue.hpp"
|
||||
#include "asio/detail/throw_error.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
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,
|
||||
asio::error_code& ec)
|
||||
{
|
||||
ec = asio::error_code();
|
||||
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, asio::error_code& ec)
|
||||
{
|
||||
return detail::write_at_buffer_sequence(d, offset, buffers,
|
||||
asio::buffer_sequence_begin(buffers),
|
||||
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)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t bytes_transferred = write_at(
|
||||
d, offset, buffers, transfer_all(), ec);
|
||||
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,
|
||||
asio::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)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t bytes_transferred = write_at(d, offset, buffers,
|
||||
ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
|
||||
asio::detail::throw_error(ec, "write_at");
|
||||
return bytes_transferred;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_EXTENSIONS)
|
||||
#if !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
template <typename SyncRandomAccessWriteDevice, typename Allocator,
|
||||
typename CompletionCondition>
|
||||
std::size_t write_at(SyncRandomAccessWriteDevice& d,
|
||||
uint64_t offset, asio::basic_streambuf<Allocator>& b,
|
||||
CompletionCondition completion_condition, asio::error_code& ec)
|
||||
{
|
||||
std::size_t bytes_transferred = write_at(d, offset, b.data(),
|
||||
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, asio::basic_streambuf<Allocator>& b)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t bytes_transferred = write_at(d, offset, b, transfer_all(), ec);
|
||||
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, asio::basic_streambuf<Allocator>& b,
|
||||
asio::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, asio::basic_streambuf<Allocator>& b,
|
||||
CompletionCondition completion_condition)
|
||||
{
|
||||
asio::error_code ec;
|
||||
std::size_t bytes_transferred = write_at(d, offset, b,
|
||||
ASIO_MOVE_CAST(CompletionCondition)(completion_condition), ec);
|
||||
asio::detail::throw_error(ec, "write_at");
|
||||
return bytes_transferred;
|
||||
}
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
#endif // !defined(ASIO_NO_EXTENSIONS)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename AsyncRandomAccessWriteDevice,
|
||||
typename ConstBufferSequence, typename ConstBufferIterator,
|
||||
typename CompletionCondition, typename WriteHandler>
|
||||
class write_at_op
|
||||
: detail::base_from_completion_cond<CompletionCondition>
|
||||
{
|
||||
public:
|
||||
write_at_op(AsyncRandomAccessWriteDevice& device,
|
||||
uint64_t offset, const ConstBufferSequence& buffers,
|
||||
CompletionCondition& completion_condition, WriteHandler& handler)
|
||||
: detail::base_from_completion_cond<
|
||||
CompletionCondition>(completion_condition),
|
||||
device_(device),
|
||||
offset_(offset),
|
||||
buffers_(buffers),
|
||||
start_(0),
|
||||
handler_(ASIO_MOVE_CAST(WriteHandler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ASIO_HAS_MOVE)
|
||||
write_at_op(const write_at_op& other)
|
||||
: detail::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)
|
||||
: detail::base_from_completion_cond<CompletionCondition>(
|
||||
ASIO_MOVE_CAST(detail::base_from_completion_cond<
|
||||
CompletionCondition>)(other)),
|
||||
device_(other.device_),
|
||||
offset_(other.offset_),
|
||||
buffers_(ASIO_MOVE_CAST(buffers_type)(other.buffers_)),
|
||||
start_(other.start_),
|
||||
handler_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()(const asio::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());
|
||||
do
|
||||
{
|
||||
{
|
||||
ASIO_HANDLER_LOCATION((__FILE__, __LINE__, "async_write_at"));
|
||||
device_.async_write_some_at(
|
||||
offset_ + buffers_.total_consumed(), buffers_.prepare(max_size),
|
||||
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());
|
||||
} while (max_size > 0);
|
||||
|
||||
handler_(ec, buffers_.total_consumed());
|
||||
}
|
||||
}
|
||||
|
||||
//private:
|
||||
typedef 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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(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
|
||||
: 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)(
|
||||
asio::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 ASIO_NOEXCEPT
|
||||
{
|
||||
return device_.get_executor();
|
||||
}
|
||||
|
||||
template <typename WriteHandler, typename ConstBufferSequence,
|
||||
typename CompletionCondition>
|
||||
void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
|
||||
uint64_t offset, const ConstBufferSequence& buffers,
|
||||
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.
|
||||
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,
|
||||
asio::buffer_sequence_begin(buffers),
|
||||
completion_cond2.value, handler2.value);
|
||||
}
|
||||
|
||||
private:
|
||||
AsyncRandomAccessWriteDevice& device_;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
#if !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename AsyncRandomAccessWriteDevice,
|
||||
typename ConstBufferSequence, typename ConstBufferIterator,
|
||||
typename CompletionCondition, typename WriteHandler, typename Allocator>
|
||||
struct associated_allocator<
|
||||
detail::write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
|
||||
ConstBufferIterator, CompletionCondition, WriteHandler>,
|
||||
Allocator>
|
||||
{
|
||||
typedef typename associated_allocator<WriteHandler, Allocator>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::write_at_op<AsyncRandomAccessWriteDevice,
|
||||
ConstBufferSequence, ConstBufferIterator,
|
||||
CompletionCondition, WriteHandler>& h,
|
||||
const Allocator& a = Allocator()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<WriteHandler, Allocator>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename AsyncRandomAccessWriteDevice,
|
||||
typename ConstBufferSequence, typename ConstBufferIterator,
|
||||
typename CompletionCondition, typename WriteHandler, typename Executor>
|
||||
struct associated_executor<
|
||||
detail::write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
|
||||
ConstBufferIterator, CompletionCondition, WriteHandler>,
|
||||
Executor>
|
||||
: detail::associated_executor_forwarding_base<WriteHandler, Executor>
|
||||
{
|
||||
typedef typename associated_executor<WriteHandler, Executor>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::write_at_op<AsyncRandomAccessWriteDevice,
|
||||
ConstBufferSequence, ConstBufferIterator,
|
||||
CompletionCondition, WriteHandler>& h,
|
||||
const Executor& ex = Executor()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<WriteHandler, Executor>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename AsyncRandomAccessWriteDevice,
|
||||
typename ConstBufferSequence, typename CompletionCondition,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_at(AsyncRandomAccessWriteDevice& d,
|
||||
uint64_t offset, const ConstBufferSequence& buffers,
|
||||
CompletionCondition completion_condition,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
detail::initiate_async_write_at_buffer_sequence<
|
||||
AsyncRandomAccessWriteDevice>(d),
|
||||
handler, offset, buffers,
|
||||
ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
|
||||
}
|
||||
|
||||
template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_at(AsyncRandomAccessWriteDevice& d,
|
||||
uint64_t offset, const ConstBufferSequence& buffers,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
detail::initiate_async_write_at_buffer_sequence<
|
||||
AsyncRandomAccessWriteDevice>(d),
|
||||
handler, offset, buffers, transfer_all());
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_EXTENSIONS)
|
||||
#if !defined(ASIO_NO_IOSTREAM)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename Allocator, typename WriteHandler>
|
||||
class write_at_streambuf_op
|
||||
{
|
||||
public:
|
||||
write_at_streambuf_op(
|
||||
asio::basic_streambuf<Allocator>& streambuf,
|
||||
WriteHandler& handler)
|
||||
: streambuf_(streambuf),
|
||||
handler_(ASIO_MOVE_CAST(WriteHandler)(handler))
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(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_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
|
||||
{
|
||||
}
|
||||
#endif // defined(ASIO_HAS_MOVE)
|
||||
|
||||
void operator()(const asio::error_code& ec,
|
||||
const std::size_t bytes_transferred)
|
||||
{
|
||||
streambuf_.consume(bytes_transferred);
|
||||
handler_(ec, bytes_transferred);
|
||||
}
|
||||
|
||||
//private:
|
||||
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(ASIO_NO_DEPRECATED)
|
||||
asio_handler_alloc_helpers::allocate(size, this_handler->handler_);
|
||||
return asio_handler_allocate_is_no_longer_used();
|
||||
#else // defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_alloc_helpers::allocate(
|
||||
size, this_handler->handler_);
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_alloc_helpers::deallocate(
|
||||
pointer, size, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_deallocate_is_no_longer_used();
|
||||
#endif // defined(ASIO_NO_DEPRECATED)
|
||||
}
|
||||
|
||||
template <typename Allocator, typename WriteHandler>
|
||||
inline bool asio_handler_is_continuation(
|
||||
write_at_streambuf_op<Allocator, WriteHandler>* this_handler)
|
||||
{
|
||||
return 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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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)
|
||||
{
|
||||
asio_handler_invoke_helpers::invoke(
|
||||
function, this_handler->handler_);
|
||||
#if defined(ASIO_NO_DEPRECATED)
|
||||
return asio_handler_invoke_is_no_longer_used();
|
||||
#endif // defined(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 ASIO_NOEXCEPT
|
||||
{
|
||||
return device_.get_executor();
|
||||
}
|
||||
|
||||
template <typename WriteHandler,
|
||||
typename Allocator, typename CompletionCondition>
|
||||
void operator()(ASIO_MOVE_ARG(WriteHandler) handler,
|
||||
uint64_t offset, basic_streambuf<Allocator>* b,
|
||||
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.
|
||||
ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
|
||||
|
||||
non_const_lvalue<WriteHandler> handler2(handler);
|
||||
async_write_at(device_, offset, b->data(),
|
||||
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 <typename Allocator, typename WriteHandler, typename Allocator1>
|
||||
struct associated_allocator<
|
||||
detail::write_at_streambuf_op<Allocator, WriteHandler>,
|
||||
Allocator1>
|
||||
{
|
||||
typedef typename associated_allocator<WriteHandler, Allocator1>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::write_at_streambuf_op<Allocator, WriteHandler>& h,
|
||||
const Allocator1& a = Allocator1()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_allocator<WriteHandler, Allocator1>::get(h.handler_, a);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Executor, typename WriteHandler, typename Executor1>
|
||||
struct associated_executor<
|
||||
detail::write_at_streambuf_op<Executor, WriteHandler>,
|
||||
Executor1>
|
||||
: detail::associated_executor_forwarding_base<WriteHandler, Executor>
|
||||
{
|
||||
typedef typename associated_executor<WriteHandler, Executor1>::type type;
|
||||
|
||||
static type get(
|
||||
const detail::write_at_streambuf_op<Executor, WriteHandler>& h,
|
||||
const Executor1& ex = Executor1()) ASIO_NOEXCEPT
|
||||
{
|
||||
return associated_executor<WriteHandler, Executor1>::get(h.handler_, ex);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !defined(GENERATING_DOCUMENTATION)
|
||||
|
||||
template <typename AsyncRandomAccessWriteDevice,
|
||||
typename Allocator, typename CompletionCondition,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_at(AsyncRandomAccessWriteDevice& d,
|
||||
uint64_t offset, asio::basic_streambuf<Allocator>& b,
|
||||
CompletionCondition completion_condition,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
detail::initiate_async_write_at_streambuf<
|
||||
AsyncRandomAccessWriteDevice>(d),
|
||||
handler, offset, &b,
|
||||
ASIO_MOVE_CAST(CompletionCondition)(completion_condition));
|
||||
}
|
||||
|
||||
template <typename AsyncRandomAccessWriteDevice, typename Allocator,
|
||||
ASIO_COMPLETION_TOKEN_FOR(void (asio::error_code,
|
||||
std::size_t)) WriteHandler>
|
||||
inline ASIO_INITFN_AUTO_RESULT_TYPE(WriteHandler,
|
||||
void (asio::error_code, std::size_t))
|
||||
async_write_at(AsyncRandomAccessWriteDevice& d,
|
||||
uint64_t offset, asio::basic_streambuf<Allocator>& b,
|
||||
ASIO_MOVE_ARG(WriteHandler) handler)
|
||||
{
|
||||
return async_initiate<WriteHandler,
|
||||
void (asio::error_code, std::size_t)>(
|
||||
detail::initiate_async_write_at_streambuf<
|
||||
AsyncRandomAccessWriteDevice>(d),
|
||||
handler, offset, &b, transfer_all());
|
||||
}
|
||||
|
||||
#endif // !defined(ASIO_NO_IOSTREAM)
|
||||
#endif // !defined(ASIO_NO_EXTENSIONS)
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_IMPL_WRITE_AT_HPP
|
||||
Reference in New Issue
Block a user