Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost::Asio read/write operations

Tags:

c++

boost-asio

What is the difference between calling boost::asio::ip::tcp::socket's read_some/write_some member functions and calling the boost::asio::read/boost::asio::write free functions?

More specifically:

Is there any benefit to using one over the other?

Why are both included in the library?

like image 886
plastic chris Avatar asked Aug 04 '09 15:08

plastic chris


1 Answers

read_some and write_some may return as soon as even a single byte has been transferred. As such you need to loop if you want to make sure you get all of the data - but this may be what you want.

The free functions are wrappers around read_some and write_some, and have different termination conditions depending on the overload. Typically they wait for the buffer to be fully transferred (or an error to occur, or in some overloads an explicit completion condition to occur)

like image 111
bdonlan Avatar answered Sep 23 '22 05:09

bdonlan