What is the difference between:
boost::asio::tcp::socket::async_read_some()
boost::asio::tcp::socket::async_receive()
As far as I can tell their documentation is identical.
Which should I prefer?
I believe the two are essentially identical. The reason they provide both is to provide interfaces similar to both iostreams (which have a read_some
member) and sockets (which have a receive
).
As Peter Tseng pointed out, async_receive
does also have an overload that accepts socket_base::message_flags
, which async_read_some
does not.
Their specification in the networking TR2 proposal (5.7.10.2 basic_stream_socket members) is identical too:
On async_receive:
Effects: Calls this->service.async_receive(this->implementation, buffers, 0, handler).
On async_read_some:
Effects: Calls this->service.async_receive(this->implementation, buffers, 0, handler).
So I guess this confirms Jerry's impression.
Confirming everyone here with two links:
The code is exactly the same. However async_receive
has one overload with message_flags, which notably allows you to specify asio::socket_base::message_peek
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.