I can't seem to find a good explanation of what consume() and commit() really means, actually I don't understand streambuf at all.
My understanding is that a streambuf is just a character array. But why is that in the documentation,
basic_streambuf::data
Get a list of buffers that represents the input sequence.
so actually there are many buffers? And what is the 'input sequence' and the 'output sequence'? Are these another two buffers?
What does the following code really 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 buffer for the read() to put data? Then when is the data transferred from that buffer to the underlying streambuf buffer? I thought it was the commit(), but
basic_streambuf::commit
Move characters from the output sequence to the input sequence.
so it seems that commit actually moves the data from the 'output sequence' to 'input sequence' without ever mentioning the underlying buffer used to store data!