Day49 - signalfd + epoll¶
Summary¶
Integrated signalfd into epoll-based server for graceful shutdown.
Key Learnings¶
signal → fd¶
Signals can be treated as file descriptor events using signalfd.
Unified Event Model¶
All event sources are handled by epoll:
- socket
- timerfd
- signalfd
Blocking signals¶
sigprocmask is required to prevent default handling.
read() is mandatory¶
Without reading signalfd, epoll will continuously trigger.
Graceful shutdown¶
Instead of abrupt termination, the server exits cleanly:
- event loop stops
- resources released in order
Challenges¶
- understanding sigset_t and signal mask
- distinguishing fd vs ptr in epoll_event union
- ensuring correct cleanup order
Outcome¶
A complete event-driven server supporting:
- multi-client TCP
- timer-based timeout
- signal-driven shutdown