Struct shmem_ipc::sharedring::Receiver
source · pub struct Receiver<T>(_, _);
Implementations
sourceimpl<T: Copy + FromBytes> Receiver<T>
impl<T: Copy + FromBytes> Receiver<T>
sourcepub fn new(capacity: usize) -> Result<Self, Error>
pub fn new(capacity: usize) -> Result<Self, Error>
Sets up a new ringbuffer and returns the receiver half.
sourcepub fn with_hugetlb(capacity: usize, tlbsize: HugetlbSize) -> Result<Self, Error>
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
sourcepub fn open(
capacity: usize,
memfd: File,
empty_signal: File,
full_signal: File
) -> Result<Self, Error>
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.
sourcepub fn mlock(&mut self) -> Result<(), Error>
pub fn mlock(&mut self) -> Result<(), Error>
mlock the backing memory to avoid it being put into swap
sourcepub fn receiver_mut(&mut self) -> &mut Receiver<T>
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.
sourcepub fn empty_signal(&self) -> &File
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.
sourcepub fn full_signal(&self) -> &File
pub fn full_signal(&self) -> &File
The file descriptor written to when the sending side should wake up
sourcepub fn receive_raw<F: FnOnce(*const T, usize) -> usize>(
&mut self,
f: F
) -> Result<Status, Error>
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.
sourcepub unsafe fn receive_trusted<F: FnOnce(&[T]) -> usize>(
&mut self,
f: F
) -> Result<Status, Error>
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.
sourcepub fn block_until_readable(&mut self) -> Result<Status, Error>
pub fn block_until_readable(&mut self) -> Result<Status, Error>
For blocking scenarios, blocks until the channel is readable.