feat(runtime): socket option natives for TCP streams #427

Merged
argus merged 1 commit from loop/426-socket-option-natives into main 2026-10-23 13:49:43 +00:00
Collaborator

Closes #426

Step 1 of #120: the runtime can set and read the TCP options of a connected stream, behind two new natives. No std/ source changes, so the seed that builds the compiler still compiles everything.

What

  • torb_network_set_option(stream, option, value) and torb_network_option(stream, option) in runtime/io.c, declared in runtime/include/torb_network.h with the option table (0 TCP_NODELAY, 1 SO_KEEPALIVE, 2 idle time, 3 probe interval, 4 probe count). A value below 1 for options 2 to 4 is invalid argument; a closed handle or a listener is closed.
  • Hooks torb_io_system_set_option / torb_io_system_option beside torb_io_system_shutdown: runtime/os/posix_io.c (TCP_KEEPIDLE, TCP_KEEPALIVE on macOS, TCP_KEEPINTVL, TCP_KEEPCNT) and runtime/os/iocp.c (Windows 10 1709 and later through the resolved setsockopt and a newly resolved getsockopt; no SIO_KEEPALIVE_VALS fallback).
  • Natives networkSetOption and networkOption in nativeEntries(); torb_natives.h and machine_natives.c updated; two keep/network rows and the counts in docs/design/NATIVES.md; docs/design/NETWORK.md section 4 points at this slice with the option table.
  • Runtime tests in runtime/tests/io_test.c: flags set and read back, keepalive times and count set and read back, 0 refused, closed handle and listener fail.

Seed

Touches the seed: yes (new natives in the manifest). This is the first of the two commits of that rule ("teach the form"); the seed refresh and publishing are for the merge gate and Torben, step 2 of #120 follows once the published seed knows the natives.

Test

Nothing was built or run locally (loop rule: gates, bootstrap and runtime build only in forge CI). tools/check-commits.sh origin/main is clean. runtime/machine_natives.c and torb_natives.h were updated by a script that follows the generator's rules (sorted by symbol, thunks renumbered) instead of a local torb natives --header; the generated-file check in CI passed.

Forge CI on e0eb950c (run 1438): tier A, tier B, gates (sh tools/gates.sh a/b), bootstrap, commit messages, pdisc, playground and same-C all green. A first push failed in the bootstrap because the option enum typedef shared its name with the function; renamed to torb_network_option_number and amended (still one commit).

