Tahr.RPC.Server (tahr v0.1.0)

Copy Markdown View Source

ONC RPC v2 TCP listener.

Spawns a gen_tcp accept loop that creates one process per connection (via Task.Supervisor). Each connection process reads bytes off the socket, reassembles them with Tahr.RPC.RecordMarking, decodes the call envelope with Tahr.RPC.Message, dispatches via Tahr.RPC.Dispatcher using the configured program registry, and writes the encoded reply back.

Options

  • :port (default 2049) — TCP port to bind. Pass 0 to bind an ephemeral port (used by tests). The actual bound port is available via port/1.
  • :bind (default "0.0.0.0") — IP address to bind.
  • :programs (required) — see Tahr.RPC.Dispatcher.programs/0.
  • :portmap_mappings (default %{}) — {prog, vers, proto} → port map for the portmapper handler. The server will merge {100003, 3, 6} (NFSv3 over TCP) on top of this with the actual bound port.
  • :name (default __MODULE__) — registered name for the listener process.

Backpressure

One Erlang process per connection means each client's calls are naturally serialised by its mailbox. Slow handlers don't impact other clients.

Summary

Types

Per-connection state.

Functions

Returns a specification to start this module under a supervisor.

Return the actual TCP port the listener is bound on.

Start the listener under the given supervision tree.

Types

conn_state()

@type conn_state() :: %{
  socket: :gen_tcp.socket(),
  buffer: binary(),
  programs: Tahr.RPC.Dispatcher.programs(),
  portmap_mappings: %{
    required({non_neg_integer(), non_neg_integer(), non_neg_integer()}) =>
      non_neg_integer()
  }
}

Per-connection state.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

port(server \\ __MODULE__)

@spec port(GenServer.server()) :: non_neg_integer()

Return the actual TCP port the listener is bound on.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Start the listener under the given supervision tree.