Skip to content

Add TCP networking and DNS to the standard library - #337

Open
pouya-eghbali wants to merge 4 commits into
developfrom
codex/stdlib-tcp
Open

pouya-eghbali wants to merge 4 commits into
developfrom
codex/stdlib-tcp

Conversation

@pouya-eghbali

@pouya-eghbali pouya-eghbali commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

What you can do

Use std/net to connect by hostname, IPv4 or IPv6, bind a listener on an ephemeral port, accept connections, and stream bytes through the existing std/stream and ByteBuffer APIs. TCP preserves byte order and supports half-close. A program can finish sending and keep reading its peer’s response.

split consumes the original connection. Its owner offers takeReader and takeWriter so each half can move to a different task and close independently. Connection deadlines cover DNS and all address attempts. Listeners and byte streams accept per-operation timeouts. Pending network I/O yields the scheduler worker and observes task cancellation.

Runtime and qualification

  • The runtime uses nonblocking sockets and the existing bounded external I/O service. Up to four system resolver calls run concurrently. Each request retains at most 64 IPv4/IPv6 candidates. An operating-system lookup can finish after its caller is cancelled.
  • Independent peers verify full-duplex byte-for-byte transfers with one and four scheduler workers, IPv4/IPv6 listeners, half-close, timeout, backpressure, resets and cancellation. Runtime ownership tests verify that reserved service slots return to baseline.
  • macOS ARM64 passed all ten targeted runtime, filesystem, stream, process and TCP checks, including TCP at -O0, -O2, ASan/UBSan and TSan. The CPU documentation verifier ran 125 programs, including the new networking example. Local development used LLVM 23.1.6. Hosted qualification uses the repository’s pinned toolchain.
  • This PR covers TCP with hostname resolution. Higher-level protocols and distributed execution are separate milestones.

Streaming measurement

A single-worker, optimized macOS ARM64 process streamed a file to a loopback peer while writing the peer's independent response to a second file. The peer verified the upload and the harness verified every saved response byte. Three runs per size, alternating sizes, gave these process-level observations. Throughput counts both directions and includes file operations and process startup.

Bytes in each direction Median combined throughput Peak resident memory across three runs
1 MiB 3.99 MiB/s 6.20–6.23 MiB
16 MiB 4.93 MiB/s 6.20–6.22 MiB

The documentation coverage test now checks individual signatures for all ten functions introduced by std/net. The full website check passes locally.

A separate one-worker TCP echo test sent 16 MiB and verified all 16 MiB coming back. With a reused 4 KiB Kalandra buffer, median combined throughput was 654 MiB/s across three runs (644–734 MiB/s), and process peak RSS was 6.05 MiB. Timing starts after connecting and ends at EOF. These are local loopback observations.

Hosted TCP results

Commit a71a525 passed the TCP source and ownership checks on macOS ARM64, Linux x86-64 and ARM64, and Windows x86-64 and ARM64. The tests exercise a deliberate short deadline separately from positive transfers and externally generated resets. The macOS development run also verified nine delayed resets with independent delays of 1, 100 and 250 ms.

@pouya-eghbali
pouya-eghbali marked this pull request as ready for review November 24, 2026 02:10

This branch has not been deployed

No deployments
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