Context
Firstly some context: A Boost.Asio server receives requests formatted as follow:
- X bytes of metadata in XML
- X bytes of optional binary data
We have a XML parser that takes a std::istream so it's really easy to just pass tcp::iostream to this function. The binary data that follows can be heavy, so we should asynchronously read packets of —say 500ko— until we read all the data.
Questions
Can we use the tcp::iostream first and then use an async_read with the underlining socket_streambuf? Of course, it's ok for the compilation, but does the read operation on socket correctly use the internal buffer of the tcp::iostream? (That could be not empty even after having read the metadata). I guess it should respect the Liskov Substitution Principle, but I prefer to be sure.
Can we switch from one method to another, where/whenever we want?