jeudi 7 février 2019

When should multithreading be used with asio?

I'm writing a networking library that uses Boost asio and am confused on whether I should use a separate thread to run the io_service or not.

I currently have a class that wraps all asio work. It has one io_service, one socket, etc, and uses async_read and async_write methods to communicate with the remote server. This class exposes read and write methods to allow users to communicate with the remote server.

This class is then called by other classes that use it's read/write methods to send and receive data to the remote server. In some cases there are chained calls to read/write data from the server until a final user-provided callback is called to pass on the final result of the computation.

I'm now trying to implement a connection pool and am wondering if I need a connection pool: all reads and writes to the remote server use async methods, none post-read processing involves blocking calls until the final user-provided callback. Should it not be ok to have a series of connection objects running at the same time without the need for a separate thread pool?

Aucun commentaire:

Enregistrer un commentaire