12 releases
Uses old Rust 2015
0.1.11 | Aug 30, 2018 |
---|---|
0.1.10 | Aug 15, 2018 |
0.1.9 | Mar 8, 2018 |
0.1.2 | Feb 24, 2018 |
#523 in Unix APIs
68KB
1K
SLoC
tokio-linux-aio
This package provides an integration of Linux kernel-level asynchronous I/O to the Tokio platform.
Linux kernel-level asynchronous I/O is different from the Posix AIO library. Posix AIO is implemented using a pool of userland threads, which invoke regular, blocking system calls to perform file I/O. Linux kernel-level AIO, on the other hand, provides kernel-level asynchronous scheduling of I/O operations to the underlying block device.
Note: Implementation and test development is still in progress. I'm waiting for tokio 0.2 to stabilize before doing a next revision of this crate. In the interim, I'm working on vervolg, an implementation of a front-end for a subset of the SQL language. Overall, my goal is to put together a test bed and experimentation platform for database kernels.
Usage
Add this to your Cargo.toml
:
[dependencies]
tokio-linux-aio = "0.1"
Next, add this to the root module of your crate:
extern crate tokio_linux_aio;
Examples
Once you have added the crate to your project you should be able to write something like this:
// Let's use a standard thread pool
let pool = futures_cpupool::CpuPool::new(5);
// These are handle objects for memory regions
let buffer = MemoryHandle::new();
{
// Here we go: create an execution context, which uses the pool for background work
let context = AioContext::new(&pool, 10).unwrap();
// Create a future to read from a given file (fd) at the given offset into our buffer
let read_future = context
.read(fd, 0, buffer)
.map(move |result_buffer| {
// do something upon successfully reading the data
assert!(validate_block(result_buffer.as_ref()));
})
.map_err(|err| {
// do something else when things go wrong
panic!("{:?}", err);
});
// Execute the future and wait for its completion
let cpu_future = pool.spawn(read_future);
let result = cpu_future.wait();
// Should be OK
assert!(result.is_ok());
}
License
This code is licensed under the MIT license.
Dependencies
~4.5–6.5MB
~108K SLoC