Using fixed length I/O buffers
Fixed length I/O buffers are usually used with I/O operations and play the role of either a data source or destination when the size of the message to be sent or received is known. For example, this can be a constant array of chars allocated on a stack, which contain a string that represents the request to be sent to the server. Or, this can be a writable buffer allocated in the free memory, which is used as a data destination point, when reading data from a socket.
In this recipe, we'll see how to represent fixed length buffers so that they can be used with Boost.Asio I/O operations.
How to do it…
In Boost.Asio, a fixed length buffer is represented by one of the two classes: asio::mutable_buffer
or asio::const_buffer
. Both these classes represent a contiguous block of memory that is specified by the address of the first byte of the block and its size in bytes. As the names of these classes suggest, asio::mutable_buffer
represents a writable buffer, whereas asio...