Xirsys.Sockets.Accumulator.Raw (xturn_sockets v2.2.1)

View Source

No framing: each push/3 is one immediately poppable packet.

What problem this solves

Datagram transports (UDP, DTLS) and inner tiers that already receive whole payloads need no length header parsing. Each read or descend push becomes one handler packet.

RFCs

  • RFC 8489 (STUN over UDP; one datagram per message)
  • RFC 9147 (DTLS datagram payloads)

Options

  • :max_size - maximum queued whole packets (default: 1024)

Overflow drops the oldest packet and surfaces :buffer_overflow on the next pop/1, then draining continues.

Summary

Functions

Builds an empty packet queue.

Dequeues one packet, reports overflow, or returns {:more, acc} when empty.

Enqueues chunk as one packet. Drops the oldest entry when over :max_size.

Functions

init(opts)

Builds an empty packet queue.

Parameters

  • opts - :max_size (default 1024)

    iex> acc = Xirsys.Sockets.Accumulator.Raw.init([]) iex> acc = Xirsys.Sockets.Accumulator.Raw.push(acc, "hello", %{n: 1}) iex> {:ok, "hello", %{n: 1}, acc} = Xirsys.Sockets.Accumulator.Raw.pop(acc) iex> elem(Xirsys.Sockets.Accumulator.Raw.pop(acc), 0) :more

pop(acc)

Dequeues one packet, reports overflow, or returns {:more, acc} when empty.

Parameters

push(acc, chunk, meta)

Enqueues chunk as one packet. Drops the oldest entry when over :max_size.

Parameters

  • acc - state from init/1
  • chunk - the whole packet
  • meta - metadata returned with this packet from pop/1