pub struct IoUring { /* private fields */ }Expand description
A Linux io_uring instance: one submission ring + one completion ring.
Implementations§
Source§impl IoUring
impl IoUring
Sourcepub fn new(entries: u32) -> Result<IoUring>
pub fn new(entries: u32) -> Result<IoUring>
Create a ring sized for at least entries in-flight submissions.
Sourcepub unsafe fn prep_read(
&mut self,
fd: i32,
buf: *mut u8,
len: u32,
user_data: u64,
) -> bool
pub unsafe fn prep_read( &mut self, fd: i32, buf: *mut u8, len: u32, user_data: u64, ) -> bool
Queue a read(fd) of len bytes into buf, tagged with user_data.
Returns false if the SQ is full.
§Safety
buf must point to len writable bytes and stay valid until the matching
completion is reaped.
Sourcepub unsafe fn prep_write(
&mut self,
fd: i32,
buf: *const u8,
len: u32,
user_data: u64,
) -> bool
pub unsafe fn prep_write( &mut self, fd: i32, buf: *const u8, len: u32, user_data: u64, ) -> bool
Queue a write(fd) of len bytes from buf, tagged with user_data.
Returns false if the SQ is full.
§Safety
buf must point to len readable bytes and stay valid until the matching
completion is reaped.
Sourcepub fn prep_recv_multishot(
&mut self,
fd: i32,
bgid: u16,
user_data: u64,
) -> bool
pub fn prep_recv_multishot( &mut self, fd: i32, bgid: u16, user_data: u64, ) -> bool
Queue a multishot recv(fd) that draws its destination buffer from
the provided-buffer group bgid (see IoUring::register_buf_ring): one
SQE re-fires a completion per arrival, the kernel picking + reporting a
buffer id each time, until it terminates (error / ENOBUFS, signalled by
Completion::has_more returning false). No per-recv SQE, no read
buffer to keep alive. Returns false if the SQ is full.
Sourcepub fn prep_accept(&mut self, listen_fd: i32, user_data: u64) -> bool
pub fn prep_accept(&mut self, listen_fd: i32, user_data: u64) -> bool
Queue an accept on listen_fd; the accepted fd arrives as the
completion’s res (already O_NONBLOCK | O_CLOEXEC). Returns false if
the SQ is full.
Sourcepub fn prep_nop(&mut self, user_data: u64) -> bool
pub fn prep_nop(&mut self, user_data: u64) -> bool
Queue a no-op tagged with user_data (used to prove the round-trip).
Returns false if the SQ is full.
Sourcepub fn submit_and_wait(&mut self, wait_nr: u32) -> Result<u32>
pub fn submit_and_wait(&mut self, wait_nr: u32) -> Result<u32>
Publish queued submissions and enter the kernel, optionally waiting for
wait_nr completions. Returns the number of SQEs consumed.
Sourcepub fn for_each_completion<F: FnMut(Completion)>(&mut self, f: F) -> u32
pub fn for_each_completion<F: FnMut(Completion)>(&mut self, f: F) -> u32
Reap every available completion, calling f for each; returns the count.
Sourcepub fn register_buf_ring(
&self,
entries: u16,
buf_size: u32,
bgid: u16,
) -> Result<ProvidedBufRing>
pub fn register_buf_ring( &self, entries: u16, buf_size: u32, bgid: u16, ) -> Result<ProvidedBufRing>
Register a provided-buffer ring of entries (power of two) buffers of
buf_size bytes each under group id bgid, for multishot
prep_recv_multishot. The kernel draws a
buffer per arrival and reports its id; the application recycles it via
ProvidedBufRing::recycle. The registration is auto-released when the
ring fd closes; the returned handle also unregisters + unmaps on drop.