It is written in the documentation:
This function is used to asynchronously read data from the stream socket. The function call always returns immediately.
I know it is asynchronous, so it returns immediately. But what does async_read_some()
differ from free function read()? When I try to std::cout
my buffer used for async_read_some()
, it seems that the function reads many times until the stream is out of data.
Does this mean async_read_some()
request continuously until it receives every data, for example, in a HTTP GET request? And the server will write little at a time and send a little to the client (for async_read_some()
to read a little bit of whole data), or it dumps all data to the client at once?
No, async_read_some()
does not request continuously.
The ip::tcp::socket::async_read_some()
function will make a system call that starts the read.
After that, the next time you call io_service::run()
on the io_service
that you passed to the constructor of the ip::tcp::socket
, the io_service
will check to see if the async_read_some()
has read any data.
If data has been read, then it will call the ReadHandler
callback that you passed to async_read_some()
.
If data has not yet been read, it will return and check for completion again the next time you call io_service::run()
.
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