runtime: socket option natives for TCP streams (step 1 of #120) #426
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
First step of #120 (socket options for
std/network, FIRST-PARTY.md gap 22): the runtime can set and read the TCPoptions of a connected stream, behind two new natives. No
std/source changes in this step, so the seed that buildsthe compiler (which imports
std/networkincompiler/src/debugger/adapter.trb) still compiles everything.Design
std/network, ownernetwork, verdictkeep(NATIVES.md):networkSetOption(stream: Int, option: Int, value: Int): Intanswers 0 or a failure,networkOption(stream: Int, option: Int): Intanswers the value(never negative) or a failure. One pair instead of one native per option, so the next option is a number, not a
manifest entry.
std/and the runtime, listed inruntime/include/torb_network.h):0
TCP_NODELAY(0 or 1), 1SO_KEEPALIVE(0 or 1), 2 idle time before the first probe in seconds, 3 intervalbetween probes in seconds, 4 probe count. Seconds are whole numbers; a value below 1 for 2 to 4 is
invalid argument, not a silent clamp.torb_io_system_shutdown:runtime/os/posix_io.c(TCP_KEEPIDLEon Linux andFreeBSD,
TCP_KEEPALIVEon macOS,TCP_KEEPINTVL,TCP_KEEPCNT) andruntime/os/iocp.c(TCP_KEEPIDLE,TCP_KEEPINTVL,TCP_KEEPCNTof Windows 10 1709 and later, through the already-resolvedsetsockopt/getsockoptpointers; an older Windows answers the system's failure, no
SIO_KEEPALIVE_VALSfallback).Closedthrough the existing lookup, astorb_network_shutdowndoes.The defaults stay what they are (
TCP_NODELAYon, keepalive off); nothing here changes a socket that no one asksabout.
options,
SO_LINGER, astd/API (step 2 of #120).Acceptance criteria
torb_network_set_optionandtorb_network_optioninruntime/io.c, declared inruntime/include/torb_network.hwith the option table above, with hooks in
runtime/os/posix_io.candruntime/os/iocp.c.nativeEntries()ofcompiler/src/backend/c/natives.trb(stateReady);runtime/include/torb_natives.handruntime/machine_natives.cregenerated withtorb natives --header, thegenerated-file check green.
keep,network) in thestd/networktable ofdocs/design/NATIVES.md; the audit check stays green.runtime/tests/io_test.c: set and read backTCP_NODELAYoff and on, keepalive on with idle,interval and count, a value of 0 is refused, a closed handle and a listener handle fail with the closed/invalid
kind. Run in the forge CI (
sh runtime/build.shjob) on Linux; no assertion depends on a probe really beingsent.
docs/design/NETWORK.mdsection 4: the "A setter is a later addition" sentence ofTCP_NODELAYpoints at thisslice, with the option table.
sh tools/gates.sh a);btoo, sinceruntime/changes.Seed
Touches the seed: yes (a new native in the manifest,
docs/design/NATIVES.md, CLAUDE.md "Seed and breakingchanges"). This is the first of the two commits of that rule, landed alone as its own PR: "teach the form". The seed
refresh and the publishing of the seed (
seedworkflow) after it lands are Torben's and the merge gate's, not theloop's. The second commit is step 2 of #120 and is filed only once the published seed knows the natives.
Commit
One commit:
feat(runtime): socket option natives for TCP streams(at most 100 characters).Dependencies
None. Independent of #119 (Unix domain sockets), which adds its own natives; whichever lands second regenerates the
two generated natives files on top of the other.
Source
docs/design/NETWORK.mdsection 4 ("TCP_NODELAYis on for every stream", "the socket options ... are lateradditions, each when a program needs it")
TCP_NODELAY, keepalive) #120TCP_NODELAY, keepalive) #120[loop:torbscript] claim implement by session:loop-torbscript-20261023 until 2026-10-23T19:06Z
[loop:torbscript] implement: natives
networkSetOption/networkOptionwith runtime, POSIX and IOCP hooks, tests, audit rows and NETWORK.md table done as one commitfeat(runtime): socket option natives for TCP streams, PR #427, CI success (tier A, tier B, gates green; one red round fixed: enum typedef name clashed with the function), next: review (merge gate; seed refresh and step 2 of #120 stay with the gate/Torben). Claim released. Worker usage: about 150k tokens, Sonnet 5.5.TCP_NODELAY, keepalive) #120TCP_NODELAY, keepalive) #120TCP_NODELAY, keepalive) #120