Source src/silo:std.effects.udp
1##! Udp effect — UDP datagram operations. 2##! 3##! Sub-effect of `Net`. `UdpSocket` is an `AnyUInt` file-descriptor 4##! identifier; addresses are `Str host` + `AnyInt port` pairs; byte 5##! payloads are `Bytes`. Typed `UdpSocket` (unique-mode), `SocketAddr`, 6##! `NetError`, and `UDuration` land with the host handler. 7##! 8##! The current decl exposes `bind`, `send-to`, `recv-from`, `send`, 9##! `recv`, `connect`, `close`, `local-addr`, and `set-broadcast`; 10##! multicast, TTL, and timeout operations are deferred. 11 12:use 13 :open core AnyInt AnyUInt Bool Bytes Pair Str Unit Result 14 :open effects.net Net 15:end 16 17# si[impl effect.udp.decl+1] 18## UDP datagram effect. Socket handles are carried as `AnyUInt` fds; 19## `SocketAddr` is represented as a `(Pair Str AnyInt)` of (host, port). 20:effect(pub) Udp Net 21 # si[impl effect.udp.bind] 22 ## Bind a UDP socket to the given host:port. Returns a socket handle. 23 .udp-bind ( Str AnyInt -> (Result AnyUInt Str) ) 24 # si[impl effect.udp.connect] 25 ## Pin the socket's default peer to the given host:port. 26 .udp-connect ( Str AnyInt AnyUInt -> (Result AnyUInt Str) ) 27 # si[impl effect.udp.send-to+1] 28 ## Send a single datagram to the given host:port via the socket. 29 .udp-send-to ( Bytes Str AnyInt AnyUInt -> (Result AnyUInt Str) ) 30 # si[impl effect.udp.send] 31 ## Send a datagram to the socket's connected peer. 32 .udp-send ( Bytes AnyUInt -> (Result AnyUInt Str) ) 33 # si[impl effect.udp.recv-from+1] 34 ## Receive a datagram (bytes + sender host:port) up to `max` bytes. 35 .udp-recv-from ( AnyUInt AnyUInt -> (Result (Pair Bytes (Pair Str AnyInt)) Str) ) 36 # si[impl effect.udp.recv] 37 ## Receive a datagram from the connected peer up to `max` bytes. 38 .udp-recv ( AnyUInt AnyUInt -> (Result Bytes Str) ) 39 # si[impl effect.udp.close] 40 ## Close the socket, releasing its kernel resources. 41 .udp-close ( AnyUInt -> ) 42 # si[impl effect.udp.local-addr] 43 ## Return the local host:port the socket is bound to. 44 .udp-local-addr ( AnyUInt -> (Pair Str AnyInt) ) 45 # si[impl effect.udp.set-broadcast+1] 46 ## Enable or disable SO_BROADCAST on the socket. 47 .udp-set-broadcast ( Bool AnyUInt -> (Result Unit Str) ) 48:end