Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost asio receive() vs read()

There are two types of reading-from-stream functions for boost::asio::ip::tcp::socket. I am assuming they their semantics vary. Could someone please outline them, the documentation I have looked through does not clarrify this.

like image 725
Hassan Syed Avatar asked Jul 18 '11 13:07

Hassan Syed


1 Answers

As it says in the documentation:

The receive() operation may not receive all of the requested number of bytes. Consider using the read() function if you need to ensure that the requested amount of data is read before the blocking operation completes.

If you actually meant read_some(), then there is no difference. receive() is the socket-specific function, whereas read_some() is the generic function available for all asio streams. (much like std::string's length() and size())

like image 91
Cory Nelson Avatar answered Oct 14 '22 02:10

Cory Nelson