silk.net.datagram_wasi.
Owned UDP sockets and complete datagrams through WASI Preview 2.
Details#
A socket owns its incoming and outgoing datagram streams and drops them before the socket. The host controls network access. Datagram boundaries are preserved; receive returns the whole payload, and send returns only after the host accepts the datagram. Deadlines use the supplied clock.
Import as UdpSocket with import silk.net.datagram_wasi { UdpSocket }.
Public declarations: 2.
Datagram#
pub struct DatagramOne complete received datagram, owning its bytes and sender address.
Field data#
pub data: BytesThe complete datagram payload, including a possible empty payload.
Field source#
pub source: SocketAddressThe sender's socket address.
UdpSocket#
pub struct UdpSocketAn owned UDP socket and its receive/send streams. Close and drop release all three resources.
Implementation UdpSocket#
impl UdpSocketAssociated function bind#
pub effect fn bind(network: &Network, local: &SocketAddress, remote: Option<&SocketAddress>, deadline: Option<Instant>) -> UdpSocket
! SocketError ? &mut MonotonicClockBinds a UDP socket to local. A remote address restricts incoming traffic and supplies the
default send destination; absent means unconnected UDP. Port zero chooses a local port.
Method address#
pub effect fn address(self: &Self) -> SocketAddress ! SocketErrorReturns the bound local address. A closed socket fails with code 9.
Method send#
pub effect fn send(self: &mut Self, bytes: &[u8], remote: Option<&SocketAddress>, deadline: Option<Instant>) -> ()
! SocketError ? &mut MonotonicClockSends one complete datagram. Unconnected sockets require a destination; connected sockets may use none. Empty payloads are valid datagrams. A closed socket fails with code 9.
Method receive#
pub effect fn receive(self: &mut Self, deadline: Option<Instant>) -> Datagram
! SocketError | OutOfMemoryError ? &mut MonotonicClock | &mut AllocatorReceives one complete datagram and owns its payload. Waits until data arrives or the deadline expires. Allocation failure releases all buffers the host returned.
Method close#
pub fn close(self: &mut Self) -> ()Closes both datagram streams and then their parent socket. Repeated calls do nothing.
Implementation Drop for UdpSocket#
impl Drop for UdpSocketOperation drop#
fn drop(self: &mut Self) -> ()Category: Networking.
Profiles: wasm32-wasip2.