0Pricing
C++ Academy · Lesson

Asynchronous IO with epoll and kqueue

Scale to many connections with epoll on Linux and kqueue on BSD or macOS.

Why Async I/O?

A thread per connection does not scale to thousands or millions of clients. Async I/O lets one thread handle many sockets by waiting for any of them to become readable or writable.

Linux: epoll

Linux s scalable event API. Add file descriptors to an epoll instance; wait for events on any of them.

#include <sys/epoll.h>
int epfd = epoll_create1(0);
epoll_event ev{};
ev.events = EPOLLIN;
ev.data.fd = sock;
epoll_ctl(epfd, EPOLL_CTL_ADD, sock, &ev);

All lessons in this course

  1. BSD Sockets API in C++
  2. Building a TCP Echo Server
  3. Asynchronous IO with epoll and kqueue
  4. Using Boost Asio for Modern Async IO
← Back to C++ Academy