ringbuf

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 15 Imported by: 266 modules, 225 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ringbuf allows interacting with the BPF ring buffer.

BPF allows submitting custom events to a BPF ring buffer map set up by userspace. This is very useful to push things like packet samples from BPF to a daemon running in user space.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosed = os.ErrClosed
)
View Source
var ErrFlushed = epoll.ErrFlushed

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader allows reading bpf_ringbuf_output from user space.

func NewReader

func NewReader(ringbufMap *ebpf.Map) (*Reader, error)

NewReader creates a new BPF ringbuf reader.

func (*Reader) AvailableBytes added in v0.17.0

func (r *Reader) AvailableBytes() int

AvailableBytes returns the amount of data available to read in the ring buffer in bytes.

func (*Reader) BufferSize added in v0.12.3

func (r *Reader) BufferSize() int

BufferSize returns the size in bytes of the ring buffer

func (*Reader) Close

func (r *Reader) Close() error

Close frees resources used by the reader.

It interrupts calls to Read.

func (*Reader) Flush added in v0.16.0

func (r *Reader) Flush() error

Flush unblocks Read/ReadInto and successive Read/ReadInto calls will return pending samples at this point, until you receive a ErrFlushed error.

func (*Reader) Read

func (r *Reader) Read() (Record, error)

Read the next record from the BPF ringbuf.

Calling [Close] interrupts the method with os.ErrClosed. Calling [Flush] makes it return all records currently in the ring buffer, followed by ErrFlushed.

Returns os.ErrDeadlineExceeded if a deadline was set and after all records have been read from the ring.

See [ReadInto] for a more efficient version of this method.

func (*Reader) ReadInto added in v0.9.0

func (r *Reader) ReadInto(rec *Record) error

ReadInto is like Read except that it allows reusing Record and associated buffers.

func (*Reader) SetDeadline added in v0.9.2

func (r *Reader) SetDeadline(t time.Time)

SetDeadline controls how long Read and ReadInto will block waiting for samples.

Passing a zero time.Time will remove the deadline.

type Record

type Record struct {
	RawSample []byte

	// The minimum number of bytes remaining in the ring buffer after this Record has been read.
	Remaining int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL