veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

io/net

lib/io/net.vk

lib/io/net.vk Pure-Veko connected TCP io/Stream adapters, timeouts, and readiness polling over net/*. Requires .net capability.

signature
TcpStreamState = struct { sock i64, peer str }

Backing state for a TCP socket-backed io/Stream.

signature
tcp-stream = fn [sock i64, peer str] io/Stream

Wraps an existing connected TCP socket handle sock in an io/Stream.

Executable Example
veko
use [io, inet = io/net]
s = inet/tcp-stream 42 '127.0.0.1:8080'
if s.name != 'tcp://127.0.0.1:8080' or (inet/stream-socket s) != 42 [ err 'io/net' ] else [ .ok ]
resolve-ipv4 fn caps: .net
signature
resolve-ipv4 = fn [host str] block[str]

Resolves host to IPv4 addresses using .net-only primitives (localhost, numeric IPv4, net/resolve, and pure-Veko UDP DNS fallback).

dial-tcp-timeout fn caps: .net
signature
dial-tcp-timeout = fn [host str, port i64, timeout dur] io/Stream

Dials a TCP connection to host:port with an enforced timeout duration and returns an io/Stream.

signature
dial-tcp = fn [host str, port i64] io/Stream

Dials a TCP connection to host:port with a default 10s deadline and returns an io/Stream.

signature
stream-socket = fn [s io/Stream] i64

Returns the underlying OS socket handle from a TCP-backed io/Stream.

set-timeout fn caps: .net
signature
set-timeout = fn [s io/Stream, timeout dur] enum

Applies a read/write deadline timeout to a TCP-backed io/Stream.

poll-streams fn caps: .net
signature
poll-streams = fn [streams block[io/Stream], timeout dur] block

Polls streams (block[io/Stream]) for readability up to timeout and returns indices of ready streams.

set-nonblock fn caps: .net
signature
set-nonblock = fn [sock i64, enabled bool] enum

Toggles non-blocking mode (O_NONBLOCK / FIONBIO) on OS socket sock.

listen-nonblock fn caps: .net
signature
listen-nonblock = fn [addr str] i64

Binds a TCP listener on addr ('127.0.0.1:0') and enables non-blocking mode.

dial-tcp-nonblock fn caps: .net
signature
dial-tcp-nonblock = fn [host str, port i64] i64

Starts a non-blocking TCP connection to host:port (returns socket handle in connecting/connected state).

sock-error fn caps: .net
signature
sock-error = fn [sock i64] i64

Reads SO_ERROR on sock (returns 0 when healthy/connected, or non-zero OS error code).

try-accept fn caps: .net
signature
try-accept = fn [ln i64] i64

Non-blocking accept on listener ln: returns >= 0 client socket, -1 if would-block, or err.

try-read-into fn caps: .net
signature
try-read-into = fn [sock i64, mut buf bytes, max_n i64] i64

Non-blocking read appending up to max_n bytes into mut buf. Returns > 0 bytes read, 0 on clean peer EOF, -1 if would-block, or err.

try-write fn caps: .net
signature
try-write = fn [sock i64, data bytes] i64

Non-blocking write of data on sock: returns >= 0 bytes written, -1 if would-block, or err.

try-write-from fn caps: .net
signature
try-write-from = fn [sock i64, data bytes, offset i64] i64

Non-blocking write of data[offset..(len data)] on sock.