These libraries are experimental. APIs may change without notice. Generated from source with koruc 0.1.7 on 9/16/2026.

Udp

@korulang/udp@0.0.1

Nonblocking UDP datagrams for Koru with phantom socket obligations

udp/index.kz · 14 tors

@korulang/udp — nonblocking UDP datagrams for Koru (v0: IPv4, posix sockets) · 21 more lines
@korulang/udp — nonblocking UDP datagrams for Koru (v0: IPv4, posix sockets) Raw datagrams behind phantom obligations. The footguns this compiles away: 1. There is no unbound-socket state AT ALL. `bind` is the only mint: a *Socket exists only once it owns a port, which is the earliest a UDP socket can do anything anyway (even sendto wants a local port). 2. `close` consumes <!bound> — send-after-close is not expressible, and a forgotten close is auto-healed or a KORU030, same as raylib's window. 3. `packets` drains the nonblocking fd up to `max` datagrams, firing `! packet` once each. The *Packet<packet!> handle is a scoped borrow: it aliases the shared recv buffer, valid only inside the branch body (same shape as raylib's *Frame<frame>, which the engine brackets). 4. packet.key folds (ipv4, port) into an i64 session key — the column a server keys per-client state on. send.key consumes the same fold, so a client row needs one column, not three. The socket is nonblocking by construction (O_NONBLOCK at bind): recv hits WouldBlock, which the drain reads as | done. This is the poll-shaped v0 — the deadline/evented recv is the named gap (kqueue exists over in Orisha's pump and wants porting into a socket-source tor someday).

Phantom lifecycles

Derived from the phantom labels in the declarations below — state! issues an obligation the compiler will chase, !state discharges it, a bare state holds it without moving it. Nothing here is hand-drawn.

Socket 1 state bound!
Packet 1 state packet!

bind

<bound!> index.kz:56

socket.port

<bound> index.kz:80

socket.rcvbuf

<bound> index.kz:95

socket.rcvsize

<bound> index.kz:108

close

<!bound> index.kz:119

packets

<bound><packet!> index.kz:131

packet.data

<packet> index.kz:159

packet.key

<packet> index.kz:163

packet.addr

<packet> index.kz:168

packet.port

<packet> index.kz:171

release.packet

<!packet> index.kz:176

send.ip

<bound> index.kz:185

send.to

<bound> index.kz:199

send.key

<bound> index.kz:213