Xirsys.Sockets.Transport.UDP (xturn_sockets v2.2.0)
View SourceUDP transport (:gen_udp).
listen/3 opens a client-facing socket. open_relay/2 opens a short-lived
relay socket (active-once, large buffers, ICMP error queue on Linux).
IPv6 sockets on Linux set ipv6_v6only.
Summary
Functions
Transfers UDP socket message delivery to pid (used for relay ingress).
Maps :udp / :udp_error messages. ICMP errors become {:icmp, info}.
Opens a relay UDP socket (active-once, 1 MiB buffers, ICMP errqueue on Linux).
Sets the don't-fragment bit. Returns {:error, :not_supported} when the OS
rejects both the inet option and the raw fallback.
Sets the IPv6 flow label on socket.
Sets IPv4 TTL or IPv6 hop limit from the socket's family.
Sets IPv4 TOS on socket.
Functions
Transfers UDP socket message delivery to pid (used for relay ingress).
Parameters
socket- open UDP socketpid- process that will receive{:udp, ...}/{:udp_passive, ...}
Maps :udp / :udp_error messages. ICMP errors become {:icmp, info}.
info is %{type, code, error_data, peer}. Integer error_data is passed
through; destination-unreachable / packet-too-big payloads may carry an MTU.
iex> alias Xirsys.Sockets.Transport.UDP
iex> UDP.handle_message({:udp, :port, {127, 0, 0, 1}, 3478, "hi"}, :sock)
{:data, "hi", {{127, 0, 0, 1}, 3478}}
iex> UDP.handle_message({:udp_error, :sock, {:icmp, 3, 4, 1280, {{8, 8, 8, 8}, 3478}}}, :sock)
{:icmp, %{type: 3, code: 4, error_data: 1280, peer: {{8, 8, 8, 8}, 3478}}}
iex> UDP.handle_message(:other, :sock)
:ignore
iex> UDP.framing()
:datagram
@spec open_relay( :inet.ip_address(), keyword() ) :: {:ok, term()} | {:error, term()}
Opens a relay UDP socket (active-once, 1 MiB buffers, ICMP errqueue on Linux).
Parameters
ip- bind addressopts- extra open options;:port(default0) is pulled out before merge
@spec set_dont_fragment(term()) :: :ok | {:error, :not_supported}
Sets the don't-fragment bit. Returns {:error, :not_supported} when the OS
rejects both the inet option and the raw fallback.
Parameters
socket- open UDP socket (IPv4 or IPv6)
@spec set_flow_label(term(), non_neg_integer()) :: :ok | {:error, term()}
Sets the IPv6 flow label on socket.
Parameters
socket- open IPv6 UDP socketlabel- 20-bit flow label
@spec set_hop_limit(term(), pos_integer()) :: :ok | {:error, term()}
Sets IPv4 TTL or IPv6 hop limit from the socket's family.
Parameters
socket- open UDP socketttl- hop limit / TTL
@spec set_tos(term(), non_neg_integer()) :: :ok | {:error, term()}
Sets IPv4 TOS on socket.
Parameters
socket- open UDP sockettos- type-of-service byte