forked from boostorg/beast
Fix all async initiating functions with use_awaitable:
Add trait:
is_completion_token_for
Fixes for
buffered_read_stream
Add tests for
basic_stream
buffered_read_stream
flat_stream
http (all)
websocket (all)
resolves #1920
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
#ifndef BOOST_BEAST_DETAIL_IS_INVOCABLE_HPP
|
||||
#define BOOST_BEAST_DETAIL_IS_INVOCABLE_HPP
|
||||
|
||||
#include <boost/asio/async_result.hpp>
|
||||
#include <boost/type_traits/make_void.hpp>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
@@ -51,6 +53,26 @@ struct is_invocable<C, R(A...)>
|
||||
};
|
||||
/** @} */
|
||||
|
||||
template<class CompletionToken, class Signature, class = void>
|
||||
struct is_completion_token_for : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
struct any_initiation
|
||||
{
|
||||
template<class...AnyArgs>
|
||||
void operator()(AnyArgs&&...);
|
||||
};
|
||||
|
||||
template<class CompletionToken, class R, class...Args>
|
||||
struct is_completion_token_for<
|
||||
CompletionToken, R(Args...), boost::void_t<decltype(
|
||||
boost::asio::async_initiate<CompletionToken, R(Args...)>(
|
||||
any_initiation(), std::declval<CompletionToken&>())
|
||||
)>> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
} // detail
|
||||
} // beast
|
||||
} // boost
|
||||
|
||||
@@ -110,7 +110,7 @@ struct run_read_op
|
||||
operator()(
|
||||
ReadHandler&& h,
|
||||
buffered_read_stream* s,
|
||||
Buffers const& b)
|
||||
Buffers const* b)
|
||||
{
|
||||
// If you get an error on the following line it means
|
||||
// that your handler does not meet the documented type
|
||||
@@ -124,7 +124,7 @@ struct run_read_op
|
||||
read_op<
|
||||
Buffers,
|
||||
typename std::decay<ReadHandler>::type>(
|
||||
std::forward<ReadHandler>(h), *s, b);
|
||||
std::forward<ReadHandler>(h), *s, *b);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -153,7 +153,7 @@ async_write_some(
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value,
|
||||
"ConstBufferSequence type requirements not met");
|
||||
static_assert(detail::is_invocable<WriteHandler,
|
||||
static_assert(detail::is_completion_token_for<WriteHandler,
|
||||
void(error_code, std::size_t)>::value,
|
||||
"WriteHandler type requirements not met");
|
||||
return next_layer_.async_write_some(buffers,
|
||||
@@ -233,7 +233,7 @@ async_read_some(
|
||||
typename ops::run_read_op{},
|
||||
handler,
|
||||
this,
|
||||
buffers);
|
||||
&buffers);
|
||||
}
|
||||
|
||||
} // beast
|
||||
|
||||
Reference in New Issue
Block a user