Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between epoll and boost::asio::io_context?

I know that epoll and io_context work asynchronously. So, can you tell me what is the difference between the two?

Are you using epoll inside asio::io_context?

like image 893
Hwan E Avatar asked Oct 23 '25 18:10

Hwan E


1 Answers

POSIX gives us a suite of utilities useful for dispatching on events and watching for activity on file descriptors. One of those utilities is epoll().

Boost ASIO also gives us a suite of utilities useful for dispatching on events and watching for activity on file descriptors. io_context is what it sounds like: a "handle" of sorts to a context for some I/O operations. Through an io_context you can poll() for activity (among other things).

They are two different interfaces for (in this comparison) a largely similar task. Boost ASIO, however, is an abstraction. Whether it uses epoll() under the bonnet to implement its magic is not really something we need to or should concern ourselves with, but it's certainly possible that it does so on POSIX systems. On Windows systems it would likely delegate to something else that the OS provides.

One school of thought is that cross-platform abstractions are always helpful, so the Boost ASIO technologies are a good choice for networking. On the other hand, some people find the old POSIX utilities to be simpler and more familiar to other programmers reading their code (as long as their target platforms support them); they also do not require you to ship a dependency. As with anything, it is up to you to decide which is the most appropriate for your use case and audience.

like image 64
Asteroids With Wings Avatar answered Oct 26 '25 07:10

Asteroids With Wings