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
- BSD Sockets API in C++
- Building a TCP Echo Server
- Asynchronous IO with epoll and kqueue
- Using Boost Asio for Modern Async IO