Reputation: 3
I'm sending some data over the network and each data piece has a header consisting of two things:
I'm reading the data type into one variable, and the length into another, thus the two async_read calls.
I know I can chain the async_reads and everything should work fine, i.e. first read the message type, and when it's read, in its async_read handler, call async_read for the data length.
But what if I don't do such chaining and just do async_read( data type ); async_read( data length );. Will Boost process the second async_read() only after the first has completed?
async_reads are called on the same tcp socket and on the same io_service object.
Upvotes: 0
Views: 51
Reputation: 18359
No, this is not a safe assumption. async_read()
is implemented as multiple calls to async_read_some()
, so the reads can end up being interleaved.
Upvotes: 2