SmolNet.Socket (smolnet v0.7.1)

Copy Markdown View Source

A stable, lightweight identity for a socket owned by a SmolNet stack.

Socket values are not processes. Operations are serialized by the stack process identified in the :stack field. The native socket ID and generation together prevent delayed readiness from addressing a later socket.

Summary

Functions

Cancels the exact pending operation described by select_info.

Types

datagram()

@type datagram() :: %{
  source: sockaddr_in() | sockaddr_in6(),
  destination: sockaddr_in() | sockaddr_in6(),
  data: binary(),
  truncated: boolean()
}

ipv4_address()

@type ipv4_address() :: {0..255, 0..255, 0..255, 0..255}

ipv6_address()

@type ipv6_address() ::
  {0..65535, 0..65535, 0..65535, 0..65535, 0..65535, 0..65535, 0..65535,
   0..65535}

sockaddr_in6()

@type sockaddr_in6() :: %{
  :family => :inet6,
  :addr => ipv6_address(),
  :port => 0..65535,
  optional(:flowinfo) => 0,
  optional(:scope_id) => 0..4_294_967_295
}

sockaddr_in()

@type sockaddr_in() :: %{family: :inet, addr: ipv4_address(), port: 0..65535}

t()

@type t() :: %SmolNet.Socket{
  family: :inet | :inet6,
  generation: pos_integer(),
  id: pos_integer(),
  kind: :stream | :datagram,
  stack: pid()
}

Functions

cancel(socket, select_info)

@spec cancel(t(), :socket.select_info()) ::
  :ok | :already_sent | :not_found | {:error, :closed | :invalid_socket}

Cancels the exact pending operation described by select_info.

Returns :ok when the waiter was removed, :already_sent when its one-shot readiness notification won the race, or :not_found when the reference does not identify the pending operation.