How async_read_some() in boost::asio::ip::tcp::socket actually works?

No async_read_some() does not request continuously.

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().

Cool. I got it now. – Amumu Nov 1 at 7:16 So, which means read() will hang until all the data has been read from the stream?

– Amumu Nov 1 at 7:30 1 Yes, though the usual term is 'block,' not 'hang'. Read() will block until complete. Async_read_some() will not block, it will return immediately, and then complete asynchronously later.

– James Brock Nov 1 at 14:36.

As the name implies, the member method async_read_some() is asynchronous. The free function read() is not. 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.

It will read from the stream up to the buffer size you indicate, this may or may not be done with multiple read operations. 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?

Not exactly. It means your application can service multiple sockets concurrently without explicit use of threads. The interactions between a server and your application are orthogonal to the use of asynchronous methods here.

Your application should expect a stream of bytes. How the server is implemented does not matter to your application.

Not exactly what I was looking for but thanks anyway. – Amumu Nov 1 at 7:15.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions