IPv6 TCP callback and shared adapter for Erlang :gen_tcp and :inet.
Select this callback with the :tcp_module option and pass the target stack
with the :smolnet_stack option. Each returned OTP socket is backed by one
temporary :gen_statem child of that stack's inet supervisor.
This module is the IPv6 callback and shared socket implementation. Use
SmolNet.Inet.Tcp as the callback for IPv4. File descriptors and
packet modes other than raw, line, 1, 2, and 4 fail explicitly.
Either module can also be :ssl's transport, as its cb_info:
{SmolNet.Inet6.Tcp, :tcp, :tcp_closed, :tcp_error}, or SmolNet.Inet.Tcp
for IPv4, with :smolnet_stack among the socket options. See the
:gen_tcp guide.
Summary
Functions
Cancels a monitor that the calling process started with monitor/1;
:inet.cancel_monitor/1 calls this for a SmolNet socket's monitor.
Starts a monitor of socket for the calling process; :inet.monitor/1
calls this for a SmolNet socket.
Returns the local port of socket, as :inet.port/1 does.
Types
@type socket_term() :: {:"$inet", SmolNet.Inet.Tcp | SmolNet.Inet6.Tcp, pid()}
Functions
@spec accept(socket_term()) :: {:ok, socket_term()} | {:error, atom()}
@spec accept(socket_term(), timeout()) :: {:ok, socket_term()} | {:error, atom()}
Cancels a monitor that the calling process started with monitor/1;
:inet.cancel_monitor/1 calls this for a SmolNet socket's monitor.
Returns true if the monitor was removed, in which case no DOWN message
for it arrives, or false if it was not found, typically because it has
already triggered and its DOWN message is in the caller's mailbox.
@spec child_spec(map()) :: Supervisor.child_spec()
@spec close(socket_term()) :: :ok
@spec connect(:inet.ip6_address(), :inet.port_number(), list()) :: {:ok, socket_term()} | {:error, atom()}
@spec connect(map(), list(), timeout()) :: {:ok, socket_term()} | {:error, atom()}
@spec controlling_process(socket_term(), pid()) :: :ok | {:error, atom()}
@spec family() :: :inet6
@spec getaddr(term()) :: {:ok, :inet.ip6_address()} | {:error, atom()}
@spec getaddr(term(), term()) :: {:ok, :inet.ip6_address()} | {:error, atom()}
@spec getaddrs(term()) :: {:ok, [:inet.ip6_address()]} | {:error, atom()}
@spec getaddrs(term(), term()) :: {:ok, [:inet.ip6_address()]} | {:error, atom()}
@spec getopts(socket_term(), list()) :: {:ok, list()} | {:error, atom()}
@spec getserv(term()) :: {:ok, :inet.port_number()} | {:error, atom()}
@spec getstat(socket_term(), list()) :: {:ok, list()} | {:error, atom()}
@spec info(socket_term()) :: map() | {:error, atom()}
@spec listen(:inet.port_number(), list()) :: {:ok, socket_term()} | {:error, atom()}
@spec monitor(socket_term()) :: reference()
Starts a monitor of socket for the calling process; :inet.monitor/1
calls this for a SmolNet socket.
When the socket closes, the caller gets
{:DOWN, ref, :socket, socket, :closed}, as for an OTP socket-backed
:gen_tcp socket, or {:DOWN, ref, :socket, socket, :nosock} at once if
socket was already closed. Any process may monitor a socket, and each
call creates a separate monitor. See cancel_monitor/1.
A SmolNet socket closes when close/1 is called, when its owner exits,
when a send timeout closes it (send_timeout_close), on a connection
error, or when its stack stops. A peer's FIN alone does not close it,
since the socket can still send.
@spec parse_address(charlist()) :: {:ok, :inet.ip6_address()} | {:error, atom()}
@spec peername(socket_term()) :: {:ok, {:inet.ip6_address(), :inet.port_number()}} | {:error, atom()}
@spec port(socket_term()) :: {:ok, :inet.port_number()} | {:error, atom()}
Returns the local port of socket, as :inet.port/1 does.
:ssl calls this on a transport given through cb_info.
@spec recv(socket_term(), non_neg_integer()) :: {:ok, term()} | {:error, atom()}
@spec recv(socket_term(), non_neg_integer(), timeout()) :: {:ok, term()} | {:error, atom()}
@spec send(socket_term(), iodata()) :: :ok | {:error, term()}
@spec send(socket_term(), iodata(), list()) :: :ok | {:error, term()}
@spec setopts(socket_term(), list()) :: :ok | {:error, atom()}
@spec shutdown(socket_term(), :read | :write | :read_write) :: :ok | {:error, atom()}
@spec socket_to_list(socket_term()) :: charlist()
@spec sockname(socket_term()) :: {:ok, {:inet.ip6_address(), :inet.port_number()}} | {:error, atom()}
@spec start_link(map()) :: :gen_statem.start_ret()
@spec unrecv(socket_term(), iodata()) :: :ok | {:error, atom()}