Internal @tcpRequest socket primitive: deferred-Text request exchange (#143) - #159
Open
assapir wants to merge 1 commit into
Open
Internal @tcpRequest socket primitive: deferred-Text request exchange (#143)#159assapir wants to merge 1 commit into
assapir wants to merge 1 commit into
Conversation
…st exchange (#143) Add `@tcpRequest(address :: Text, requestBytes :: Text) -> Text` (deferred): a one-shot, close-delimited TCP request exchange — connect, write the request, read the response until the peer closes — returning the response bytes as a deferred `Text`, forced on use exactly like `@readStdin`. It reuses the generic launch/Deferred/force core and the reactor-parked non-blocking TCP, adding no new park/deferred plumbing: a new `launch_deferred_text` wrapper is now shared by both value-returning primitives so the `{deferred, -1}` C-ABI tagging lives in one place. The producer copies its address/request into owned buffers before the background fiber is spawned, so it never reads a caller Text that could be reclaimed. Sockets stay internal: the primitive is declared in a new trusted corelib module `internal.net` (added to the `@`-declaration gate), not a public `core.net` — the HTTP client sits on it and users do not import raw sockets. This is the bytes-backed foundation for http.client's send: HTTP framing/parsing happens in Quilon on the forced response bytes. Ships with a runtime round-trip unit test and a compiler JIT+AOT round-trip test, both against a local listener; extends the intrinsic-link smoke gate; documents the internal primitive in LANGUAGE.md's concurrency section. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Adds the low-level socket
@primitive the HTTP client (#143) will sit on:A one-shot, close-delimited TCP request exchange — connect to
address(host:port), write the request bytes, read the response until the peer closes — returning all response bytes as a deferredText, forced on use exactly like@readStdin. This is design (a): the deferred value is raw response bytes; HTTP framing/parsing will happen in Quilon on force.How it fits the existing model
launch(|| ...)producer over the merged reactor-parked non-blocking TCP (quilon-rt/net.rs) and the genericlaunch/Deferred/forcecore (Deferred values + @readStdin: the value-returning half of colorless implicit futures #149). No new park/deferred plumbing.launch_deferred_textwrapper now holds the{ deferred, -1 }C-ABI tagging in one place, shared by both value-returning primitives (@readStdin,@tcpRequest).Textthat a later collection could reclaim.__force_text, the deferred-taint pass) works unchanged —@tcpRequestis just recognized as a second deferred-producing primitive.Sockets stay internal
Declared in a new trusted, internal corelib module
internal.net(added to the@-declaration gateCORELIB_SOURCES), not a publiccore.net. The HTTP client imports it; users do not import raw sockets. No public corelib doc (it is not user-facing); noted inLANGUAGE.md's concurrency /@-primitives section as an internal primitive.Fault handling
Fail-loud on resolve/connect/write/read failure, reporting the target address and the stage it failed at, then
__exit(1)— same posture as the stdin reader.Tests
quilon-rt/net.rs): launch@tcpRequestagainst a localstd::netlistener on its own thread, force the deferred value on a fiber, assert the response bytes.tests/tcp_request_test.rs): spawn a local listener, compile+run a.qlprogram that does one@tcpRequestandassertEqs the response — matching response exits 0, a wrong expectation trips the assertion (proving the real server bytes flowed and forced), under bothquilon run(JIT) andquilon build(native AOT).__tcp_request_launch(guarded by a runtime-false branch so the symbol is emitted but no real connection runs).@readStdinones.Full suite passes;
cargo fmt --check+clippy -D warningsclean. Reviewed via read-only correctness and simplification passes (no bugs; one duplication consolidated intolaunch_deferred_text).Status
PARKED — do not merge without explicit per-PR approval.
Known limitation (documented):
to_socket_addrsDNS resolution for a hostname is blocking; numeric addresses (the tests) never block. Non-blocking DNS is a later refinement.🤖 Generated with Claude Code