1

I am studying asynchronous I/O. i knows about select(), poll(), and epoll(). What I'm curious about is asynchronous I/O when using boost::asio. as a result of investigation, io_service is used. Which one of select(), poll(), and epoll?

Hwan E
  • 566
  • 2
  • 13

1 Answers1

1

asio::io_service is outdated.

In newer boost versions it is replaced by asio::io_context.

io_context (formly io_service) main purpose executing ansynchrounous operations for object in the asio library, for ex. socket, acceptor, etc, according documentation:

...Synchronous operations on I/O objects implicitly run the io_context object for an individual operation. The io_context functions run(), run_one(), run_for(), run_until(), poll() or poll_one() must be called for the io_context to perform asynchronous operations on behalf of a C++ program. Notification that an asynchronous operation has completed is delivered by invocation of the associated handler. Handlers are invoked only by a thread that is currently calling any overload of run(), run_one(), run_for(), run_until(), poll() or poll_one() for the io_context....

Bascially, you send the tasks to be executed to the io_context (async_... functions), and io_context is reponsible to execute those tasks ( probably on thread or thread pool) and call the provided callback (=handler).

It normally uses internally some version of task-stealing for efficient task distribution on threads in a thread pool.

StPiere
  • 4,113
  • 15
  • 24
  • Do you use epoll() inside io_context? – Hwan E Sep 06 '20 at 13:53
  • I'm not sure about implementation details, but I would expect it to use the platform available notification system for socket io - for ex. epoll on linux, kqueue on osx and completition ports on win. – StPiere Sep 06 '20 at 14:31