ConnectedUDPSocket[optional UDP: ConnectedUDPBackend ref]¶
A UDP socket connected to a single peer: bind, connect, send datagrams, receive datagrams, and close. The peer is fixed at creation and the kernel filters incoming datagrams by source address.
A ConnectedUDPSocketActor owns one and delegates to it.
Create with
ConnectedUDPSocket(auth, host, port, peer_host, peer_port, enclosing, ler),
using ConnectedUDPSocket.none() as the field initializer before that.
See the package documentation for the full lifecycle.
Constructors¶
create¶
Bind a UDP socket to host:port and connect it to
peer_host:peer_port. Port "0" for the local side lets the OS
assign an ephemeral port.
new ref create(
auth: UDPAuth val,
host: String val,
port: String val,
peer_host: String val,
peer_port: String val,
enclosing: ConnectedUDPSocketActor[UDP] ref,
ler: ConnectedUDPLifecycleEventReceiver[UDP] ref,
read_buffer_size: ReadBufferSize = DefaultReadBufferSize(),
ip_version: IPVersion = DualStack,
max_datagrams_per_turn: USize val = 256)
: ConnectedUDPSocket[UDP] ref^
Parameters¶
- auth: UDPAuth val
- host: String val
- port: String val
- peer_host: String val
- peer_port: String val
- enclosing: ConnectedUDPSocketActor[UDP] ref
- ler: ConnectedUDPLifecycleEventReceiver[UDP] ref
- read_buffer_size: ReadBufferSize = DefaultReadBufferSize()
- ip_version: IPVersion = DualStack
- max_datagrams_per_turn: USize val = 256
Returns¶
- ConnectedUDPSocket[UDP] ref^
none¶
Placeholder for field initialization before the real constructor runs.
Returns¶
- ConnectedUDPSocket[UDP] ref^
Public Functions¶
send¶
Send one datagram to the connected peer. Returns UDPSendOk when the
datagram was handed to the OS. UDP sends are synchronous and
all-or-nothing: the entire datagram goes out or nothing does.
Parameters¶
- data: ByteSeq
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
remote_address¶
Return the remote peer address the socket is connected to.
Returns¶
- NetAddress val
read_again¶
Re-enter the read loop. Called internally after yielding or exhausting the per-turn budget; applications do not call this directly.
Returns¶
- None val
is_open¶
True when the socket is connected 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 for this socket. Returns (errno, value). On success errno is 0.
Returns¶
set_so_rcvbuf¶
Set the OS receive buffer size for this socket. Returns 0 on success, or a non-zero errno.
Parameters¶
- bufsize: U32 val
Returns¶
- U32 val
get_so_sndbuf¶
Get the OS send buffer size for this socket. Returns (errno, value). On success errno is 0.
Returns¶
set_so_sndbuf¶
Set the OS send buffer size for this socket. Returns 0 on success, or a non-zero errno.
Parameters¶
- bufsize: U32 val
Returns¶
- U32 val
getsockopt¶
General interface to getsockopt(2). Returns (0, data) on success or
(errno, undefined) on failure. Returns (1, empty) when the socket is
not open.
fun box getsockopt(
level: I32 val,
option_name: I32 val,
option_max_size: USize val = 4)
: (U32 val , Array[U8 val] iso^)
Parameters¶
Returns¶
getsockopt_u32¶
Wrapper for getsockopt(2) where the kernel returns a C uint32_t.
Returns (0, value) on success or (errno, undefined) on failure.
Returns (1, 0) when the socket is not open.
Parameters¶
Returns¶
setsockopt¶
General interface to setsockopt(2). Returns 0 on success, or a non-zero
errno. Returns non-zero when the socket is not open.
Parameters¶
Returns¶
- U32 val
setsockopt_u32¶
Wrapper for setsockopt(2) where the kernel expects a C uint32_t.
Returns 0 on success, or a non-zero errno. Returns non-zero when the
socket is not open.
Parameters¶
Returns¶
- U32 val