Boost: is it possible to use multiple recursion in asynchronous calls?

I am new to asio infrastructure, so please be kind. I researched several examples of boost asio and found that people use asynchronous calling as follows:

void read() { async_read(socket_, boost::asio::buffer(&user_[0], user_.size()), boost::bind(&Connection::handle_user_read, this, placeholders::error, placeholders::bytes_transferred)); } void handle_user_read(...) { ... read(); ... } 

I think this code is unsafe because it uses multiple recursion. Therefore, it cannot be used when many read operations are performed due to calls. I am not 100% sure of this and cannot find similar thoughts in other people.

Can someone explain this in detail?

+5
source share
2 answers

I believe that the read () function simply adds a new request to read the asynchronous request into the I / O queue and exits immediately, so there is no recursion in this code.

I mean that read () does not call Connection :: handle_user_read directly. It simply stores a pointer to functions inside the I / O queue. This function will be called asynchronously by external code when a new piece of data is available.

+4
source

This is not recursion; it has chained asynchronous operations; be aware of threading issues:

Why do I need a string for each connection when using boost :: asio?

0
source

Source: https://habr.com/ru/post/1236216/


All Articles