Struct Receiver

Source
pub struct Receiver<T>(/* private fields */);

Implementations§

Source§

impl<T: Copy + FromBytes> Receiver<T>

Source

pub fn new(capacity: usize) -> Result<Self, Error>

Sets up a new ringbuffer and returns the receiver half.

Source

pub fn with_hugetlb( capacity: usize, tlbsize: HugetlbSize, ) -> Result<Self, Error>

Create a new ringbuffer with hugetlb support and returns the receiver half. Supports linux version 4.16+ only

Source

pub fn open( capacity: usize, memfd: File, empty_signal: File, full_signal: File, ) -> Result<Self, Error>

Attaches to a ringbuffer set up by the sending side.

Source

pub fn mlock(&mut self) -> Result<(), Error>

mlock the backing memory to avoid it being put into swap

Source

pub fn receiver_mut(&mut self) -> &mut Receiver<T>

Low-level access to the ringbuffer.

Note that reading directly using these methods will not trigger a signal for the sending side to wake up.

Source

pub fn memfd(&self) -> &Memfd

The file descriptor for the shared memory area

Source

pub fn empty_signal(&self) -> &File

The file descriptor to register notification for in your favorite non-blocking framework (tokio, async-std etc).

It is written to by the sending side when the buffer is no longer empty.

Source

pub fn full_signal(&self) -> &File

The file descriptor written to when the sending side should wake up

Source

pub fn receive_raw<F: FnOnce(*const T, usize) -> usize>( &mut self, f: F, ) -> Result<Status, Error>

Receives data from the ringbuffer.

Because this is a ringbuffer between untrusted processes we can never create references to the data, so we have to resort to raw pointers. The closure receives a (ptr, count) pair which can be read from using e g std::ptr::read, and returns the number of items that can be dropped from the ringbuffer. If the buffer is empty, the closure is not called. If there is more data that could be read (e g in another part of the ringbuffer), that is indicated in the returned Status struct.

Source

pub unsafe fn receive_trusted<F: FnOnce(&[T]) -> usize>( &mut self, f: F, ) -> Result<Status, Error>

Receives data from the ringbuffer.

The closure receives a slice of data and returns the number of items that can be dropped from the ringbuffer. If the buffer is empty, the closure is not called. If there is more data that could be read (e g in another part of the ringbuffer), that is indicated in the returned Status struct.

§Safety

Caller must ensure that no one can read or write the data area, except for at most one Receiver (this one) and at most one Sender, both set up correctly.

Source

pub fn block_until_readable(&mut self) -> Result<Status, Error>

For blocking scenarios, blocks until the channel is readable.

Auto Trait Implementations§

§

impl<T> Freeze for Receiver<T>

§

impl<T> RefUnwindSafe for Receiver<T>
where T: RefUnwindSafe,

§

impl<T> Send for Receiver<T>

§

impl<T> Sync for Receiver<T>

§

impl<T> Unpin for Receiver<T>

§

impl<T> UnwindSafe for Receiver<T>
where T: RefUnwindSafe,

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>,

Source§

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>,

Source§

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.