I cannot find a good explanation of what consumes () and commit () really means, in fact, I donβt understand streambuf at all.
I understand that streambuf is just an array of characters. But why is this in the documentation,
basic_streambuf::data Get a list of buffers that represents the input sequence.
so there really are many buffers? And what is an "input sequence" and an "output sequence"? Are these two more buffers?
What does the following code do?
streambuf b; size_t size; size = read( socket, b.prepare( 1024 ) ); b.commit( size ); size = write( socket, b.data() ); b.consume( size );
when i call b.prepare () does it allocate a new read buffer () to hold the data? Then, when data is transferred from this buffer to the streambuf base buffer? I thought it was commit (), but
basic_streambuf::commit Move characters from the output sequence to the input sequence.
therefore, it seems that commit actually moves data from the "output sequence" to the "input sequence" without mentioning the underlying buffer used to store the data!
source share