Skip to content

feat: add timed TCP read and write I/O - #10

Merged
zuudevs merged 13 commits into
mainfrom
feat/tcp-io
Sep 14, 2026
Merged

zuudevs merged 13 commits into
mainfrom
feat/tcp-io

Conversation

@zuudevs

@zuudevs zuudevs commented Sep 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Completes the byte-oriented v1 TCP transport primitive by adding bounded synchronous reads and complete writes with partial-I/O handling.

Added

  • src/platform/socket_mode.hpp / .cpp
    • reusable cross-platform blocking/non-blocking mode helper
    • shared by connect and I/O paths
  • src/platform/socket_io.hpp / .cpp
    • readable/writable readiness waits
    • Windows select() / POSIX poll()
    • normalized send / recv attempts
    • native interrupted/would-block/connection-closed classification
    • MSG_NOSIGNAL where available
  • TcpConnection::write_all(std::string_view, timeout)
    • loops until the entire byte sequence is sent
    • handles partial sends, EINTR, and would-block
    • one absolute timeout budget for the complete operation
    • returns bytes written on success
  • TcpConnection::read_some(char*, capacity, timeout)
    • incremental byte read suitable for the future HTTP parser
    • handles EINTR, would-block, EOF, and timeout
    • returns bytes read on success
  • macOS/BSD SO_NOSIGPIPE socket setup where MSG_NOSIGNAL is unavailable

Failure semantics

  • peer EOF/reset maps to ConnectionClosed
  • write timeout maps to WriteTimeout
  • read timeout maps to ReadTimeout
  • other send/receive failures map to WriteFailed / ReadFailed
  • after an I/O timeout or unrecoverable I/O failure, the connection is closed conservatively so an incomplete HTTP byte stream cannot be reused accidentally
  • empty writes and zero-capacity reads are successful no-ops

Tests

  • complete 2 MiB loopback payload write with concurrent reader
  • normal incremental read
  • deterministic read timeout
  • peer close detection
  • deterministic zero-deadline write timeout
  • zero-length read/write behavior

Tests use loopback sockets only and require no public network access.

CI cleanup

  • removes the currently unused Google Benchmark vcpkg dependency; benchmarks/CMakeLists.txt is still empty, so CI no longer downloads/builds Benchmark unnecessarily

Scope

This PR completes the low-level synchronous TCP byte stream needed by the HTTP layer. It intentionally does not implement HTTP request serialization, response parsing, chunked decoding, redirects, or connection reuse policy yet.

@zuudevs
zuudevs merged commit 2f09caa into main Sep 14, 2026
6 checks passed
@zuudevs
zuudevs deleted the feat/tcp-io branch September 14, 2026 15:12
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.

1 participant