Skip to main content

LioUring

Struct LioUring 

Source
pub struct LioUring { /* private fields */ }
Expand description

A Linux io_uring instance for high-performance async I/O.

This struct provides access to both submission and completion operations on a single io_uring instance.

Implementations§

Source§

impl LioUring

Source

pub fn new(capacity: u32) -> Result<Self>

Create a new io_uring instance with the specified capacity.

The capacity determines the size of the submission queue. The kernel may adjust this value.

§Errors

Returns an error if io_uring initialization fails (e.g., insufficient permissions, kernel doesn’t support io_uring, or out of resources).

Source

pub fn with_params(params: Params) -> Result<Self>

Create a new io_uring instance with custom parameters.

§Errors

Returns an error if io_uring initialization fails.

Source

pub unsafe fn push(&mut self, entry: Entry, user_data: u64) -> Result<()>

Push an operation to the submission queue.

§Safety

Caller guarantees that the Entry has valid data and that any pointers within the operation point to valid data that will remain valid until the operation completes.

§Errors

Returns an error if the submission queue is full. Call submit() to drain the queue and try again.

Source

pub unsafe fn push_with_flags( &mut self, entry: Entry, user_data: u64, flags: SqeFlags, ) -> Result<()>

Push an operation to the submission queue with custom flags.

§Safety

Same requirements as push().

§Errors

Returns an error if the submission queue is full.

Source

pub fn submit(&mut self) -> Result<usize>

Submit queued operations to the kernel.

When SQPOLL is enabled, this avoids the syscall if the kernel thread is already running. Only enters the kernel if needed to wake the thread.

Returns the number of operations submitted.

§Errors

Returns an error if submission fails.

Source

pub fn is_sqpoll(&self) -> bool

Check if SQPOLL mode is enabled.

Source

pub fn sq_space_left(&self) -> usize

Get the number of free slots in the submission queue.

Source

pub fn wait(&mut self) -> Result<Completion>

Wait for and retrieve the next completion.

This blocks until at least one completion is available.

§Errors

Returns an error if waiting fails.

Source

pub fn wait_timeout(&mut self, timeout: Duration) -> Result<Option<Completion>>

Wait for and retrieve the next completion with a timeout.

Returns Ok(None) if the timeout expires with no completions.

§Errors

Returns an error if waiting fails (other than timeout).

Source

pub fn try_wait(&mut self) -> Result<Option<Completion>>

Try to retrieve the next completion without blocking.

Returns None if no completions are available.

§Errors

Returns an error if peeking fails (not including “no data available”).

Source

pub fn peek(&self) -> Result<Option<Completion>>

Peek at the next completion without removing it from the queue.

Returns None if no completions are available.

Source

pub fn cq_ready(&self) -> usize

Get the number of available completions ready to be consumed.

Source

pub unsafe fn register_buffers(&mut self, buffers: &[IoSlice<'_>]) -> Result<()>

Register fixed buffers for zero-copy I/O.

Pre-registers buffers with the kernel to enable zero-copy operations. Registered buffers can be used with ReadFixed and WriteFixed operations.

§Safety

The buffers must remain valid and not be modified or moved until they are unregistered or the io_uring instance is dropped.

§Errors

Returns an error if registration fails (e.g., insufficient resources).

Source

pub fn unregister_buffers(&mut self) -> Result<()>

Unregister previously registered buffers.

Source

pub fn register_files(&mut self, fds: &[i32]) -> Result<()>

Register fixed file descriptors.

Pre-registers file descriptors with the kernel. Registered files can be referenced by index instead of fd, avoiding fd lookup overhead.

§Errors

Returns an error if registration fails.

Source

pub fn register_files_update(&mut self, offset: u32, fds: &[i32]) -> Result<()>

Update registered files at specific indices.

Replace file descriptors at the given indices. Use -1 to remove a file.

Source

pub fn unregister_files(&mut self) -> Result<()>

Unregister all previously registered files.

Trait Implementations§

Source§

impl Drop for LioUring

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

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.