# `MaeBPF.RingBuf`
[🔗](https://github.com/cocoa-xu/MaeBPF/blob/v0.1.0/maebpf/lib/maebpf/ring_buf.ex#L1)

Zero-polling `BPF_MAP_TYPE_RINGBUF` consumer backed by `ring_buffer__epoll_fd`
and BEAM `enif_select`.

Supports bounded list draining (`consume/2`) and single-allocation packed
binary draining (`consume_packed/2`) with zero-copy pure-Elixir decoders
(`decode_packed/1`, `fold_packed/3`).

# `close`

Stops `enif_select` registration and releases the underlying ring buffer.

# `consume`

Drains up to `:max_events` (default `512`) currently available samples from
the ring buffer without blocking.

Returns `{:ok, events, has_more}` where `has_more` is `true` when the event
bound was reached and callers should yield before draining further.

# `consume_packed`

Drains up to `:max_events` (default `1024`) or `:max_bytes` (default `262_144`)
samples into a single contiguous little-endian length-prefixed binary:

    <<len::little-unsigned-32, payload::binary-size(len), ...>>

Returns `{:ok, count, packed_binary, has_more}`.

# `decode_packed`

Decodes a packed ring buffer binary into a list of zero-copy sub-binaries.

# `fold_packed`

Folds over a packed ring buffer binary without allocating an intermediate list.

# `map_fd`

Returns the duplicated map file descriptor owned by this ring buffer handle.

# `open`

Opens a kernel ring buffer from an already-opened pinned map handle.

# `open`

Opens a kernel ring buffer map from a loaded eBPF object.

# `select`

Arms BEAM `enif_select` readiness notification on the ring buffer's epoll FD.

When kernel events arrive, the calling process receives
`{:select, ringbuf, ref, :ready_input}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
