basic_stream uses async_initiate

This commit is contained in:
Vinnie Falco
2019-02-19 09:51:36 -08:00
parent c5b655c954
commit a5adc328e4

View File

@@ -184,7 +184,7 @@ struct basic_stream<Protocol, Executor, RatePolicy>::ops
{ {
template<bool isRead, class Buffers, class Handler> template<bool isRead, class Buffers, class Handler>
class async_op class transfer_op
: public async_op_base<Handler, Executor> : public async_op_base<Handler, Executor>
, public boost::asio::coroutine , public boost::asio::coroutine
{ {
@@ -273,7 +273,7 @@ class async_op
public: public:
template<class Handler_> template<class Handler_>
async_op( transfer_op(
Handler_&& h, Handler_&& h,
basic_stream& s, basic_stream& s,
Buffers const& b) Buffers const& b)
@@ -532,7 +532,7 @@ struct run_read_op
detail::is_invocable<ReadHandler, detail::is_invocable<ReadHandler,
void(error_code, std::size_t)>::value, void(error_code, std::size_t)>::value,
"ReadHandler type requirements not met"); "ReadHandler type requirements not met");
async_op< transfer_op<
true, true,
Buffers, Buffers,
typename std::decay<ReadHandler>::type>( typename std::decay<ReadHandler>::type>(
@@ -556,7 +556,7 @@ struct run_write_op
detail::is_invocable<WriteHandler, detail::is_invocable<WriteHandler,
void(error_code, std::size_t)>::value, void(error_code, std::size_t)>::value,
"WriteHandler type requirements not met"); "WriteHandler type requirements not met");
async_op< transfer_op<
false, false,
Buffers, Buffers,
typename std::decay<WriteHandler>::type>( typename std::decay<WriteHandler>::type>(
@@ -564,6 +564,77 @@ struct run_write_op
} }
}; };
struct run_connect_op
{
template<class ConnectHandler>
void
operator()(
ConnectHandler&& h,
basic_stream& s,
endpoint_type const& ep)
{
// If you get an error on the following line it means
// that your handler does not meet the documented type
// requirements for a ConnectHandler.
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);
}
};
struct run_connect_range_op
{
template<
class RangeConnectHandler,
class EndpointSequence,
class Condition>
void
operator()(
RangeConnectHandler&& h,
basic_stream& s,
EndpointSequence const& eps,
Condition const& cond)
{
// If you get an error on the following line it means
// that your handler does not meet the documented type
// requirements for a RangeConnectHandler.
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);
}
};
struct run_connect_iter_op
{
template<
class IteratorConnectHandler,
class Iterator,
class Condition>
void
operator()(
IteratorConnectHandler&& h,
basic_stream& s,
Iterator begin, Iterator end,
Condition const& cond)
{
// If you get an error on the following line it means
// that your handler does not meet the documented type
// requirements for a IteratorConnectHandler.
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);
}
};
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -696,14 +767,13 @@ async_connect(
endpoint_type const& ep, endpoint_type const& ep,
ConnectHandler&& handler) ConnectHandler&& handler)
{ {
BOOST_BEAST_HANDLER_INIT( return net::async_initiate<
ConnectHandler, void(error_code)); ConnectHandler,
ops::template connect_op< void(error_code)>(
BOOST_ASIO_HANDLER_TYPE( typename ops::run_connect_op{},
ConnectHandler, void(error_code))>( handler,
std::forward<ConnectHandler>(handler), *this,
*this, ep); ep);
return init.result.get();
} }
template<class Protocol, class Executor, class RatePolicy> template<class Protocol, class Executor, class RatePolicy>
@@ -718,14 +788,14 @@ async_connect(
EndpointSequence const& endpoints, EndpointSequence const& endpoints,
RangeConnectHandler&& handler) RangeConnectHandler&& handler)
{ {
BOOST_BEAST_HANDLER_INIT(RangeConnectHandler, return net::async_initiate<
void(error_code, typename Protocol::endpoint)); RangeConnectHandler,
ops::template connect_op< void(error_code, typename Protocol::endpoint)>(
BOOST_ASIO_HANDLER_TYPE(RangeConnectHandler, typename ops::run_connect_range_op{},
void(error_code, typename Protocol::endpoint))>( handler,
std::move(init.completion_handler), *this, *this,
endpoints, detail::any_endpoint{}); endpoints,
return init.result.get(); detail::any_endpoint{});
} }
template<class Protocol, class Executor, class RatePolicy> template<class Protocol, class Executor, class RatePolicy>
@@ -742,14 +812,14 @@ async_connect(
ConnectCondition connect_condition, ConnectCondition connect_condition,
RangeConnectHandler&& handler) RangeConnectHandler&& handler)
{ {
BOOST_BEAST_HANDLER_INIT(RangeConnectHandler, return net::async_initiate<
void(error_code, typename Protocol::endpoint)); RangeConnectHandler,
ops::template connect_op< void(error_code, typename Protocol::endpoint)>(
BOOST_ASIO_HANDLER_TYPE(RangeConnectHandler, typename ops::run_connect_range_op{},
void(error_code, typename Protocol::endpoint))>( handler,
std::move(init.completion_handler), *this, *this,
endpoints, connect_condition); endpoints,
return init.result.get(); connect_condition);
} }
template<class Protocol, class Executor, class RatePolicy> template<class Protocol, class Executor, class RatePolicy>
@@ -763,14 +833,14 @@ async_connect(
Iterator begin, Iterator end, Iterator begin, Iterator end,
IteratorConnectHandler&& handler) IteratorConnectHandler&& handler)
{ {
BOOST_BEAST_HANDLER_INIT(IteratorConnectHandler, return net::async_initiate<
void(error_code, Iterator)); IteratorConnectHandler,
ops::template connect_op< void(error_code, Iterator)>(
BOOST_ASIO_HANDLER_TYPE(IteratorConnectHandler, typename ops::run_connect_iter_op{},
void(error_code, Iterator))>( handler,
std::move(init.completion_handler), *this, *this,
begin, end, detail::any_endpoint{}); begin, end,
return init.result.get(); detail::any_endpoint{});
} }
template<class Protocol, class Executor, class RatePolicy> template<class Protocol, class Executor, class RatePolicy>
@@ -786,14 +856,14 @@ async_connect(
ConnectCondition connect_condition, ConnectCondition connect_condition,
IteratorConnectHandler&& handler) IteratorConnectHandler&& handler)
{ {
BOOST_BEAST_HANDLER_INIT(IteratorConnectHandler, return net::async_initiate<
void(error_code, Iterator)); IteratorConnectHandler,
ops::template connect_op< void(error_code, Iterator)>(
BOOST_ASIO_HANDLER_TYPE(IteratorConnectHandler, typename ops::run_connect_iter_op{},
void(error_code, Iterator))>( handler,
std::move(init.completion_handler), *this, *this,
begin, end, connect_condition); begin, end,
return init.result.get(); connect_condition);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -813,7 +883,7 @@ async_read_some(
return net::async_initiate< return net::async_initiate<
ReadHandler, ReadHandler,
void(error_code, std::size_t)>( void(error_code, std::size_t)>(
ops::run_read_op{}, typename ops::run_read_op{},
handler, handler,
*this, *this,
buffers); buffers);
@@ -834,14 +904,12 @@ async_write_some(
return net::async_initiate< return net::async_initiate<
WriteHandler, WriteHandler,
void(error_code, std::size_t)>( void(error_code, std::size_t)>(
ops::run_write_op{}, typename ops::run_write_op{},
handler, handler,
*this, *this,
buffers); buffers);
} }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
// Customization points // Customization points