Skip to main content

Module tcp

Module tcp 

Source
Expand description

TCP client natives (tcp.lg): the SYNC implementations the AOT tier calls via map_native_function, plus the shared error-message formatters every tier reuses — one wording, so the tiers cannot drift even in their Err text.

Std-only (no tokio): the AOT tier blocks the calling thread, exactly like file::read. The async tiers (tree-walker/VM) live in the compile crate’s TcpRegistry over tokio and reuse the formatters below.

Connections are process-global, keyed by an opaque Int handle — the value a LOGOS program threads through tcpSend/tcpRecv/tcpClose. A closed or never-opened handle is always an Err value, never a panic.

Constants§

MAX_RECV
The largest single tcpRecv/tcpRecvExact request (64 MiB) — a guard against a hostile or corrupted length field, not a protocol limit (loop for more).

Functions§

accept
Accept one queued connection (blocks; a set_timeout on the listener applies).
close
Close the connection or listener; the handle is dead afterwards.
connect
Open a TCP connection; Ok carries the opaque connection handle.
connect_tls
Open a TCP connection and complete a TLS handshake over it; Ok carries the same opaque handle every other native takes, so tcpSend/tcpRecv work unchanged.
ensure_crypto_provider
The client TLS configuration: the bundled Mozilla roots, plus any extra root the operator names in LOGOS_TLS_EXTRA_ROOT (a PEM file).
err_accept
err_connect
err_invalid_len
err_invalid_port
err_invalid_timeout
err_listen
err_recv
err_send
err_shutdown
err_timeout
err_torn
err_unknown_conn
listen
Bind a listening socket (passive open; port 0 = ephemeral).
listener_port
The local port a listener is bound to (how an ephemeral bind is learned).
recv
Block until at least one byte arrives (or EOF), returning up to max_len bytes. A clean EOF is Ok of the empty Seq — a value, not an error.
recv_exact
Block until exactly len bytes arrive; a peer closing early is an Err (a torn frame is never silently truncated — protocol framing depends on it).
send
Send every byte (each Int masked to 0–255); Ok carries the byte count. data arrives as the AOT tier’s borrowed Seq of Int parameter form.
set_timeout
Set the connection’s read+write timeout in milliseconds (0 clears it) — Python settimeout style: it applies to every subsequent recv/send, whose expiry is the shared tcp: operation timed out error.
shutdown_write
Half-close: send FIN on the write side (shutdown(SHUT_WR)), keep reading.
tls_config
upgrade_tls
Wrap an ESTABLISHED plain connection in TLS, in place.