pub struct RegisteredBufferPool { /* private fields */ }Expand description
A pre-registered buffer pool for io_uring operations.
Buffers are registered with the kernel once at creation time, eliminating the per-operation buffer mapping overhead that would otherwise occur.
§Example
use laminar_core::io_uring::RegisteredBufferPool;
let mut pool = RegisteredBufferPool::new(&mut ring, 64 * 1024, 256)?;
// Acquire a buffer
let (idx, buf) = pool.acquire()?;
buf[..5].copy_from_slice(b"hello");
// Use the buffer for I/O
pool.submit_write_fixed(fd, idx, 0, 5)?;
// After completion, release the buffer
pool.release(idx);Implementations§
Source§impl RegisteredBufferPool
impl RegisteredBufferPool
Sourcepub fn new(
ring: &mut IoUring,
buffer_size: usize,
buffer_count: usize,
) -> Result<Self, IoUringError>
pub fn new( ring: &mut IoUring, buffer_size: usize, buffer_count: usize, ) -> Result<Self, IoUringError>
Sourcepub fn acquire(&mut self) -> Result<(u16, &mut [u8]), IoUringError>
pub fn acquire(&mut self) -> Result<(u16, &mut [u8]), IoUringError>
Acquire a buffer from the pool.
Returns the buffer index and a mutable reference to the buffer.
§Errors
Returns an error if no buffers are available.
Sourcepub fn try_acquire(&mut self) -> Option<(u16, &mut [u8])>
pub fn try_acquire(&mut self) -> Option<(u16, &mut [u8])>
Try to acquire a buffer without blocking.
Returns None if no buffers are available.
Sourcepub fn release(&mut self, buf_index: u16)
pub fn release(&mut self, buf_index: u16)
Release a buffer back to the pool.
The buffer must not be in-flight (submitted to io_uring but not yet
completed). In debug builds, this is checked via assertion.
§Panics
Panics in debug builds if the buffer index is invalid or the buffer is still in-flight.
Sourcepub fn mark_in_flight(&mut self, buf_index: u16)
pub fn mark_in_flight(&mut self, buf_index: u16)
Mark a buffer as in-flight (submitted to io_uring).
Call this after submitting a read/write operation that uses this buffer.
Call Self::complete_in_flight when the CQE arrives.
Sourcepub fn complete_in_flight(&mut self, buf_index: u16)
pub fn complete_in_flight(&mut self, buf_index: u16)
Mark a buffer as no longer in-flight (CQE received).
Sourcepub fn submit_read_fixed(
&mut self,
ring: &mut IoUring,
fd: RawFd,
buf_index: u16,
offset: u64,
len: u32,
) -> Result<u64, IoUringError>
pub fn submit_read_fixed( &mut self, ring: &mut IoUring, fd: RawFd, buf_index: u16, offset: u64, len: u32, ) -> Result<u64, IoUringError>
Submit a read operation using a registered buffer.
The data will be read into the buffer at the given index.
§Arguments
ring- Theio_uringinstancefd- File descriptor to read frombuf_index- Index of the registered bufferoffset- File offset to read fromlen- Number of bytes to read
§Returns
The user_data value that will identify this operation in completions.
§Errors
Returns an error if the submission queue is full.
Sourcepub fn submit_write_fixed(
&mut self,
ring: &mut IoUring,
fd: RawFd,
buf_index: u16,
offset: u64,
len: u32,
) -> Result<u64, IoUringError>
pub fn submit_write_fixed( &mut self, ring: &mut IoUring, fd: RawFd, buf_index: u16, offset: u64, len: u32, ) -> Result<u64, IoUringError>
Submit a write operation using a registered buffer.
The data in the buffer at the given index will be written.
§Arguments
ring- Theio_uringinstancefd- File descriptor to write tobuf_index- Index of the registered bufferoffset- File offset to write tolen- Number of bytes to write
§Returns
The user_data value that will identify this operation in completions.
§Errors
Returns an error if the submission queue is full.
Sourcepub const fn buffer_size(&self) -> usize
pub const fn buffer_size(&self) -> usize
Get the size of each buffer.
Sourcepub const fn total_count(&self) -> usize
pub const fn total_count(&self) -> usize
Get the total number of buffers.
Sourcepub fn available_count(&self) -> usize
pub fn available_count(&self) -> usize
Get the number of available buffers.
Sourcepub const fn acquired_count(&self) -> usize
pub const fn acquired_count(&self) -> usize
Get the number of acquired buffers.
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Check if the pool is exhausted.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RegisteredBufferPool
impl RefUnwindSafe for RegisteredBufferPool
impl Send for RegisteredBufferPool
impl Sync for RegisteredBufferPool
impl Unpin for RegisteredBufferPool
impl UnsafeUnpin for RegisteredBufferPool
impl UnwindSafe for RegisteredBufferPool
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more