Re: [boost] Should pass boost::asio::io_service by raw pointer or smart pointer?
On Thu, Dec 20, 2018 at 6:45 PM Richard Hodges
...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/8afbc6090bded0cdfda46871d829ea778a... 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/8afbc6090bded0cdfda46871d829ea778a... 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/8afbc6090bded0cdfda46871d829ea778a... 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
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-... 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
On Thu, Dec 20, 2018 at 6:45 PM Richard Hodges
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/8afbc6090bded0cdfda46871d829ea778a...
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/8afbc6090bded0cdfda46871d829ea778a...
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/8afbc6090bded0cdfda46871d829ea778a...
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
On Thu, Dec 20, 2018 at 8:37 PM hh h
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?
It is both wrong, and outdated. Modern asio's executor_work_guard has a member function reset() which releases the work. Probably the shared_ptr in the examples used to manage the guard were written before the reset() member was added. But there are other constructs in that tutorial which are outdated. I would look to the latest Asio examples and documentation for best practices. And if you have specific questions don't hesitate to ask on the list or open an issue in the relevant repository. Regards
Thanks Vinnie, that blog and author were also referenced by a boost
asio book, wandering how much could be quickly outdated by books and
online commentate, this mailing list is the truly one for updated
clarification.
Thank you and very much appreciated.
- JHH
On 12/21/18, Vinnie Falco
On Thu, Dec 20, 2018 at 8:37 PM hh h
wrote: 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?
It is both wrong, and outdated. Modern asio's executor_work_guard has a member function reset() which releases the work. Probably the shared_ptr in the examples used to manage the guard were written before the reset() member was added. But there are other constructs in that tutorial which are outdated.
I would look to the latest Asio examples and documentation for best practices. And if you have specific questions don't hesitate to ask on the list or open an issue in the relevant repository.
Regards
reposting to group as previous message was sent direct.
On Fri, 21 Dec 2018 at 15:32, hh h
Thanks Vinnie, that blog and author were also referenced by a boost asio book, wandering how much could be quickly outdated by books and online commentate, this mailing list is the truly one for updated clarification.
There are three good places that spring to mind: * Here * StackOverflow * CppCon videos (search on youtube). I don't think there's any need to buy a book on anything technical these days. It would be out of date before it were published. *Absolutely ignore all blogs.* They are not subject to anywhere near the same degree of meticulous scrutiny and unforgiving peer review as the StackOverflow c++ channel. If you post a wrong answer there, the people who actually know their stuff will come in for the kill within minutes. This is good for people who are looking to learn, as it means that bad information and worthless opinion is erased before it can do much damage.
Thank you and very much appreciated.
- JHH
On 12/21/18, Vinnie Falco
wrote: On Thu, Dec 20, 2018 at 8:37 PM hh h
wrote: 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?
It is both wrong, and outdated. Modern asio's executor_work_guard has a member function reset() which releases the work. Probably the shared_ptr in the examples used to manage the guard were written before the reset() member was added. But there are other constructs in that tutorial which are outdated.
I would look to the latest Asio examples and documentation for best practices. And if you have specific questions don't hesitate to ask on the list or open an issue in the relevant repository.
Regards
-- Richard Hodges hodges.r@gmail.com office: +442032898513 home: +376841522 mobile: +376380212 (this will be *expensive* outside Andorra!) skype: madmongo facebook: hodges.r
Thanks Richard, great advice.
On 12/21/18, Richard Hodges via Boost
reposting to group as previous message was sent direct.
On Fri, 21 Dec 2018 at 15:32, hh h
wrote: Thanks Vinnie, that blog and author were also referenced by a boost asio book, wandering how much could be quickly outdated by books and online commentate, this mailing list is the truly one for updated clarification.
There are three good places that spring to mind:
* Here * StackOverflow * CppCon videos (search on youtube).
I don't think there's any need to buy a book on anything technical these days. It would be out of date before it were published.
*Absolutely ignore all blogs.*
They are not subject to anywhere near the same degree of meticulous scrutiny and unforgiving peer review as the StackOverflow c++ channel.
If you post a wrong answer there, the people who actually know their stuff will come in for the kill within minutes.
This is good for people who are looking to learn, as it means that bad information and worthless opinion is erased before it can do much damage.
Thank you and very much appreciated.
- JHH
On 12/21/18, Vinnie Falco
wrote: On Thu, Dec 20, 2018 at 8:37 PM hh h
wrote: 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?
It is both wrong, and outdated. Modern asio's executor_work_guard has a member function reset() which releases the work. Probably the shared_ptr in the examples used to manage the guard were written before the reset() member was added. But there are other constructs in that tutorial which are outdated.
I would look to the latest Asio examples and documentation for best practices. And if you have specific questions don't hesitate to ask on the list or open an issue in the relevant repository.
Regards
-- Richard Hodges hodges.r@gmail.com office: +442032898513 home: +376841522 mobile: +376380212 (this will be *expensive* outside Andorra!) skype: madmongo facebook: hodges.r
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Op 21-12-18 om 09:31 schreef hh h via Boost:
by a boost asio book,
There's a whole cottage industry of very questionable quality books on Boost Asio. See my run-ins here - https://twitter.com/sehetw/status/938804901563551744 - https://stackoverflow.com/questions/48076068/crash-terminate-called-after-th... Perhaps your source was this book, or one of the other Packt titles
participants (4)
-
hh h
-
Richard Hodges
-
Seth
-
Vinnie Falco