[−][src]Crate libaiofut
Straightforward Linux AIO using Futures/async/await.
Example
Use libaiofut to schedule writes to a file:
use futures::{executor::LocalPool, future::FutureExt, task::LocalSpawnExt}; use libaiofut::{AIOManager, new_batch_scheduler}; use std::os::unix::io::AsRawFd; let mut aiomgr = AIOManager::new(new_batch_scheduler(None), 10, None, None).unwrap(); let file = std::fs::OpenOptions::new() .read(true) .write(true) .create(true) .truncate(true) .open("test") .unwrap(); let fd = file.as_raw_fd(); // keep all returned futures in a vector let ws = vec![(0, "hello"), (5, "world"), (2, "xxxx")] .into_iter() .map(|(off, s)| aiomgr.write(fd, off, s.as_bytes().into(), None)) .collect::<Vec<_>>(); // here we use futures::executor::LocalPool to poll all futures let mut pool = LocalPool::new(); let spawner = pool.spawner(); for w in ws.into_iter() { let h = spawner.spawn_local_with_handle(w).unwrap().map(|r| { println!("wrote {} bytes", r.unwrap().0); }); spawner.spawn_local(h).unwrap(); } pool.run();
Structs
AIO | Represent the necessary data for an AIO operation. Memory-safe when moved. |
AIOBatchSchedulerIn | |
AIOBatchSchedulerOut | |
AIOFuture | Represents a scheduled (future) asynchronous I/O operation, which gets executed (resolved) automatically. |
AIOManager | Manager all AIOs. |
AIONotifier | The state machine for finished AIO operations and wakes up the futures. |
Enums
Error |
Traits
AIOSchedulerIn | |
AIOSchedulerOut |
Functions
new_batch_scheduler | Create the scheduler that submits AIOs in batches. |
Type Definitions
AIOResult | The result of an AIO operation: the number of bytes written on success, or the errno on failure. |