A high perf generalized mem safe io_uring Reactor Core
- Linux: Full, zero-copy support via
io_uring. - Windows: Currently stubbed (IOCP loop awaiting implementation).
Below is a complete example of instantiating the reactor, registering decoupled memory, and executing a background file write.
use std::fs::File;
use std::sync::Arc;
use polyring::{Ring, ShutdownPolicy};
fn main() -> std::io::Result<()> {
let mut ring = Ring::new(128, 256)?;
let data = b"Hello, asynchronous world!".to_vec().into_boxed_slice();
let buffer_token = ring.buf_registry.as_mut().unwrap().register(data)?;
let file = Arc::new(File::create("output.txt")?);
let write_token = ring.write(file, buffer_token, 0)?;
let _submitted_count = ring.submit()?;
let completion = ring.wait()?;
match completion.status {
Ok(payload) => println!("Success! Transferred: {:?}", payload),
Err(e) => eprintln!("I/O Failure: {}", e),
}
ring.shutdown(ShutdownPolicy::DrainAll)?;
Ok(())
}Manages the memory you intend to share with the kernel.
register(box): Hands ownership to the registry, returns a safe token.reclaim(token): Takes ownership back to user space once the kernel is done.
read()/write(): Stage operations into the local queue.cancel(token): Stage anAsyncCancelsignal targeting a previously submitted operation.submit(): Transactionally flushes the staged queue to the kernel's Submission Queue (SQ).wait(): Blocks until a Completion Queue Event (CQE) is ready, seamlessly advancing the operation's internal state machine.