add net module: tcp sockets via libuv (prereq for pure-ts postgres driver)#585
Open
add net module: tcp sockets via libuv (prereq for pure-ts postgres driver)#585
Conversation
…/end/destroy, on connect/data/error/close events). prereq for pure-ts postgres driver. smoke test passes (connect-refused path).
This was referenced Apr 20, 2026
Open
Open
Contributor
Benchmark Results (Linux x86-64)
CLI Tool Benchmarks
|
… was failing because chad build couldn't resolve the chadscript/net import since registerStdlib call was missing. one-line fix in src/chad-native.ts.
… socket class + createConnection so user code + ide gets typechecked (was missing from the initial net-module commit, paired with the registerStdlib fix).
This was referenced Apr 20, 2026
Owner
Author
|
CI is blocked on a main-branch regression, not on this PR's code. Bisected: #597 — the Repro is deterministic: reduce registerStdlib calls in chad-native.ts to 7 → compile succeeds. Any 8th (regardless of content/order/key) → fails with Options:
I lean option 1. Pausing on pushing more commits to this branch. |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
netmodule exposing raw TCP sockets via libuv. Prerequisite for a pure-TypeScript Postgres driver (and any future protocol implementation — Redis, MongoDB, etc).Built by an agent in worktree isolation off
origin/main. Smoke test passes on macOS arm64.What's in it
c_bridges/net-bridge.c(401 LOC) — libuv-backed TCP bridge:cs_net_connect,cs_socket_write/end/destroy,cs_socket_poll/wait, event kind/data/len/consume accessors. GC-aware, no trampolines.lib/net.ts(225 LOC) —Socketclass withon('connect' | 'data' | 'error' | 'close', cb),write(buf: Buffer),end(),destroy(),removeDataListener(cb). ExposescreateConnection(host, port).scripts/build-vendor.sh— buildsnet-bridge.oafterchild-process-spawnsrc/compiler.ts+src/native-compiler-lib.ts—usesNetdetection (scansdeclaredExternFunctionsforcs_net_*prefix, mirrorsusesPostgres), conditional linking ofnet-bridge.o+-luv.github/workflows/ci.yml—net-bridge.oadded to release tarball packaging +verify-lib-contentslisttests/fixtures/net/tcp-echo.ts— smoke test:createConnection→cs_net_connect→ libuv connect →isOpen()/destroy()round-trip. Follows the// @test-passedfixture pattern.Chad-subset friction points discovered
All documented in the "Known limits" block at the top of
lib/net.ts. Four of these are real codegen bugs worth filing as separate issues:Array<(x: string) => void>emits "function-pointer arrays not yet supported". Forced a single-listener-per-event shape instead of the usual array-of-listeners pattern.store i8* __lambda_Nmissing the@sigil; clang rejects the IR. Worked around with a module-level_netNoopCbreference.letflags mutated inside listeners aren't visible outside. Test had to signal via stdout sentinels instead of a captured flag.arr[i](args)call pattern — parser rejects as "Unsupported call expression: ElementAccessExpression".let x: Type;then later-assign — method resolution onxbreaks ("Method 'on' on 'x' is not supported"). Worked around by inlining thecreateConnectioncall.char*across the FFI boundary doesn't reliably compare=== "". Dropped the throw-on-fail; callers useisOpen()instead.Test plan
bash scripts/build-vendor.shbuildsc_bridges/net-bridge.onpm run buildtypecheckslib/net.tstests/fixtures/net/tcp-echo.tscompiles + runs + emitsTEST_PASSEDverify-cross-compiled-binaryfindsnet-bridge.oin the release tarballFollow-ups (separate PRs)
removeDataListeneris wired for the TLS-upgrade demultiplexer hook)net+tlsonce both land)