Giter VIP home page Giter VIP logo

io-uring's Introduction

Linux IO Uring

github actions crates license license docs.rs

The low-level io_uring userspace interface for Rust.

Usage

To use io-uring crate, first add this to your Cargo.toml:

[dependencies]
io-uring = "0.6"

Next we can start using io-uring crate. The following is quick introduction using Read for file.

use io_uring::{opcode, types, IoUring};
use std::os::unix::io::AsRawFd;
use std::{fs, io};

fn main() -> io::Result<()> {
    let mut ring = IoUring::new(8)?;

    let fd = fs::File::open("README.md")?;
    let mut buf = vec![0; 1024];

    let read_e = opcode::Read::new(types::Fd(fd.as_raw_fd()), buf.as_mut_ptr(), buf.len() as _)
        .build()
        .user_data(0x42);

    // Note that the developer needs to ensure
    // that the entry pushed into submission queue is valid (e.g. fd, buffer).
    unsafe {
        ring.submission()
            .push(&read_e)
            .expect("submission queue is full");
    }

    ring.submit_and_wait(1)?;

    let cqe = ring.completion().next().expect("completion queue is empty");

    assert_eq!(cqe.user_data(), 0x42);
    assert!(cqe.result() >= 0, "read error: {}", cqe.result());

    Ok(())
}

Note that opcode Read is only available after kernel 5.6. If you use a kernel lower than 5.6, this example will fail.

Test and Benchmarks

You can run the test and benchmark of the library with the following commands.

$ cargo run --package io-uring-test
$ cargo bench --package io-uring-bench

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in io-uring by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

io-uring's People

Contributors

quininer avatar frankreh avatar kestrer avatar lucab avatar albertofaria avatar rushilmehra avatar taiki-e avatar dagenix avatar saiintbrisson avatar serzhiio avatar lanquemar avatar aidanhs avatar supercilex avatar barcharcraz avatar reisz avatar dekellum avatar fathyb avatar gardnervickers avatar hagsteel avatar jackkelly avatar jsitnicki avatar notgull avatar sw17ch avatar dzamlo avatar ma-etl avatar mrakh avatar mxxo avatar stefano-garzarella avatar stephandollberg avatar thomasdezeeuw 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.