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. 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. I used to work with Qt, which works this way (via signals/slots) but since I moved to boost I wonder how I can reproduce this behavior. Can anyone tell how to approach this ? Thanks in advance, best Alex
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'
On 10/23/2014 10:53 AM, Alexander Carôt wrote: 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
On 23 Oct 2014 at 10:53, Alexander Carôt wrote:
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.
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.
I used to work with Qt, which works this way (via signals/slots) but since I moved to boost I wonder how I can reproduce this behavior.
Can anyone tell how to approach this ?
Always keep an async_receive() pending at all times and supply a thread pool of executors for asio to issue callbacks onto. You can easily peg a 1Gbit ethernet connection with a low CPU usage with that alone. If you need to max out a 10Gbit or 40Gbit ethernet connection, come back to us. Those have non-trivial design requirements. Niall -- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/
Hi Andreas and Niall, thanks a lot for responding to my question !
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...
Yes, you are right. Obviously I misunderstood the boost async concept and will now implement it as you stated below. In fact this is equal to the Qt principle and this is exactly what I need. In case of further implementation issues I might get back - otherwise all is good :-) Thanks, best Alex
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?
Am 24.10.14 01:07 schrieb "Niall Douglas" unter
On 23 Oct 2014 at 10:53, Alexander Carôt wrote:
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.
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.
I used to work with Qt, which works this way (via signals/slots) but since I moved to boost I wonder how I can reproduce this behavior.
Can anyone tell how to approach this ?
Always keep an async_receive() pending at all times and supply a thread pool of executors for asio to issue callbacks onto. You can easily peg a 1Gbit ethernet connection with a low CPU usage with that alone.
If you need to max out a 10Gbit or 40Gbit ethernet connection, come back to us. Those have non-trivial design requirements.
Niall
-- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Alexander Carôt
-
Andreas Wehrmann
-
Niall Douglas