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 readmember function, or did “Boost just forgot to implement it” ?
All of the streaming interfaces in Asio provide both
read_someandasync_read_somemoethods. This is true for the TCP sockets, SSL streams, and Serial ports. The implementation ofread,read_until, and their async cousins all have the same implementations, based on using theread_somemethod. Thereadfunction is written as a generic template, that can use theread_somemethod 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_someis the interface, andreadis just a wrapper that adds blocking in the case of partial reads for a variety of different sources.