Use async_initiate

This commit is contained in:
Vinnie Falco committed 2019-02-21 06:39:35 -08:00
1 parent e2d3f741b8
commit d08cc82e15
26 files changed
+1216 -590

No files matched your search

+16 -7
View File
@@ -539,16 +539,17 @@ struct run_read_op
operator()(
ReadHandler&& h,
basic_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
// requirements for a ReadHandler.
// requirements for the handler.
static_assert(
detail::is_invocable<ReadHandler,
void(error_code, std::size_t)>::value,
"ReadHandler type requirements not met");
transfer_op<
true,
Buffers,
@@ -568,11 +569,13 @@ struct run_write_op
{
// If you get an error on the following line it means
// that your handler does not meet the documented type
// requirements for a WriteHandler.
// requirements for the handler.
static_assert(
detail::is_invocable<WriteHandler,
void(error_code, std::size_t)>::value,
"WriteHandler type requirements not met");
transfer_op<
false,
Buffers,
@@ -592,11 +595,13 @@ struct run_connect_op
{
// If you get an error on the following line it means
// that your handler does not meet the documented type
// requirements for a ConnectHandler.
// requirements for the handler.
static_assert(
detail::is_invocable<ConnectHandler,
void(error_code)>::value,
"ConnectHandler type requirements not met");
connect_op<typename std::decay<ConnectHandler>::type>(
std::forward<ConnectHandler>(h), s, ep);
}
@@ -617,11 +622,13 @@ struct run_connect_range_op
{
// If you get an error on the following line it means
// that your handler does not meet the documented type
// requirements for a RangeConnectHandler.
// requirements for the handler.
static_assert(
detail::is_invocable<RangeConnectHandler,
void(error_code, typename Protocol::endpoint)>::value,
"RangeConnectHandler type requirements not met");
connect_op<typename std::decay<RangeConnectHandler>::type>(
std::forward<RangeConnectHandler>(h), s, eps, cond);
}
@@ -642,11 +649,13 @@ struct run_connect_iter_op
{
// If you get an error on the following line it means
// that your handler does not meet the documented type
// requirements for a IteratorConnectHandler.
// requirements for the handler.
static_assert(
detail::is_invocable<IteratorConnectHandler,
void(error_code, Iterator)>::value,
"IteratorConnectHandler type requirements not met");
connect_op<typename std::decay<IteratorConnectHandler>::type>(
std::forward<IteratorConnectHandler>(h), s, begin, end, cond);
}
@@ -22,23 +22,26 @@
namespace boost {
namespace beast {
template<class Stream, class DynamicBuffer>
struct buffered_read_stream<Stream, DynamicBuffer>::ops
{
template<class MutableBufferSequence, class Handler>
class buffered_read_stream<
Stream, DynamicBuffer>::read_some_op
: public async_op_base<
Handler, beast::executor_type<buffered_read_stream>>
class read_op
: public async_op_base<Handler,
beast::executor_type<buffered_read_stream>>
{
buffered_read_stream& s_;
MutableBufferSequence b_;
int step_ = 0;
public:
read_some_op(read_some_op&&) = default;
read_some_op(read_some_op const&) = delete;
read_op(read_op&&) = default;
read_op(read_op const&) = delete;
template<class Handler_>
read_some_op(
read_op(
Handler_&& h,
buffered_read_stream& s,
MutableBufferSequence const& b)
@@ -56,6 +59,7 @@ public:
error_code ec,
std::size_t bytes_transferred)
{
// VFALCO TODO Rewrite this using reenter/yield
switch(step_)
{
case 0:
@@ -99,6 +103,35 @@ public:
}
};
struct run_read_op
{
template<class ReadHandler, class Buffers>
void
operator()(
ReadHandler&& h,
buffered_read_stream& s,
Buffers const& b)
{
// If you get an error on the following line it means
// that your handler does not meet the documented type
// requirements for the handler.
static_assert(
beast::detail::is_invocable<ReadHandler,
void(error_code, std::size_t)>::value,
"ReadHandler type requirements not met");
read_op<
Buffers,
typename std::decay<ReadHandler>::type>(
std::forward<ReadHandler>(h),
s,
b);
}
};
};
//------------------------------------------------------------------------------
template<class Stream, class DynamicBuffer>
@@ -198,12 +231,13 @@ async_read_some(
if(buffer_.size() == 0 && capacity_ == 0)
return next_layer_.async_read_some(buffers,
std::forward<ReadHandler>(handler));
BOOST_BEAST_HANDLER_INIT(
ReadHandler, void(error_code, std::size_t));
read_some_op<MutableBufferSequence, BOOST_ASIO_HANDLER_TYPE(
ReadHandler, void(error_code, std::size_t))>(
std::move(init.completion_handler), *this, buffers);
return init.result.get();
return net::async_initiate<
ReadHandler,
void(error_code, std::size_t)>(
typename ops::run_read_op{},
handler,
*this,
buffers);
}
} // beast
+41 -9
View File
@@ -23,8 +23,11 @@ namespace boost {
namespace beast {
template<class NextLayer>
struct flat_stream<NextLayer>::ops
{
template<class Handler>
class flat_stream<NextLayer>::write_op
class write_op
: public async_op_base<Handler,
beast::executor_type<flat_stream>>
, public net::coroutine
@@ -34,9 +37,9 @@ public:
class ConstBufferSequence,
class Handler_>
write_op(
Handler_&& h,
flat_stream<NextLayer>& s,
ConstBufferSequence const& b,
Handler_&& h)
ConstBufferSequence const& b)
: async_op_base<Handler,
beast::executor_type<flat_stream>>(
std::forward<Handler_>(h),
@@ -72,6 +75,34 @@ public:
}
};
struct run_write_op
{
template<class WriteHandler, class Buffers>
void
operator()(
WriteHandler&& h,
flat_stream& s,
Buffers const& b)
{
// If you get an error on the following line it means
// that your handler does not meet the documented type
// requirements for the handler.
static_assert(
beast::detail::is_invocable<WriteHandler,
void(error_code, std::size_t)>::value,
"WriteHandler type requirements not met");
write_op<
typename std::decay<WriteHandler>::type>(
std::forward<WriteHandler>(h),
s,
b);
}
};
};
//------------------------------------------------------------------------------
template<class NextLayer>
@@ -212,12 +243,13 @@ async_write_some(
static_assert(net::is_const_buffer_sequence<
ConstBufferSequence>::value,
"ConstBufferSequence type requirements not met");
BOOST_BEAST_HANDLER_INIT(
WriteHandler, void(error_code, std::size_t));
write_op<BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void(error_code, std::size_t))>(
*this, buffers, std::move(init.completion_handler));
return init.result.get();
return net::async_initiate<
WriteHandler,
void(error_code, std::size_t)>(
typename ops::run_write_op{},
handler,
*this,
buffers);
}
template<class NextLayer>