Assume that an async_read_some service has been enabled on a socket in boost::asio, what will happen if a blocking read on the same socket is called?
A piece of pseudo code looks like:
using boost::asio::local::stream_protocol;
boost::asio::io_service io;
stream_protocol::socket s(io);
s.connect(stream_protocol::endpoint(address));
s.async_read_some(aBuffer, aCallback); // start async_read
boost::thread thread(boost::bind(&boost::asio::io_service::run, &io));
usleep(1000000); // do some stuff
boost::asio::read(bBuffer); // request a blocking read
My naive test shows that the blocking read always get priority: data will first fill the bBuffer before the async callback being called. It's a desired behaviour on my side.
Question: It is a guaranteed behaviour? On all socket types?
Boost.Asio does not make this guarantee on any I/O object. When a synchronous operation is initiated on an I/O object that has an outstanding asynchronous operation of the same type, the order in which the underlying system calls occur is unspecified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With