Add UDP socket support to runtime (udp.bind, udp.send-to, udp.receive-from, udp.close) #433
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq#433
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Motivation
Seq has TCP socket primitives but no UDP. UDP unblocks a long list of common protocols — DNS resolvers, NTP clients, multicast discovery, syslog, OSC (audio/lighting control), QUIC's underlying transport, and most game-network patterns. A near-term motivating use case is a Seq → OSC → Csound live-coding music POC, but the API design should serve all the above, not just OSC.
The design context lives at
docs/design/LIVE_CODING_CSOUND_POC.md— it explicitly treats UDP as a prerequisite that's worth landing even if the music POC fails.Proposed API
Mirror the shape of the existing
tcp.*words. Sockets are integer handles managed by a registry, just liketcp.*. All operations return a success Bool on top so callers can branch with[ ... ] [ ... ] if.Stack-effect conventions match
tcp.*: failure pushes zeroed/empty values plusfalse. Success Bool is always on top.Implementation Notes (non-prescriptive)
may::net::UdpSocketfor coroutine-aware non-blocking I/O — strands must yield while waiting onrecv_from, same astcp.readdoes today.crates/runtime/src/udp.rsmirroring the structure oftcp.rs. TheSocketRegistry<T>pattern (with free-list reuse) used bytcp.rsshould be lifted into something shared if it isn't already, or duplicated for UDP and refactored later.MAX_SOCKETS = 10_000andMAX_READ_SIZE = 1 MB(per datagram) feel right.lib.rs, type signatures incrates/compiler/src/builtins.rs, AST validation entry, codegen runtime symbol.Tests
Loopback test that proves round-trip: bind a UDP socket on
127.0.0.1port 0, get the assigned port back, send a payload to that port from another socket, receive it, assert byte-exact match including the source host/port. Mirror thetcp/tests.rsstructure so it lives undercrates/runtime/src/udp/tests.rs.Negative tests: invalid port (negative, > 65535) returns
(0, false); closed-socket send returnsfalse; closed-socket recv returns the failure tuple.What does NOT change
Downstream
Once UDP lands, the live-coding POC adds an OSC encoder (in Seq, in the example dir) and a Csound example without further runtime changes. UDP is the only required runtime addition for the whole POC.
https://github.com/navicore/patch-seq/pull/434