diff --git a/src/cqe.rs b/src/cqe.rs index b6ffaab..40d96e6 100644 --- a/src/cqe.rs +++ b/src/cqe.rs @@ -54,6 +54,16 @@ impl<'ring> CompletionQueue<'ring> { Ok(CompletionQueueEvent::new(self.ring, &mut *cqe.assume_init())) } } + + pub fn num_cqes_ready(&self) -> u32 { + unsafe { + uring_sys::io_uring_cq_ready(self.ring.as_ptr()) + } + } + + pub fn has_ready_cqes(&self) -> bool { + self.num_cqes_ready() > 0 + } } unsafe impl<'ring> Send for CompletionQueue<'ring> { } diff --git a/src/lib.rs b/src/lib.rs index 24b31c6..5d5ffc2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -217,6 +217,14 @@ impl IoUring { self.sq().submit_and_wait_with_timeout(wait_for, duration) } + pub fn sq_space_left(&self) -> u32 { + SubmissionQueue::new(&self).space_left() + } + + pub fn sq_has_space(&self) -> bool { + SubmissionQueue::new(&self).has_space() + } + pub fn peek_for_cqe(&mut self) -> Option> { unsafe { let mut cqe = MaybeUninit::uninit(); @@ -288,6 +296,14 @@ impl IoUring { pub fn raw_mut(&mut self) -> &mut uring_sys::io_uring { &mut self.ring } + + pub fn num_cqes_ready(&self) -> u32 { + CompletionQueue::new(&self).num_cqes_ready() + } + + pub fn has_ready_cqes(&self) -> bool { + CompletionQueue::new(&self).has_ready_cqes() + } } impl Drop for IoUring { diff --git a/src/sqe.rs b/src/sqe.rs index 1f53267..17d2e3d 100644 --- a/src/sqe.rs +++ b/src/sqe.rs @@ -89,6 +89,16 @@ impl<'ring> SubmissionQueue<'ring> { } } + pub fn space_left(&self) -> u32 { + unsafe { + uring_sys::io_uring_sq_space_left(self.ring.as_ptr()) + } + } + + pub fn has_space(&self) -> bool { + self.space_left() > 0 + } + /// Submit all events in the queue. Returns the number of submitted events. /// /// If this function encounters any IO errors an [`io::Error`](std::io::Result) variant is returned.