Xirsys.Sockets.Engine (xturn_sockets v2.2.0)

View Source

Drain loop: pop every whole packet from a tier, dispatch the handler, repeat.

Connection and DatagramServer call push_and_drain/9 after each read. drain/8 is used for timer ticks (reorder timeouts) without a new chunk.

Summary

Types

Result of a drain pass: updated accumulators, handler states, async tier pids, and :ok or :close.

Types

drain_result()

@type drain_result() :: {map(), map(), map(), :ok | :close}

Result of a drain pass: updated accumulators, handler states, async tier pids, and :ok or :close.

Functions

drain(pipeline, tier_key, conn, accs, states, tier_sessions, transport_mod, owner_pid)

Pops whole packets from tier_key until the accumulator returns {:more, _}.

Handler {:reply, _, _} is sent on conn.socket. {:descend, next, payload, _} pushes payload into next. {:close, _} stops the connection after this pass. Framing errors emit :frame_error and continue.

Parameters

  • pipeline - compiled pipeline
  • tier_key - tier to drain (:root, ...)
  • conn - connection context used for replies
  • accs - map of tier name to accumulator state
  • states - map of tier name to handler state
  • tier_sessions - map of async tier name to session pid
  • transport_mod - Xirsys.Sockets.Transport implementation
  • owner_pid - connection or datagram-server process

push_and_drain(pipeline, chunk, meta, conn, accs, states, tier_sessions, transport_mod, owner_pid)

@spec push_and_drain(
  Xirsys.Sockets.Pipeline.t(),
  binary(),
  map(),
  Xirsys.Sockets.Conn.t(),
  map(),
  map(),
  map(),
  module(),
  pid()
) :: drain_result()

Pushes chunk into :root, then drains from :root.

Unthrottled: this path carries media as well as control traffic. Apply Config.check_rate_limit/1 in the handler for the message classes that need a budget.

Parameters

  • pipeline - compiled pipeline
  • chunk - inbound bytes from handle_message/2
  • meta - packet metadata (:from, :received_at, ...)
  • conn - connection context
  • accs / states / tier_sessions - session maps
  • transport_mod - transport used for {:reply, _, _}
  • owner_pid - owning process