Boost logo

Boost Users :

Subject: [Boost-users] asio UDP async receive question - seems to lose packets?
From: Ákos Maróy (akos_at_[hidden])
Date: 2010-11-15 05:37:19


Hi,

I have a question about boost asio UDP async receive. For me, it seems
to silently not receive packets, even on localhost.

I have a small sample here: http://pastebin.com/NnbK1T7G , which is
based on one of the asio examples. the sample code is quite simple:

- it allows sync sending of messages (strings)
- it allows async reception of such messages
- it will put each received message into a vector, which is guarded by a
mutex
- another thread will process messages from this vector on a regular
basis, which processing is also guarded by a mutex.

if I compile & run the sample, I get:

./async_asio
b sent 20000 messages
a received 1981 messages

which is a profound loss of packets.

as seen in the sample, after the receive handler is called, the recieved
message is copied over, and socket::async_receive_from() is called ASAP.
I don't see what else would need to be done to have all messages received.

If I remove the processing of messages in threa_func(), the results are
markedly better:

./async_asio
b sent 20000 messages
a received 19963 messages

increasing the sleeping time at the end does no good - it seems the
messages were lost already.

I wonder what the proper pattern is to receive messages, store them, and
process them in an async manner?

Akos


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