Xirsys.Sockets.Pipeline (xturn_sockets v2.2.0)
View SourceDeclarative multi-tier pipeline specification.
use Xirsys.Sockets.Pipeline
tier :root,
accumulator: {Xirsys.Sockets.Accumulator.LengthPrefixed, header_size: 2},
handler: MyApp.Handlers.Root
tier :inner,
accumulator: Xirsys.Sockets.Accumulator.Raw,
handler: MyApp.Handlers.Inner,
dispatch: :pool,
pool_size: 8Every pipeline must declare :root. Duplicate tier names fail at compile time.
Acceptor / DatagramServer also accept the legacy {accumulator, handler}
pair, which resolve/1 turns into a single-tier pipeline.
Summary
Functions
Imports tier/2 and compiles __tiers__/0 / __tier_spec__/1.
Builds fresh root-tier session maps for a single datagram (stateless UDP).
Initializes root-tier accumulator and handler state for a stream connection.
Returns true when the pipeline declares more than the mandatory :root tier.
Resolves a compiled pipeline module or {accumulator, handler} sugar
into a runtime %Pipeline{}.
Declares one named tier on the using module.
Returns the %Pipeline.Tier{} for key.
Types
@type t() :: %Xirsys.Sockets.Pipeline{ tiers: %{required(atom()) => Xirsys.Sockets.Pipeline.Tier.t()} }
Compiled pipeline: a map of tier name to Pipeline.Tier.
Functions
Imports tier/2 and compiles __tiers__/0 / __tier_spec__/1.
Parameters
_opts- unused; reserved for futureuseoptions
Builds fresh root-tier session maps for a single datagram (stateless UDP).
Parameters
pipeline- struct fromresolve/1opts-:handler_statestored under:rootiex> p = Xirsys.Sockets.Pipeline.resolve({Xirsys.Sockets.Accumulator.Raw, :handler}) iex> {accs, states} = Xirsys.Sockets.Pipeline.fresh_session(p, handler_state: :idle) iex> Map.keys(accs) [:root] iex> states %{root: :idle}
@spec init_session(t(), Xirsys.Sockets.Conn.t(), keyword()) :: {map(), map()}
Initializes root-tier accumulator and handler state for a stream connection.
Calls handle_connect/1 when the root handler exports it.
Parameters
pipeline- struct fromresolve/1conn- new connection contextopts-:handler_stateused whenhandle_connect/1is absent
Returns true when the pipeline declares more than the mandatory :root tier.
Parameters
pipeline- struct fromresolve/1
@spec resolve(module() | {Xirsys.Sockets.Spec.spec(), module()}) :: t()
Resolves a compiled pipeline module or {accumulator, handler} sugar
into a runtime %Pipeline{}.
Parameters
pipeline- a module thatuses this one, or{accumulator_spec, handler_mod}iex> p = Xirsys.Sockets.Pipeline.resolve({Xirsys.Sockets.Accumulator.Raw, :handler}) iex> Xirsys.Sockets.Pipeline.multi_tier?(p) false iex> spec = Xirsys.Sockets.Pipeline.tier_spec(p, :root) iex> spec.accumulator Xirsys.Sockets.Accumulator.Raw iex> spec.handler :handler iex> spec.dispatch :inline
Declares one named tier on the using module.
Parameters
name- atom key (:rootis required on every pipeline)opts-:accumulatorand:handler(required); optional:dispatch(:inline|:task|:pool),:pool_size,:task_supervisor,:pool_supervisor
@spec tier_spec(t(), atom()) :: Xirsys.Sockets.Pipeline.Tier.t()
Returns the %Pipeline.Tier{} for key.
Raises if key was not declared.
Parameters
pipeline- struct fromresolve/1key- tier name (:root, ...)