You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: std.net listener and UDP bind APIs are unconditional -1 runtime stubs #658
The public std.net module advertises TCP listening/accept and UDP binding, but the user runtime implementations unconditionally return -1. No server can be built against these APIs.
Reproduction
with -e 'use std.net;print_i32(tcp_listen(18080));print_i32(udp_bind(18081))'
Actual:
-1
-1
Expected: valid descriptors when those unused loopback ports can be bound, or a real OS-derived error when they cannot.
Public contract
lib/std/net.w:13-19 documents tcp_listen and tcp_accept as working socket operations, and lines 37–39 do the same for udp_bind. The module header says these primitives wrap POSIX APIs. The §18.6 requirements also mark std.net; TCP, UDP, DNS complete.
Exact root cause
rt/rt_core.w:3453-3466 labels these functions “Network stubs” and discards every argument:
pub fn with_net_tcp_listen(port: i32, backlog: i32) -> i32:
let _ = port
let _ = backlog
-1
pub fn with_net_tcp_accept(sock: i32) -> i32:
let _ = sock
-1
pub fn with_net_udp_bind(port: i32) -> i32:
let _ = port
-1
Repository-wide symbol search finds no platform implementation that overrides these bodies. LLDB stops at rt_core.w:3458; the emitted function is exactly mov w0, #-1; ret.
5 Whys
Listening and binding always fail because their runtime functions return -1.
They return -1 because rt_core contains placeholder bodies.
There are no Darwin/Linux/Windows listener or bind implementations to delegate to.
The public stdlib wrappers were exposed before their runtime backend existed.
No loopback listener/bind test exercises the advertised server-side surface.
Acceptance criteria
Implement TCP socket creation, bind, listen, and accept on supported platforms.
Implement UDP socket creation and bind on supported platforms.
Preserve real OS error information (preferably through a typed public error surface rather than an undifferentiated -1).
Add loopback tests that bind port 0, discover the selected address, connect/accept, exchange bytes, and close both ends; add an equivalent UDP bind/send/receive test.
Remove the stub label and unconditional placeholder bodies.
Implementation: the three rt_core -1 stubs are gone; with_net_tcp_listen, with_net_tcp_accept, and with_net_udp_bind are real implementations in both POSIX platform files (rt/darwin_aarch64.w, rt/linux_x86_64.w), living beside the existing connect/send/recv family: socket → SO_REUSEADDR → bind INADDR_ANY → listen (TCP), EINTR-looped accept, UDP socket + bind. Platform-correct constants and sockaddr_in layouts (Darwin SOL_SOCKET=0xFFFF/sin_len; Linux SOL_SOCKET=1/u16 family).
Error surface: failures return -errno (the rt_access convention), not an undifferentiated -1. Verified live: double-listen on the same port returns -48 (EADDRINUSE on Darwin). std.net doc comments updated. (A fully typed Result-based net API would be a larger surface redesign — noting it as future work rather than smuggling it into this fix.)
New primitives the acceptance flow requires: sock_port() (getsockname — discover the ephemeral port after tcp_listen(0)/udp_bind(0)) and udp_connect() (connected UDP socket so send/recv work for datagrams; tcp_connect refactored onto the shared resolver helper rather than duplicating it).
Verified live on Darwin (all in behav_net_loopback.w):
TCP: tcp_listen(0) → sock_port → tcp_connect(127.0.0.1) → tcp_accept → ping/pong both directions → all three fds closed
The issue's repro now yields valid descriptors for both tcp_listen(18080) and udp_bind(18081)
(Port-1 note: binding port 1 succeeds unprivileged on macOS 11+ — that's the OS, not a bug.)
Platforms: Linux implementation is source-identical in shape and passes --target x86_64-unknown-linux-gnu --no-prelude --validate-all; no Linux host execution yet. Windows has no with_net_* backend at all (programs using std.net never linked there), so nothing regressed — Windows net lands with the deferred post-v0.16.0 Windows work.
Gates: build ok, FIXPOINT, analyze audit:all violations=0, all test targets green (behavior now includes the loopback fixture), EMIT-C smoke ok, test-green + last-green recorded.
Activity
Runtime: implement std.net listener and UDP surfaces (#658)
ehartford commentedon Jul 17, 2026
Fixed in 4945320.
Implementation: the three rt_core
-1stubs are gone;with_net_tcp_listen,with_net_tcp_accept, andwith_net_udp_bindare real implementations in both POSIX platform files (rt/darwin_aarch64.w, rt/linux_x86_64.w), living beside the existing connect/send/recv family:socket→SO_REUSEADDR→bindINADDR_ANY →listen(TCP), EINTR-loopedaccept, UDPsocket+bind. Platform-correct constants andsockaddr_inlayouts (DarwinSOL_SOCKET=0xFFFF/sin_len; LinuxSOL_SOCKET=1/u16 family).Error surface: failures return
-errno(the rt_access convention), not an undifferentiated-1. Verified live: double-listen on the same port returns-48(EADDRINUSE on Darwin). std.net doc comments updated. (A fully typedResult-based net API would be a larger surface redesign — noting it as future work rather than smuggling it into this fix.)New primitives the acceptance flow requires:
sock_port()(getsockname — discover the ephemeral port aftertcp_listen(0)/udp_bind(0)) andudp_connect()(connected UDP socket sosend/recvwork for datagrams;tcp_connectrefactored onto the shared resolver helper rather than duplicating it).Verified live on Darwin (all in
behav_net_loopback.w):tcp_listen(0)→sock_port→tcp_connect(127.0.0.1)→tcp_accept→ ping/pong both directions → all three fds closedudp_bind(0)→sock_port→udp_connect→ datagram delivered → closedtcp_listen(18080)andudp_bind(18081)Platforms: Linux implementation is source-identical in shape and passes
--target x86_64-unknown-linux-gnu --no-prelude --validate-all; no Linux host execution yet. Windows has nowith_net_*backend at all (programs using std.net never linked there), so nothing regressed — Windows net lands with the deferred post-v0.16.0 Windows work.Gates: build ok, FIXPOINT, analyze audit:all violations=0, all test targets green (behavior now includes the loopback fixture), EMIT-C smoke ok, test-green + last-green recorded.