Skip to main content

kevy_uring/
completion.rs

1//! A reaped completion event.
2
3use crate::ffi::{IORING_CQE_BUFFER_SHIFT, IORING_CQE_F_BUFFER, IORING_CQE_F_MORE};
4
5/// One reaped completion (`struct io_uring_cqe`): the `user_data` you tagged
6/// the submission with, and `res` (bytes transferred / accepted fd when ≥ 0,
7/// else `-errno`).
8#[repr(C)]
9#[derive(Clone, Copy, Debug)]
10pub struct Completion {
11    /// The `user_data` tag the submission carried.
12    pub user_data: u64,
13    /// Result of the op: bytes transferred or accepted fd (≥ 0) or `-errno`.
14    pub res: i32,
15    /// io_uring `flags` (provided-buffer id + multishot armed bit).
16    pub flags: u32,
17}
18
19impl Completion {
20    /// The provided-buffer id the kernel filled, if this completion consumed
21    /// one (multishot/`recv` with buffer select). Recycle it via
22    /// [`ProvidedBufRing::recycle`](crate::ProvidedBufRing::recycle) once the
23    /// bytes are copied out.
24    pub fn buffer_id(&self) -> Option<u16> {
25        (self.flags & IORING_CQE_F_BUFFER != 0)
26            .then_some((self.flags >> IORING_CQE_BUFFER_SHIFT) as u16)
27    }
28
29    /// Whether the originating multishot SQE remains armed (more completions
30    /// to come). When `false`, the op terminated and must be re-submitted.
31    pub fn has_more(&self) -> bool {
32        self.flags & IORING_CQE_F_MORE != 0
33    }
34}