Wahib Mkadmi
Wahib Mkadmi

Reputation: 644

Understanding asio::async_read behavior

I've inherited code that extensively uses asio::async_* methods to integrate with my main project. In my main project I'm using io_context::post() to have some control over the scheduling and dispatching of the connections.

The application is a client running on an infinite loop with tens of thousands of connections to different hosts.

I'd like to know more about the asio::async_* behavior. I do know that io_context::post() dispatches work items to the system and schedules the callbacks on the thread(s) running io_context::run().

My first thought is to simply pass the io_context around and .post() on that instance, but that doesn't look like a good design choice to me.

AFAIK, I can't cleanly implement back pressure with the asio::async_* methods (pardon my blatant ignorance if I'm mistaken, asio's documentation isn't the most abundant), which is why I'm trying to have the whole application .post() to io_context so I can control and not DoS my machine.

edit: updated the title

Upvotes: 0

Views: 76

Answers (1)

alex_noname
alex_noname

Reputation: 32233

You can find a concise but sufficient to provide an understanding description of sync and async operations on an example of connect and async_connect functions here: Basic Boost.Asio Anatomy

Upvotes: 1

Related Questions