diff --git a/include/boost/beast/core/impl/basic_stream.hpp b/include/boost/beast/core/impl/basic_stream.hpp index 0c016d97..9db330ee 100644 --- a/include/boost/beast/core/impl/basic_stream.hpp +++ b/include/boost/beast/core/impl/basic_stream.hpp @@ -184,7 +184,7 @@ struct basic_stream::ops { template -class async_op +class transfer_op : public async_op_base , public boost::asio::coroutine { @@ -273,7 +273,7 @@ class async_op public: template - async_op( + transfer_op( Handler_&& h, basic_stream& s, Buffers const& b) @@ -532,7 +532,7 @@ struct run_read_op detail::is_invocable::value, "ReadHandler type requirements not met"); - async_op< + transfer_op< true, Buffers, typename std::decay::type>( @@ -556,7 +556,7 @@ struct run_write_op detail::is_invocable::value, "WriteHandler type requirements not met"); - async_op< + transfer_op< false, Buffers, typename std::decay::type>( @@ -564,6 +564,77 @@ struct run_write_op } }; +struct run_connect_op +{ + template + 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::value, + "ConnectHandler type requirements not met"); + connect_op::type>( + std::forward(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::value, + "RangeConnectHandler type requirements not met"); + connect_op::type>( + std::forward(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::value, + "IteratorConnectHandler type requirements not met"); + connect_op::type>( + std::forward(h), s, begin, end, cond); + } +}; + }; //------------------------------------------------------------------------------ @@ -696,14 +767,13 @@ async_connect( endpoint_type const& ep, ConnectHandler&& handler) { - BOOST_BEAST_HANDLER_INIT( - ConnectHandler, void(error_code)); - ops::template connect_op< - BOOST_ASIO_HANDLER_TYPE( - ConnectHandler, void(error_code))>( - std::forward(handler), - *this, ep); - return init.result.get(); + return net::async_initiate< + ConnectHandler, + void(error_code)>( + typename ops::run_connect_op{}, + handler, + *this, + ep); } template @@ -718,14 +788,14 @@ async_connect( EndpointSequence const& endpoints, RangeConnectHandler&& handler) { - BOOST_BEAST_HANDLER_INIT(RangeConnectHandler, - void(error_code, typename Protocol::endpoint)); - ops::template connect_op< - BOOST_ASIO_HANDLER_TYPE(RangeConnectHandler, - void(error_code, typename Protocol::endpoint))>( - std::move(init.completion_handler), *this, - endpoints, detail::any_endpoint{}); - return init.result.get(); + return net::async_initiate< + RangeConnectHandler, + void(error_code, typename Protocol::endpoint)>( + typename ops::run_connect_range_op{}, + handler, + *this, + endpoints, + detail::any_endpoint{}); } template @@ -742,14 +812,14 @@ async_connect( ConnectCondition connect_condition, RangeConnectHandler&& handler) { - BOOST_BEAST_HANDLER_INIT(RangeConnectHandler, - void(error_code, typename Protocol::endpoint)); - ops::template connect_op< - BOOST_ASIO_HANDLER_TYPE(RangeConnectHandler, - void(error_code, typename Protocol::endpoint))>( - std::move(init.completion_handler), *this, - endpoints, connect_condition); - return init.result.get(); + return net::async_initiate< + RangeConnectHandler, + void(error_code, typename Protocol::endpoint)>( + typename ops::run_connect_range_op{}, + handler, + *this, + endpoints, + connect_condition); } template @@ -763,14 +833,14 @@ async_connect( Iterator begin, Iterator end, IteratorConnectHandler&& handler) { - BOOST_BEAST_HANDLER_INIT(IteratorConnectHandler, - void(error_code, Iterator)); - ops::template connect_op< - BOOST_ASIO_HANDLER_TYPE(IteratorConnectHandler, - void(error_code, Iterator))>( - std::move(init.completion_handler), *this, - begin, end, detail::any_endpoint{}); - return init.result.get(); + return net::async_initiate< + IteratorConnectHandler, + void(error_code, Iterator)>( + typename ops::run_connect_iter_op{}, + handler, + *this, + begin, end, + detail::any_endpoint{}); } template @@ -786,14 +856,14 @@ async_connect( ConnectCondition connect_condition, IteratorConnectHandler&& handler) { - BOOST_BEAST_HANDLER_INIT(IteratorConnectHandler, - void(error_code, Iterator)); - ops::template connect_op< - BOOST_ASIO_HANDLER_TYPE(IteratorConnectHandler, - void(error_code, Iterator))>( - std::move(init.completion_handler), *this, - begin, end, connect_condition); - return init.result.get(); + return net::async_initiate< + IteratorConnectHandler, + void(error_code, Iterator)>( + typename ops::run_connect_iter_op{}, + handler, + *this, + begin, end, + connect_condition); } //------------------------------------------------------------------------------ @@ -813,7 +883,7 @@ async_read_some( return net::async_initiate< ReadHandler, void(error_code, std::size_t)>( - ops::run_read_op{}, + typename ops::run_read_op{}, handler, *this, buffers); @@ -834,14 +904,12 @@ async_write_some( return net::async_initiate< WriteHandler, void(error_code, std::size_t)>( - ops::run_write_op{}, + typename ops::run_write_op{}, handler, *this, buffers); } -//------------------------------------------------------------------------------ - //------------------------------------------------------------------------------ // // Customization points