Boost logo

Boost Users :

Subject: Re: [Boost-users] "event-driven" async-receive
From: Andreas Wehrmann (a.wehrmann_at_[hidden])
Date: 2014-10-23 05:10:35


On 10/23/2014 10:53 AM, Alexander Carôt wrote:
> Hello all,
>
> I have question regarding the async_receive_from – operation (using UDP):
>
> Right now I have a thread, which triggers the receive call in constant
> intervals. This works allright if the sender sends data in the same interval
> or larger intervals.
Now, why would you do that? It doesn't seem to make any sense to 'poll'
the socket for data...

>
> However, if the send intervals are (much) smaller (or if multiple senders
> exist) the receive-operation is not triggered often enough.
>
> Eventually I’d like the receiving socket to behave in an „event-driven
> “ manner – so, whenever data is there the receive-handler should be invoked.

This is exactly how async_receive works, you call async_receive with a
handler callback
which gets called when either an error occurs or data has been received.
In the handler callback, you do whatever you do with the data and then
call async_receive again to wait for the next packet;
I think this is exactly what you want?

Regards


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