Tortoise311.Transport behaviour (tortoise311 v0.12.1)

View Source

Abstraction for working with network connections; this is done to normalize the :ssl and :gen_tcp modules, so they get a similar interface.

This work has been heavily inspired by the Ranch project by NineNines.

Summary

Functions

Create a new Transport specification used by the Connection process to log on to the MQTT server. This allow us to filter the options passed to the connection type, and guide the user to connect to the individual transport type.

Types

opts()

@type opts() :: any()

socket()

@type socket() :: any()

stats()

@type stats() :: any()

t()

@opaque t()

Callbacks

accept(socket, timeout)

@callback accept(socket(), timeout()) ::
  {:ok, socket()} | {:error, :closed | :timeout | atom()}

accept_ack(socket, timeout)

@callback accept_ack(socket(), timeout()) :: :ok

close(socket)

@callback close(socket()) :: :ok

connect(charlist, port_number, opts, timeout)

@callback connect(charlist(), :inet.port_number(), opts(), timeout()) ::
  {:ok, socket()} | {:error, atom()}

controlling_process(socket, pid)

@callback controlling_process(socket(), pid()) ::
  :ok | {:error, :closed | :now_owner | atom()}

getopts(socket, list)

@callback getopts(socket(), [atom()]) :: {:ok, opts()} | {:error, atom()}

getstat(socket)

@callback getstat(socket()) :: {:ok, stats()} | {:error, atom()}

getstat(socket, list)

@callback getstat(socket(), [atom()]) :: {:ok, stats()} | {:error, atom()}

listen(opts)

@callback listen(opts()) :: {:ok, socket()} | {:error, atom()}

new(opts)

@callback new(opts()) :: t()

peername(socket)

@callback peername(socket()) ::
  {:ok, {:inet.ip_address(), :inet.port_number()}} | {:error, atom()}

recv(socket, non_neg_integer, timeout)

@callback recv(socket(), non_neg_integer(), timeout()) ::
  {:ok, any()} | {:error, :closed | :timeout | atom()}

send(socket, iodata)

@callback send(socket(), iodata()) :: :ok | {:error, atom()}

setopts(socket, opts)

@callback setopts(socket(), opts()) :: :ok | {:error, atom()}

shutdown(socket, arg2)

@callback shutdown(socket(), :read | :write | :read_write) :: :ok | {:error, atom()}

sockname(socket)

@callback sockname(socket()) ::
  {:ok, {:inet.ip_address(), :inet.port_number()}} | {:error, atom()}

Functions

new(arg)

@spec new({atom(), [term()]}) :: t()

Create a new Transport specification used by the Connection process to log on to the MQTT server. This allow us to filter the options passed to the connection type, and guide the user to connect to the individual transport type.