I working on a client/server application using boost asio, specifically boost::asio::ip::tcp::socket
to connect and transfer data. Right now I am using boost::asio::async_read
to recive a certain amount of bytes. Until now, in all cases I know how many bytes I want to receive, before calling my handler. Therefore I don't see a reason to use the sockets meber function read_some
. But I wonder why there is no "async_read" member function of boost::asio::ip::tcp::socket
but only the free one.
So my question is: Are there conceptual or technical reasons why there is a read_some
member function but no read
member function, or did "Boost just forgot to implement it" ?
All of the streaming interfaces in Asio provide both read_some
and async_read_some
moethods. This is true for the TCP sockets, SSL streams, and Serial ports. The implementation of read
, read_until
, and their async cousins all have the same implementations, based on using the read_some
method. The read
function is written as a generic template, that can use the read_some
method on its first argument to perform the call as you requested.
There are some C++ advocates that recommend using non-friend non-member functions whenever possible, so as to minimize the changes when a class implementation changes. read_some
is the interface, and read
is just a wrapper that adds blocking in the case of partial reads for a variety of different sources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With