Boost logo

Boost Users :

From: Stephan Menzel (stephan.menzel_at_[hidden])
Date: 2019-09-03 14:21:54


Hello all,

my experiments with custom composed operations in asio have led me to
another question regarding the use of such methods.
What do I do in order to have multiple handlers in flight, e.g. for a timer?

My example is here:
https://github.com/MrMoose/moose_tools/blob/master/TimedConnect.hpp

I'm trying to realize an old dream in asio. A function that will take a
socket and asynchronously do a resolve and connect to the result while
having a timeout around the operation.

Here in the test cases (lower part) is how I imagine usage:
https://github.com/MrMoose/moose_tools/blob/master/test/TestAsioHelpers.cpp#L190

This works (the unit test does...) but I think it's no good and illustrate
the problem. In the coroutine impl I can safely jump in and out and resume
the code represented by the coroutine object as was explained to me
yesterday. But what can I do with the timer? I cannot std::move(self) into
it because it gets moved again moments later and I cannot yield on the
timer wait operation. I want the timer handler and the async ops handlers
both be in flight and have called whichever completes first.

I tried coroutine fork thinking it might be the right tool but that seems
to clash with the move-self-ahead pattern which is used here.

If I don't yield and set the timer to a fixed lambda (as in the example
above) it seems to work but I guess that's not how it's supposed to be,
right?

Any hints as to how I can make this better?

Cheers,
Stephan



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net