tokio-linux-aio

Crates.iotokio-linux-aio
lib.rstokio-linux-aio
version0.1.11
sourcesrc
created_at2018-02-14 04:43:10.922442
updated_at2018-08-30 06:12:58.001227
descriptionTokio bindings for Linux kernel AIO
homepage
repositoryhttps://github.com/hmwill/tokio-linux-aio
max_upload_size
id51078
size66,681
Hans-Martin Will (hmwill)

documentation

https://docs.rs/tokio-linux-aio/

README

tokio-linux-aio

Version License Docs Build Status Join the chat at https://gitter.im/tokio-linux-aio/Lobby

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.

Commit count: 102

cargo fmt