Skip to content

Day45 - Learning Log

📌 Summary

Implemented a TCP server using:

  • blocking socket
  • poll
  • epoll
  • non-blocking I/O

📌 Key Learnings

1. poll vs epoll

  • poll scans all fds
  • epoll only returns ready fds

2. epoll is NOT non-blocking

  • epoll = event notification
  • non-blocking = fd behavior

3. accept must drain queue

while (accept()):
    handle client

Otherwise connections may be missed.


4. recv() behavior

  • n > 0 → data
  • n == 0 → client closed
  • n < 0 → error

5. EAGAIN is not an error

EAGAIN → no more data now

Used to terminate read loop.


6. send() is not guaranteed to send all

  • partial write possible
  • may return EAGAIN

7. Non-blocking design

  • never block inside event loop
  • always return control to loop

8. TX queue design insight

TX queue is:

buffer + offset

NOT:

FIFO packet queue

9. EPOLLOUT must be controlled

Wrong:

always enable EPOLLOUT
→ busy loop

Correct:

enable only when needed

📌 Observations

  • epoll handles burst connections efficiently
  • connection lifecycle becomes clear with logs
  • testing tools (nc) behavior affects results

📌 Next Improvements

  • TX queue + EPOLLOUT
  • integrate input subsystem (Day44)
  • support protocol parsing