partisan_peer_socket (partisan v6.0.0)

View Source

Wrapper that allows transparent usage of plain TCP or TLS socket for peer connections.

This module also implements the monotonic channel functionality.

Summary

Functions

Wraps a TCP socket with the appropriate information for transceiving on and controlling the socket later. If TLS/SSL is enabled, this performs the socket upgrade/negotiation before returning the wrapped socket.

Returns socket-level byte/packet counters, e.g. recv_oct, send_oct, send_pend. These come directly from the runtime (no counting done by Partisan) so they are cheap to poll periodically.

Same as getstat/1 but restricted to the counters in Items.

Returns the wrapped socket from within the connection.

Byte/packet counters and send-queue depth for telemetry, straight from getstat/2 (no counting done by Partisan). Returns #{} if the socket is unavailable, rather than failing the caller's tick.

Types

options/0

-type options() :: [gen_tcp:option()] | map().

reason/0

-type reason() :: closed | inet:posix().

t/0

-type t() ::
          #partisan_peer_socket{socket :: gen_tcp:socket() | ssl:sslsocket() | socket:socket(),
                                transport :: gen_tcp | ssl,
                                control :: inet | ssl,
                                monotonic :: boolean()}.

Functions

accept(TCPSocket)

-spec accept(gen_tcp:socket()) -> t().

Wraps a TCP socket with the appropriate information for transceiving on and controlling the socket later. If TLS/SSL is enabled, this performs the socket upgrade/negotiation before returning the wrapped socket.

close(Partisan_peer_socket)

-spec close(t()) -> ok.

See also: gen_tcp:close/1, ssl:close/1.

connect(Address, Port, Options)

-spec connect(inet:socket_address() | inet:hostname(), inet:port_number(), options()) ->
                 {ok, t()} | {error, inet:posix()}.

See also: gen_tcp:connect/3, ssl:connect/3.

connect(Address, Port, Options, Timeout)

-spec connect(inet:socket_address() | inet:hostname(), inet:port_number(), options(), timeout()) ->
                 {ok, t()} | {error, inet:posix()}.

connect(Address, Port, Options, Timeout, PartisanOptions)

-spec connect(inet:socket_address() | inet:hostname(),
              inet:port_number(),
              options(),
              timeout(),
              map() | list()) ->
                 {ok, t()} | {error, inet:posix()}.

getstat(Partisan_peer_socket)

-spec getstat(t()) -> {ok, [{atom(), integer()}]} | {error, inet:posix()}.

Returns socket-level byte/packet counters, e.g. recv_oct, send_oct, send_pend. These come directly from the runtime (no counting done by Partisan) so they are cheap to poll periodically.

See also: inet:getstat/1, ssl:getstat/1.

getstat(Partisan_peer_socket, Items)

-spec getstat(t(), Items :: [atom()]) -> {ok, [{atom(), integer()}]} | {error, inet:posix()}.

Same as getstat/1 but restricted to the counters in Items.

See also: inet:getstat/2, ssl:getstat/2.

recv(Conn, Length)

-spec recv(t(), integer()) -> {ok, iodata()} | {error, reason()}.

See also: gen_tcp:recv/2, ssl:recv/2.

recv(Partisan_peer_socket, Length, Timeout)

-spec recv(t(), integer(), timeout()) -> {ok, iodata()} | {error, reason()}.

See also: gen_tcp:recv/3, ssl:recv/3.

send(Partisan_peer_socket, Data)

-spec send(t(), iodata()) -> ok | {error, reason()}.

See also: gen_tcp:send/2, ssl:send/2.

setopts(Partisan_peer_socket, Options)

-spec setopts(t(), options()) -> ok | {error, inet:posix()}.

See also: inet:setopts/2, ssl:setopts/2.

socket(Conn)

-spec socket(t()) -> gen_tcp:socket() | ssl:sslsocket().

Returns the wrapped socket from within the connection.

telemetry_stats(Partisan_peer_socket)

-spec telemetry_stats(t() | undefined) -> map().

Byte/packet counters and send-queue depth for telemetry, straight from getstat/2 (no counting done by Partisan). Returns #{} if the socket is unavailable, rather than failing the caller's tick.