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

View Source

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

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