If someone could please help me out, I cannot understand how the boost::asio::read function works in boost asio. In boost\'s example they have it declare the buffer size before
Usually, you know how much bytes you want to read from the definition of protocol.
In the opposite case you have to read bytes one by one and observe the error code to stop at the end of connection, file, etc.
Synchronous methods (for example read
) in Boost.Asio are nice for short examples, but in practical use cases you should prefer the asynchronous version async_read, which allows you to cancel or just wait for a next chunk of data without blocking your program.