Skip to content

UDPSocket

[Source]

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


Constructors

create

[Source]

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

Returns


Public Behaviours

write_to

[Source]

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.

be write_to(
  data: ByteSeq,
  to: NetAddress val)

Parameters


dispose

[Source]

be dispose()

Public Functions

send_to

[Source]

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.

fun ref send_to(
  data: ByteSeq,
  to: NetAddress box)
: SendToResult

Parameters

Returns


close

[Source]

Close the socket. No graceful shutdown: the fd is closed immediately.

fun ref close()
: None val

Returns


local_address

[Source]

Return the local IP address the socket is bound to.

fun ref local_address()
: NetAddress val

Returns


is_open

[Source]

True when the socket is bound and has not been closed.

fun box is_open()
: Bool val

Returns


is_closed

[Source]

True when the socket has been closed.

fun box is_closed()
: Bool val

Returns


get_so_rcvbuf

[Source]

Get the OS receive buffer size. Returns (errno, value).

fun box get_so_rcvbuf()
: (U32 val , U32 val)

Returns


set_so_rcvbuf

[Source]

Set the OS receive buffer size. Returns 0 on success, or errno.

fun box set_so_rcvbuf(
  bufsize: U32 val)
: U32 val

Parameters

  • bufsize: U32 val

Returns


get_so_sndbuf

[Source]

Get the OS send buffer size. Returns (errno, value).

fun box get_so_sndbuf()
: (U32 val , U32 val)

Returns


set_so_sndbuf

[Source]

Set the OS send buffer size. Returns 0 on success, or errno.

fun box set_so_sndbuf(
  bufsize: U32 val)
: U32 val

Parameters

  • bufsize: U32 val

Returns


getsockopt_u32

[Source]

Get a socket option as a U32. Returns (errno, value).

fun box getsockopt_u32(
  level: I32 val,
  option_name: I32 val)
: (U32 val , U32 val)

Parameters

  • level: I32 val
  • option_name: I32 val

Returns


setsockopt_u32

[Source]

Set a socket option as a U32. Returns 0 on success, or errno.

fun box setsockopt_u32(
  level: I32 val,
  option_name: I32 val,
  option: U32 val)
: U32 val

Parameters

  • level: I32 val
  • option_name: I32 val
  • option: U32 val

Returns