简体   繁体   中英

Is there way to get the number of bytes transfered in Boost asio with coroutines

I am using boost asio with coroutine to get some data from tcp socket. In the exmaples shown in those document, the example looks like

http::async_read(socket, buffer, request, yield[ec]);

But how can I get number of bytes transferred in this case.

Without using coroutine we can bind a callback function.

void onReadDataComplete(boost::system::error_code ec, std::size_t bytes_transferred)

But it is not very clear how can I do the same thing with coroutine.

Read carefully this link .

Your initiating function async_read can be called with handler or yield . Handler signature must be

void handler(boost::system::error_code ec, result_type result);

where result means how many bytes were read. When you call async_read with yield in place of handler , async_read returns result_type ie size_t - which means counter of read bytes. So you need only to check return value from async_read .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM