Expand description
kernel_async_ring: the kernel async-I/O ring (io_uring on Linux,
IoRing on Windows, POSIX aio on FreeBSD / macOS) exposed as a
substrate ring primitive.
Both OSes ship the same architecture - a user->kernel SUBMISSION ring
and a kernel->user COMPLETION ring - which is exactly the substrate’s
SharedRing shape applied to the user/kernel boundary. This wraps that
kernel object behind one cross-platform surface; only the ring
syscalls are gated, the verb shape (prepare / submit / reap) and the
normalized Completion are shared:
- Linux (
#[cfg(target_os = "linux")]):io_uringvia the mainlineio-uringcrate (IoUring::new/opcode::Read/submit_and_wait/ completion iterator). - Windows (
#[cfg(windows)]):IoRingviawindows-sys(CreateIoRing/BuildIoRingReadFile/SubmitIoRing/PopIoRingCompletion), gated onQueryIoRingCapabilities+IsIoRingOpSupportedso an unsupported build degrades toErrrather than UB. - FreeBSD (
#[cfg(target_os = "freebsd")]): POSIXaiowith kqueue completion. Eachaio_readcarries anaio_sigeventset toSIGEV_KEVENTagainst the ring’s kqueue, so completion posts anEVFILT_AIOkevent (ident= the aiocb pointer,udata= the caller’s tag);submit_and_waitis akeventwait,reapcallsaio_return. There is no separate batched submit -aio_readissues each op immediately - but the prepare / wait / reap verb shape is identical. - macOS (
#[cfg(target_os = "macos")]): POSIXaiowithaio_suspendcompletion. Darwin has noSIGEV_KEVENTand itsEVFILT_AIOkqueue filter rejects registration, so completion is driven byaio_suspendover the in-flight set rather than akeventwait;aio_readstill does the real kernel async I/O andreapcallsaio_return. Same prepare / wait / reap verb shape.
The completion encodings differ - io_uring packs bytes-or--errno
into one i32; IoRing splits ResultCode (HRESULT) and
Information (bytes); aio reports via aio_error + aio_return - so
all three are normalized to a single Completion with an
io::Result<usize> byte count.
Structs§
- Completion
- One reaped completion: which submission it answers (
user_data, the tag the caller passed toprepare_read) and its result - the number of bytes transferred, or the error the kernel reported. - Kernel
Async Ring - A kernel async-I/O ring backed by an
io_uringinstance.
Functions§
- open_
for_ async_ read - Open a file for reading through the kernel async ring. On Windows the
handle must carry
FILE_FLAG_OVERLAPPEDforIoRing; on Linux and FreeBSD a plain read handle is fine. Keep the returnedFilealive while its reads are in flight.