pub struct UserRingBuffer { /* private fields */ }
Expand description
Represents a user ring buffer. This is a special kind of map that is used to transfer data between user space and kernel space.
Implementations§
Source§impl UserRingBuffer
impl UserRingBuffer
Sourcepub fn new(map: &dyn MapCore) -> Result<Self>
pub fn new(map: &dyn MapCore) -> Result<Self>
Create a new user ring buffer from a map.
§Errors
- If the map is not a user ring buffer.
- If the underlying libbpf function fails.
Sourcepub fn reserve(&self, size: usize) -> Result<UserRingBufferSample<'_>>
pub fn reserve(&self, size: usize) -> Result<UserRingBufferSample<'_>>
Reserve a sample in the user ring buffer.
Returns a UserRingBufferSample
that contains a mutable reference to sample that can be written to.
The sample must be submitted via UserRingBuffer::submit
before it is
dropped.
§Parameters
size
- The size of the sample in bytes.
This function is not thread-safe. It is necessary to synchronize amongst multiple producers when invoking this function.
Sourcepub fn submit(&self, sample: UserRingBufferSample<'_>) -> Result<()>
pub fn submit(&self, sample: UserRingBufferSample<'_>) -> Result<()>
Submit a sample to the user ring buffer.
This function takes ownership of the sample and submits it to the ring buffer. After submission, the consumer will be able to read the sample from the ring buffer.
This function is thread-safe. It is not necessary to synchronize amongst multiple producers when invoking this function.
Trait Implementations§
Source§impl AsRawLibbpf for UserRingBuffer
impl AsRawLibbpf for UserRingBuffer
Source§fn as_libbpf_object(&self) -> NonNull<Self::LibbpfType>
fn as_libbpf_object(&self) -> NonNull<Self::LibbpfType>
Retrieve the underlying libbpf_sys::user_ring_buffer
.
Source§type LibbpfType = user_ring_buffer
type LibbpfType = user_ring_buffer
libbpf
type.