feat(cpp_server): centralize errno classification + add TCP relay server#3
Open
minjcore wants to merge 1 commit into
Open
feat(cpp_server): centralize errno classification + add TCP relay server#3minjcore wants to merge 1 commit into
minjcore wants to merge 1 commit into
Conversation
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>
caokhang91
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three related pieces of work on
base/cpp_server:os_error.h— single source of truth for errno handling. Maps rawerrnoto an app-levelIoOutcome(Retry/WouldBlock/PeerGone/FdExhausted/NoBufferSpace/Fatal), plus anio_should_wait()helperfor the immediate-I/O fast paths.
Wired
classify_errno()into all three event-loop backends, replacing thescattered
errno == EAGAIN || EWOULDBLOCK/== EINTRchecks:event_loop_kqueue.cpp(5 sites)event_loop_epoll.cpp(5 sites)event_loop_uring.cpp(4 sites — io_uring uses negated errno, so itclassifies
-ret/-res)Behavior is unchanged — pure de-duplication. Mapping is exact:
EAGAIN/EWOULDBLOCK → WouldBlock,EINTR → Retry,ECONNABORTED → PeerGone.tcp_replay_server.cpp— standalone TCP relay (machine A → relay →machine B) with bidirectional pumping and a
--selftestmode that needs noexternal hosts or capture files. Added a
make replaytarget.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 443against ISP interference.
Test plan
make cpp_server+make test→test_http_parser,test_tcp_ringpass, clean under
-Wall -Wextra.make replay && ./tcp_replay_server --selftest→ A→relay→B→relay→A round-trips1 MiB byte-exact, exit 0.
git grepconfirms no rawerrno == EAGAIN/EWOULDBLOCK/EINTRchecks remain inthe event loops.
Notes
event_loop_epoll.cppandevent_loop_uring.cppare Linux-only and were notbuilt 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