UDPSocket¶
A UDP socket actor driven by a
UDPSocketNotify.
Wraps the net package's UDPSocket class, UDPSocketActor trait, and
UDPLifecycleEventReceiver trait into a single actor.
send_to is synchronous and returns a SendToResult — use it from within
callbacks where the result matters. write_to is a fire-and-forget
behavior for sending from other actors; the result is discarded.
actor tag UDPSocket is
UDPSocketActor[UDPRuntimeBackend ref] tag,
UDPLifecycleEventReceiver[UDPRuntimeBackend ref] ref
Implements¶
- UDPSocketActor[UDPRuntimeBackend ref] tag
- UDPLifecycleEventReceiver[UDPRuntimeBackend ref] ref
Constructors¶
create¶
Bind a UDP socket to host:port. Port "0" lets the OS assign an
ephemeral port.
new tag create(
auth: UDPAuth val,
notify: UDPSocketNotify iso,
host: String val,
port: String val,
read_buffer_size: ReadBufferSize = net.DefaultReadBufferSize(),
ip_version: IPVersion = net.DualStack,
max_datagrams_per_turn: USize val = 256)
: UDPSocket tag^
Parameters¶
- auth: UDPAuth val
- notify: UDPSocketNotify iso
- host: String val
- port: String val
- read_buffer_size: ReadBufferSize = net.DefaultReadBufferSize()
- ip_version: IPVersion = net.DualStack
- max_datagrams_per_turn: USize val = 256
Returns¶
- UDPSocket tag^
Public Behaviours¶
write_to¶
Send a datagram. Fire-and-forget: the send is silently dropped if the
socket is not open. Use send_to from within a callback when the result
matters.
Parameters¶
- data: ByteSeq
- to: NetAddress val
dispose¶
Public Functions¶
send_to¶
Send one datagram to to. Returns SendToOk when the datagram was
handed to the OS. UDP sends are synchronous and all-or-nothing.
Callable from any callback (where sock is ref). From outside the
actor, use the write_to behavior instead.
Parameters¶
- data: ByteSeq
- to: NetAddress box
Returns¶
close¶
Close the socket. No graceful shutdown: the fd is closed immediately.
Returns¶
- None val
local_address¶
Return the local IP address the socket is bound to.
Returns¶
- NetAddress val
is_open¶
True when the socket is bound and has not been closed.
Returns¶
- Bool val
is_closed¶
True when the socket has been closed.
Returns¶
- Bool val
get_so_rcvbuf¶
Get the OS receive buffer size. Returns (errno, value).
Returns¶
set_so_rcvbuf¶
Set the OS receive buffer size. Returns 0 on success, or errno.
Parameters¶
- bufsize: U32 val
Returns¶
- U32 val
get_so_sndbuf¶
Get the OS send buffer size. Returns (errno, value).
Returns¶
set_so_sndbuf¶
Set the OS send buffer size. Returns 0 on success, or errno.
Parameters¶
- bufsize: U32 val
Returns¶
- U32 val
getsockopt_u32¶
Get a socket option as a U32. Returns (errno, value).
Parameters¶
Returns¶
setsockopt_u32¶
Set a socket option as a U32. Returns 0 on success, or errno.
Parameters¶
Returns¶
- U32 val