Skip to main content

IoUringState

Struct IoUringState 

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

Orchestrator for the io_uring ring.

Lifetime: owns an fd + three mmap’d regions (SQ ring, CQ ring, SQEs array). Drop closes + unmaps in reverse order.

Thread-safety: Send + Sync is safe because every public method takes &mut self OR uses atomic operations on the ring pointers (head/tail are AtomicU32 in the mmap’d memory). The &mut self receiver on get_sqe + commit_sqe prevents two producers from racing on the submission queue; CQE reaping via peek_cqe also takes &mut self for the same reason on the completion side.

Implementations§

Source§

impl IoUringState

Source

pub fn new(entries: u32) -> Result<Self, PipelineError>

Create an IoUringState with entries SQEs, SQPOLL enabled, and a 2-second kernel-thread idle timeout.

§Errors
Source

pub fn enter( &self, to_submit: u32, min_complete: u32, flags: u32, ) -> Result<i32, PipelineError>

Enter the ring to submit items or wait for completions.

§Errors

Returns PipelineError::IoUringSyscall if the syscall fails. Typical causes: EINTR (retry), EBUSY (wait and retry), ENXIO (kernel-side SQPOLL thread died).

Source

pub fn uses_sqpoll(&self) -> bool

True when this ring was created with kernel-side SQ polling.

Source

pub fn sq_needs_wakeup(&self) -> bool

True when the SQPOLL thread has slept and must be explicitly woken.

Source

pub fn wake_sqpoll(&self) -> Result<i32, PipelineError>

Wake a sleeping SQPOLL thread so already-published SQEs make progress.

Source

pub fn get_sqe(&mut self) -> Option<&mut io_uring_sqe>

Obtain a mutable reference to the next available SQE.

Source

pub fn commit_sqe(&mut self)

Commit the currently acquired SQE and advance the SQ tail.

Source

pub fn peek_cqe(&mut self) -> Option<&io_uring_cqe>

Read the next available CQE from the completion queue.

Source

pub fn register_buffers(&self, iovecs: &[Iovec]) -> Result<(), PipelineError>

Register a set of buffers with the kernel via IORING_REGISTER_BUFFERS, unlocking IORING_OP_READ_FIXED zero-validation reads. iovecs must outlive every SQE that references a buf_index into it; the kernel only reads iovecs during this registration call itself.

§Errors

Returns PipelineError::IoUringSyscall if io_uring_register fails - typical causes are EFAULT (bad pointer), ENOMEM, or EOPNOTSUPP (kernel < 5.1).

Source

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

Register fixed files via IORING_REGISTER_FILES. After registration, SQEs that set IOSQE_FIXED_FILE treat fd as the index into this table, skipping the per-SQE fd refcount bump.

§Errors

Same as IoUringState::register_buffers.

Source

pub fn advance_cq(&mut self)

Advance the CQ head, acknowledging completion.

Trait Implementations§

Source§

impl Drop for IoUringState

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for IoUringState

Source§

impl Sync for IoUringState

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more