Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost ASIO streambuf

I am confused about the input sequence and output sequence in boost asio::streambuf classes.

According to the code examples (for sending data) in the documentation it seems that the buffer representing the input sequence is used for writting to socket and the one representing the output sequence is used for reading.

Example -

boost::asio::streambuf b;
std::ostream os(&b);
os << "Hello, World!\n";
// try sending some data in input sequence
size_t n = sock.send(b.data());
b.consume(n); // sent data is removed from input sequence

Now, is there a nomenclature problem?

like image 279
Rohit Avatar asked Aug 12 '15 08:08

Rohit


1 Answers

"Everything is relative"

Albert Einstein

The documentation says:

Characters written to the output sequence of a basic_streambuf object are appended to the input sequence of the same object.

From the point of view of the streambuf it will read from its output sequence and write into its input sequence which might seem kind of inverted, but you can think of the streambuf as a pipe for things to make sense.

From the user (anything that uses the streambuf, including sockets) point of view now, you will write into the ouput sequence of the streambuf and read from its input sequence which seems more natural.

So yeah the same way left and right are inverted depending on what you're facing, inputs and outputs are inverted depending from which side you look at it.

"Don't believe every quote you read on the internet, because I totally didn't say that"

Albert Einstein

like image 73
Drax Avatar answered Sep 22 '22 12:09

Drax