Sign in to follow this  
Jethro_T

Boost ASIO Receive Handler

Recommended Posts

I'm using boost::asio::ip::udp::socket::async_receive_from(). Does anyone know if this function guarantees that it's handler function will be called in this order? My code is single threaded so only 1 handler executes at once.

Data written to receiving buffer
Handler executed
Data written to receiving buffer
Handler executed
Data written to receiving buffer
Handler executed
...

I checked the documentation and it doesn't seem to say. Hopefully someone knows, I'm having a very strange issue with my Server's receiving functionality and I'm thinking it might be because I'm expecting things to behave like above.

Share this post


Link to post
Share on other sites
A UDP socket handler will be called exactly once per incoming datagram.

If you use a single thread, I don't believe that the callbacks will be re-ordered compared to the order they arrive on the socket -- but that doesn't really matter, because the UDP datagrams may be re-ordered externally by the network.

If you queue more than one async receive operation, though, they each need to use a different area of buffer data -- you can't re-use the same buffer area for two, simultaneously outstanding, async requests.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this