Boost logo

Boost :

Subject: Re: [boost] Should pass boost::asio::io_service by raw pointer or smart pointer?
From: hh h (jupiter.hce_at_[hidden])
Date: 2018-12-21 04:37:03


Hi Richard,

I've just read a blog "A guide to getting started with boost::asio" by
Drew_Benton at https://www.gamedev.net/blogs/entry/2249317-a-guide-to-getting-started-with-boostasio/?pg=2

It looks like a very good tutorial, but it used all shared pointer for
io_services, deadline_timer, socket, io_service::strand,
io_service::work and applications which contradicted to your comments,
was it wrong or outdated or did I misinterpreted your following point?

> * Many people keep shared_ptr's to sockets, deadline_timers and so on. This
> is an error. All ASIO io objects are moveable. Store by value.

Thank you.

On 12/21/18, Vinnie Falco via Boost <boost_at_[hidden]> wrote:
> On Thu, Dec 20, 2018 at 6:45 PM Richard Hodges <hodges.r_at_[hidden]> wrote:
>> ...even with Vinnie's easy to follow guide, it requires a hundred lines
>> of
>> boilerplate to implement what amounts to one async method.
>
> Yes, that is kind of irritating. I've been working on some tools to
> make it easier.
>
> The function wrap_handler returns a new completion handler which wraps
> your function object (lambda) and inherits the allocator and executor
> of another completion handler:
>
> <https://github.com/vinniefalco/beast/blob/8afbc6090bded0cdfda46871d829ea778aa80ced/include/boost/beast/_experimental/core/detail/wrap_handler.hpp#L88>
>
> The class template base_handler<> is meant as a base class for
> composed operations, it holds the handler for you and it provides all
> the hooks. I notice that you didn't include an overload for
> asio_handler_invoke in your example, which will certainly cause
> undefined behavior in some cases:
>
> <https://github.com/vinniefalco/beast/blob/8afbc6090bded0cdfda46871d829ea778aa80ced/include/boost/beast/_experimental/core/detail/handler_base.hpp#L27>
>
> You can see both wrap_handler and handler_base used together to
> implement a composed operation, a flavor of async_read_some which has
> a built-in timeout:
>
> <https://github.com/vinniefalco/beast/blob/8afbc6090bded0cdfda46871d829ea778aa80ced/include/boost/beast/_experimental/core/impl/basic_timed_stream.hpp#L42>
>
> In particular, handler_base let me leave out all of the boilerplate
> which is nice. It is possible that with some adaptation these
> utilities can be used to achieve the result you desire.
>
> These experimental features will appear in Boost.Beast version 1.70.0.
>
> Regards
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk