Discussion:
[asio-users] Can the handler be moved from the async_result_init?
Vinnie Falco
2016-03-24 21:05:01 UTC
Permalink
My websocket stream wrapper interface tries to resemble asio's socket
interfaces as much as possible. I'm adapting my asynchronous initiation
functions to also work with futures by respecting the customization points,
leading to this implementation:

template<class... Args>
using handler_type =
typename boost::asio::handler_type<Args...>::type;

template<class Stream>
template<class Buffers, class Handler>
BOOST_ASIO_INITFN_RESULT_TYPE(Handler,
void(boost::system::error_code))
socket<Stream>::async_write(opcode::value op, bool fin,
Buffers&& bs, Handler&& h)
{
static_assert(beast::is_call_possible<Handler,
void(error_code)>::value,
"Type does not meet the handler requirements");
assert((! wr_cont_ && op != opcode::cont) ||
(wr_cont_ && op == opcode::cont));
wr_cont_ = ! fin;
boost::asio::detail::async_result_init<Handler,
void(boost::system::error_code)> init(
std::forward<Handler>(h));
write_op<std::decay_t<Buffers>, handler_type<Handler,
void(boost::system::error_code)>>{
std::forward<Handler>(init.handler), *this,
op, fin, std::forward<Buffers>(bs)};
return init.result.get();
}

I'm wondering about the call to construct write_op, is it okay to std::move
the init.handler out? Or could a possible implementation of
async_result_init::get need it?

Also, I'm concerned that I have to use detail classes from asio in order to
make user-defined asynchronous initiation functions "first class" (that is,
support the same set of features supported by the initiation functions in
the asio library itself). Is this a legitimate concern and is there a plan
going forward?

Thanks
--
Follow me on Github: https://github.com/vinniefalco
Bjorn Reese
2016-03-27 16:01:34 UTC
Permalink
Post by Vinnie Falco
Also, I'm concerned that I have to use detail classes from asio in order
to make user-defined asynchronous initiation functions "first class"
Without detail functionality:

template <typename CompletionToken>
typename boost::asio::async_result<typename
boost::asio::handler_type<CompletionToken,
void(boost::system::error_code)>::type>::type
async_stuff(BOOST_ASIO_MOVE_ARG(CompletionToken) token)
{
typedef typename boost::asio::handler_type<CompletionToken,
void(boost::system::error_code)>::type handler_type;
handler_type handler(BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
boost::asio::async_result<handler_type> result(handler);

// Your code here

return result.get();
}


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio

Loading...