Skip to content

feat: add timed TCP connection establishment - #9

Merged
zuudevs merged 9 commits into
mainfrom
feat/tcp-connection
Sep 14, 2026
Merged

zuudevs merged 9 commits into
mainfrom
feat/tcp-connection

Conversation

@zuudevs

@zuudevs zuudevs commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Summary

Adds the v1 TCP connection-establishment layer on top of the merged resolver and native-socket primitives.

Added

  • src/platform/socket_connect.hpp / .cpp
    • native socket creation helper
    • non-blocking connect setup
    • Windows select() / POSIX poll() wait path
    • SO_ERROR verification after readiness
    • restore blocking mode after a successful connect
    • platform-native diagnostic code capture
  • src/net/tcp_connection.hpp / .cpp
    • move-only internal TcpConnection
    • candidate iteration in resolver order
    • one total connect-timeout budget shared across all endpoint candidates
    • fallback to later candidates after socket-creation/connect failure
    • explicit SocketCreateFailed, ConnectFailed, and ConnectTimeout mapping
    • deterministic RAII close semantics through NativeSocket
  • tests/tcp_connection_test.cpp
    • real IPv4 loopback listener connection
    • candidate fallback
    • zero-timeout behavior
    • empty-candidate behavior
    • explicit close semantics

Build changes

  • compile timed-connect and TCP connection sources into the internal target
  • wire TCP connection tests into the existing GoogleTest target

Timeout semantics

The configured connect timeout is a budget for the complete connection operation, not a fresh timeout for every resolved address. IPv6/IPv4 candidate fallback therefore remains bounded by the caller's requested timeout.

CI / determinism

Connection tests use a local ephemeral loopback listener only. They do not require public internet or external services.

Scope

This PR intentionally does not add request writes, response reads, partial-I/O loops, read/write timeouts, HTTP serialization, or connection reuse policy. Those build on this established connection primitive in follow-up PRs.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f0faafd374

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +156 to +157
if (wait_result < 0) {
return {ConnectStatus::Failed, errno};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retry poll when a signal interrupts the wait

On POSIX, if a signal is delivered while a connection attempt is pending, poll() returns -1 with errno == EINTR; this path reports ConnectFailed and abandons a potentially viable endpoint well before the configured deadline. Retry the wait after recomputing the remaining timeout when the error is EINTR, while preserving other errors as failures.

Useful? React with 👍 / 👎.

@zuudevs
zuudevs merged commit 92a870a into main Sep 14, 2026
9 of 12 checks passed
@zuudevs
zuudevs deleted the feat/tcp-connection branch September 14, 2026 14:46
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