Skip to content

Day48 - Epoll Timerfd Idle Timeout

Summary

Implemented idle timeout handling using timerfd integrated with epoll.


Key Learnings

timerfd

  • fd-based timer mechanism
  • integrates naturally with epoll
  • read() returns expiration count

Timeout Design

  • global timer + per-client timestamp
  • periodic scanning approach
  • simple and effective

Client Management

  • maintain separate client list
  • do not rely on epoll for tracking
  • careful handling when deleting nodes during traversal

Debugging

Added debug logs:

[DEBUG] fd=6 idle=10494 ms
[TIMER] client timeout

Confirmed:

  • timeout behavior is correct
  • activity resets idle timer
  • multi-client case works

Issues Encountered

  • confusion between epoll events and client tracking
  • handling list traversal with deletion
  • understanding timerfd expiration semantics

Outcome

A fully working:

  • epoll-based multi-client TCP server
  • with TX queue
  • and idle timeout management

This resembles a simplified production-grade server design.