Code Monkey home page Code Monkey logo

tokio-linux-aio's Introduction

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));
        })
        .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.

tokio-linux-aio's People

Contributors

dependabot-support avatar gitter-badger avatar hmwill avatar kevin-vigor avatar srijs avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.