Skip to content

feat(cpp_server): centralize errno classification + add TCP relay server#3

Open
minjcore wants to merge 1 commit into
mainfrom
feat/os-error-classify-and-relay
Open

feat(cpp_server): centralize errno classification + add TCP relay server#3
minjcore wants to merge 1 commit into
mainfrom
feat/os-error-classify-and-relay

Conversation

@minjcore

Copy link
Copy Markdown
Owner

Summary

Three related pieces of work on base/cpp_server:

  1. os_error.h — single source of truth for errno handling. Maps raw
    errno to an app-level IoOutcome (Retry / WouldBlock / PeerGone /
    FdExhausted / NoBufferSpace / Fatal), plus an io_should_wait() helper
    for the immediate-I/O fast paths.

  2. Wired classify_errno() into all three event-loop backends, replacing the
    scattered errno == EAGAIN || EWOULDBLOCK / == EINTR checks:

    • event_loop_kqueue.cpp (5 sites)
    • event_loop_epoll.cpp (5 sites)
    • event_loop_uring.cpp (4 sites — io_uring uses negated errno, so it
      classifies -ret / -res)

    Behavior is unchanged — pure de-duplication. Mapping is exact:
    EAGAIN/EWOULDBLOCK → WouldBlock, EINTR → Retry, ECONNABORTED → PeerGone.

  3. tcp_replay_server.cpp — standalone TCP relay (machine A → relay →
    machine B) with bidirectional pumping and a --selftest mode that needs no
    external hosts or capture files. Added a make replay target.

  4. MACOS_USERSPACE.md — notes on the macOS/kqueue userspace path:
    syscalls crossed, the kqueue event model, the errno→decision table (now
    implemented in os_error.h), macOS-vs-Linux gotchas, and running on port 443
    against ISP interference.

Test plan

  • macOS: make cpp_server + make testtest_http_parser, test_tcp_ring
    pass, clean under -Wall -Wextra.
  • make replay && ./tcp_replay_server --selftest → A→relay→B→relay→A round-trips
    1 MiB byte-exact, exit 0.
  • git grep confirms no raw errno == EAGAIN/EWOULDBLOCK/EINTR checks remain in
    the event loops.

Notes

event_loop_epoll.cpp and event_loop_uring.cpp are Linux-only and were not
built locally (macOS). The edits are mechanical token replacements through the
shared os_error.h, which is compile-checked. Please confirm a Linux build
(CI or a Linux box) before merge.

🤖 Generated with Claude Code

os_error.h: single source of truth mapping raw errno to app-level IoOutcome
(Retry / WouldBlock / PeerGone / FdExhausted / NoBufferSpace / Fatal), plus an
io_should_wait() helper for the immediate-I/O fast paths.

Wire classify_errno() into all three event-loop backends, replacing the
scattered `errno == EAGAIN || EWOULDBLOCK` / `== EINTR` checks:
- event_loop_kqueue.cpp (5 sites)
- event_loop_epoll.cpp  (5 sites)
- event_loop_uring.cpp  (4 sites; io_uring uses negated errno, classifies -ret/-res)
Behavior is unchanged — pure de-duplication of error handling.

tcp_replay_server.cpp: standalone TCP relay (machine A -> relay -> machine B)
with bidirectional pumping and a --selftest mode that needs no external hosts
or capture files. Added a `make replay` target.

MACOS_USERSPACE.md: notes on the macOS/kqueue userspace path — syscalls, the
kqueue event model, the errno->decision table (now implemented in os_error.h),
macOS-vs-Linux gotchas, and running on port 443 against ISP interference.

Verified on macOS: make cpp_server + make test (test_http_parser, test_tcp_ring)
clean under -Wall -Wextra; make replay + --selftest round-trips 1 MiB OK.
epoll/uring are Linux-only and not built here — changes are mechanical token
replacements through the shared, compile-checked header.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@minjcore minjcore requested a review from caokhang91 June 16, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants