jeudi 7 février 2019

How to implement a connection pool using Boost::Asio?

I'm currently writing a network library that uses Boost::Asio to manage TCP connections.

I managed to make my code work if I have a single thread by manually calling io_context::run whenever there is work to do, ie, my library exposes a setter to the end user, the implementation of the setter is a series of callbacks that implement the business logic and the final line of code (outside of the callbacks) is a method that calls io_context::run and io_context::reset. All work the library does is turn std::vector<char> into model objects that represent the content of the vectors. This takes milliseconds.

I now want to add connection pooling but am confused on how to go about it.

Since I use asynchronous calls, do I need a thread pool? If I'm using async methods why do I need to worry about the server being too slow to respond (which is possible)? I assume io_context::run will block while sending data to the server and once again when processing data received but in both these cases this should be in the millisecond range.

Aucun commentaire:

Enregistrer un commentaire