Networking in C · advanced · ~12 min
Handle multiple sockets in one thread.
select(int nfds, fd_set *r, fd_set *w, fd_set *e, struct timeval *to) waits for any of several fds to become readable/writable, with an optional timeout. poll is the modern, cleaner variant with an array of struct pollfd.
These let a single thread serve many connections without fork per client. The next step up is epoll (Linux) / kqueue (BSD/macOS) — better for thousands of fds.