Function copy_cqes [src]
Copies as many CQEs as are ready, and that can fit into the destination cqes slice.
If none are available, enters into the kernel to wait for at most wait_nr CQEs.
Returns the number of CQEs copied, advancing the CQ ring.
Provides all the wait/peek methods found in liburing, but with batching and a single method.
The rationale for copying CQEs rather than copying pointers is that pointers are 8 bytes
whereas CQEs are not much more at only 16 bytes, and this provides a safer faster interface.
Safer, because you no longer need to call cqe_seen(), avoiding idempotency bugs.
Faster, because we can now amortize the atomic store release to cq.head across the batch.
See https://github.com/axboe/liburing/issues/103#issuecomment-686665007.
Matches the implementation of io_uring_peek_batch_cqe() in liburing, but supports waiting.
Prototype
pub fn copy_cqes(self: *IoUring, cqes: []linux.io_uring_cqe, wait_nr: u32) !u32
Parameters
self: *IoUring
cqes: []linux.io_uring_cqe
wait_nr: u32
Source
pub fn copy_cqes(self: *IoUring, cqes: []linux.io_uring_cqe, wait_nr: u32) !u32 {
const count = self.copy_cqes_ready(cqes);
if (count > 0) return count;
if (self.cq_ring_needs_flush() or wait_nr > 0) {
_ = try self.enter(0, wait_nr, linux.IORING_ENTER_GETEVENTS);
return self.copy_cqes_ready(cqes);
}
return 0;
}