Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need io_service in boost?

I am trying to learn Boost.asio library. Now I can create a client and server which can communicate.

Why do we need to define an io_service object? Because if that is the only type of object available for the sockets to register/communicate with underlying OS, why do we have to define it anyways. Can't the sockets automatically guess it? What am I missing here?

like image 660
InQusitive Avatar asked Dec 18 '22 13:12

InQusitive


1 Answers

Are you reverse-discovering why singletons are bad? That's your answer.

As it is done, you are in control and get to decide how many resources are shared between services in Asio.

Because of that, you can now

  • use Asio in your application even though one of the libraries you link to also uses it
  • use Asio with a service per thread (so there will be no shared state) or with many threads per service

etc.

like image 52
sehe Avatar answered Dec 24 '22 01:12

sehe