AlgoMaster Logo

epoll, kqueue, and IOCP

Medium Priority28 min readUpdated August 14, 2026

A server with thousands of mostly idle connections should not have to resubmit and rescan thousands of descriptors on every wait. Modern operating systems provide scalable I/O notification facilities that keep registration state in the kernel and return the events or completions the application needs to process.

The major platform families expose different APIs:

  • Linux provides epoll.
  • BSD systems and macOS provide kqueue.
  • Windows provides I/O completion ports, commonly called IOCP.

These names are often grouped together as high-concurrency I/O mechanisms, but they do not all follow the same model. epoll and socket filters in kqueue normally report readiness: an operation can probably make progress without blocking. IOCP normally reports completion: an asynchronous operation submitted earlier has finished.

That distinction affects application state, buffer ownership, cancellation, and worker design. This chapter develops the mental model for all three and builds a portable Python echo server that uses epoll on Linux or kqueue on BSD/macOS without a framework.

Premium Content

Subscribe to unlock full access to this content and more premium articles.