Struct libbpf_rs::UserRingBuffer

source ·
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

source

pub fn new(map: &MapHandle) -> 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.
source

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.

source

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

source§

fn as_libbpf_object(&self) -> NonNull<Self::LibbpfType>

Retrieve the underlying libbpf_sys::user_ring_buffer.

§

type LibbpfType = user_ring_buffer

The underlying libbpf type.
source§

impl Debug for UserRingBuffer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for UserRingBuffer

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.