Closes #426 Step 1 of #120: the runtime can set and read the TCP options of a connected stream, behind two new natives. No `std/` source changes, so the seed that builds the compiler still compiles everything. ## What - `torb_network_set_option(stream, option, value)` and `torb_network_option(stream, option)` in `runtime/io.c`, declared in `runtime/include/torb_network.h` with the option table (0 `TCP_NODELAY`, 1 `SO_KEEPALIVE`, 2 idle time, 3 probe interval, 4 probe count). A value below 1 for options 2 to 4 is `invalid argument`; a closed handle or a listener is `closed`. - Hooks `torb_io_system_set_option` / `torb_io_system_option` beside `torb_io_system_shutdown`: `runtime/os/posix_io.c` (`TCP_KEEPIDLE`, `TCP_KEEPALIVE` on macOS, `TCP_KEEPINTVL`, `TCP_KEEPCNT`) and `runtime/os/iocp.c` (Windows 10 1709 and later through the resolved `setsockopt` and a newly resolved `getsockopt`; no `SIO_KEEPALIVE_VALS` fallback). - Natives `networkSetOption` and `networkOption` in `nativeEntries()`; `torb_natives.h` and `machine_natives.c` updated; two `keep`/`network` rows and the counts in `docs/design/NATIVES.md`; `docs/design/NETWORK.md` section 4 points at this slice with the option table. - Runtime tests in `runtime/tests/io_test.c`: flags set and read back, keepalive times and count set and read back, 0 refused, closed handle and listener fail. ## Seed Touches the seed: yes (new natives in the manifest). This is the first of the two commits of that rule ("teach the form"); the seed refresh and publishing are for the merge gate and Torben, step 2 of #120 follows once the published seed knows the natives. ## Test Nothing was built or run locally (loop rule: gates, bootstrap and runtime build only in forge CI). `tools/check-commits.sh origin/main` is clean. `runtime/machine_natives.c` and `torb_natives.h` were updated by a script that follows the generator's rules (sorted by symbol, thunks renumbered) instead of a local `torb natives --header`; the generated-file check in CI passed. Forge CI on e0eb950c (run 1438): tier A, tier B, gates (`sh tools/gates.sh a`/`b`), bootstrap, commit messages, pdisc, playground and same-C all green. A first push failed in the bootstrap because the option enum typedef shared its name with the function; renamed to `torb_network_option_number` and amended (still one commit).
feat(runtime): socket option natives for TCP streams
Some checks failed
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
ci / commit messages (pull_request) Successful in 3s
ci / what the change touches (pull_request) Successful in 3s
pdisc / pdisc (pull_request) Successful in 8s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / which runners exist (pull_request) Successful in 0s
ci / bootstrap (linux-x64) (pull_request) Failing after 52s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / every host emits the same C (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Has been skipped
ci / tier B (linux-x64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
62f981a539
torb_network_set_option and torb_network_option set and read TCP_NODELAY, SO_KEEPALIVE and the keepalive idle time,
interval and probe count of a connected stream, behind the natives networkSetOption and networkOption. One pair serves
every option, so the next one is a number in the table of torb_network.h and not a manifest entry. A value below 1 for
a time or a count is invalid argument, a closed handle or a listener is closed. The hooks sit beside
torb_io_system_shutdown in posix_io.c and iocp.c (Windows 10 1709 and later for the keepalive times).

This is the first of the two commits of the seed rule for #120: the natives are taught, std/network follows. The
generated natives header and machine table are regenerated, the audit table has the two rows, NETWORK.md section 4
lists the options.

Refs #120
orion force-pushed loop/426-socket-option-natives from 62f981a539
Some checks failed
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
ci / commit messages (pull_request) Successful in 3s
ci / what the change touches (pull_request) Successful in 3s
pdisc / pdisc (pull_request) Successful in 8s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / which runners exist (pull_request) Successful in 0s
ci / bootstrap (linux-x64) (pull_request) Failing after 52s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / every host emits the same C (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Has been skipped
ci / tier B (linux-x64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
to e0eb950c87
All checks were successful
ci / commit messages (pull_request) Successful in 3s
ci / what the change touches (pull_request) Successful in 3s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 8s
ci / which runners exist (pull_request) Successful in 0s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 2m9s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Successful in 4m43s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 2m12s
ci / every host emits the same C (pull_request) Successful in 4m51s
ci / pack the seed (pull_request) Has been skipped
ci / tier B (linux-x64) (pull_request) Successful in 12m16s
ci / archives (pull_request) Has been skipped
ci / the playground (torb as WebAssembly) (pull_request) Successful in 1m53s
ci / gates (pull_request) Successful in 0s
2026-10-23 13:15:31 +00:00
Compare
argus approved these changes 2026-10-23 13:49:42 +00:00
argus left a comment

Checklist (head e0eb950):

  • Tests: ok. Three runtime tests cover flags, keepalive times/count read back, refusals (0, negative, >int range, unknown option) and closed handle/listener; CI (tier A/B, bootstrap, gates incl. generated-file check, pdisc) green on this head.
  • Correctness: ok. Validation happens before the lookup and nothing is clamped; Linux (4/5/6) and Windows (3/16/17) fallback option numbers match the system headers; macOS uses TCP_KEEPALIVE for the idle time; flags are normalized to 0/1 on read.
  • Scope: ok. Matches #426/step 1 of #120; no std/ changes, seed untouched beyond the manifest rows.
  • Security/data: ok. No secrets, no new ports or dependencies; no stored formats touched.
  • Docs: ok. NATIVES.md counts and rows, NETWORK.md option table and the Windows 10 1709 note.
  • Architecture: ok. Runtime-internal hooks beside shutdown; no new boundary beyond the two documented natives.

Non-blocking: none. Merging by rebase.

Checklist (head e0eb950): - Tests: ok. Three runtime tests cover flags, keepalive times/count read back, refusals (0, negative, >int range, unknown option) and closed handle/listener; CI (tier A/B, bootstrap, gates incl. generated-file check, pdisc) green on this head. - Correctness: ok. Validation happens before the lookup and nothing is clamped; Linux (4/5/6) and Windows (3/16/17) fallback option numbers match the system headers; macOS uses TCP_KEEPALIVE for the idle time; flags are normalized to 0/1 on read. - Scope: ok. Matches #426/step 1 of #120; no std/ changes, seed untouched beyond the manifest rows. - Security/data: ok. No secrets, no new ports or dependencies; no stored formats touched. - Docs: ok. NATIVES.md counts and rows, NETWORK.md option table and the Windows 10 1709 note. - Architecture: ok. Runtime-internal hooks beside shutdown; no new boundary beyond the two documented natives. Non-blocking: none. Merging by rebase.
argus merged commit a176990ebc into main 2026-10-23 13:49:43 +00:00
argus deleted branch loop/426-socket-option-natives 2026-10-23 13:49:43 +00:00
Sign in to join this conversation.
No reviewers
No labels
loop
ready
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language!427
No description provided.