1 个不稳定版本

0.1.0 2024年5月28日

#390异步


用于 fluke-buffet

MIT/Apache

15KB
274

IoUringAsync (fluke 分支)

这是 fluke 对 https://github.com/thomasbarrett/io-uring-async 的分支

以下为原始 README 文件。

IoUringAsync

IoUringAsync 是在常用库 io-uring 上的一层薄薄的异步兼容层,使其更容易与 Tokio 运行时一起使用。

类似项目

该项目深受 tokio-uring 项目的启发。与 tokio-uring 不同,IoUringAsync 不是它自己的运行时。相反,它是一组轻量级的、大多数与运行时不相关的 future。

限制

目前,该项目不支持多射击 io_uring 操作。

完全控制 SQE 提交。

let sqe = opcode::Write(...).build();
let fut = uring.push(sqe);
uring.submit();
let cqe = fut.await;

示例

use std::rc::Rc;
use io_uring::{squeue, cqueue, opcode};
use io_uring_async::IoUringAsync;
use send_wrapper::SendWrapper;

fn main() {
    let uring = IoUringAsync::new(8).unwrap();
    let uring = Rc::new(uring);

    // Create a new current_thread runtime that submits all outstanding submission queue
    // entries as soon as the executor goes idle.
    let uring_clone = SendWrapper::new(uring.clone());
    let runtime = tokio::runtime::Builder::new_current_thread().
        on_thread_park(move || { uring_clone.submit().unwrap(); }).
        enable_all().
        build().unwrap();

    runtime.block_on(async move {
        tokio::task::LocalSet::new().run_until(async {
            // Spawn a task that waits for the io_uring to become readable and handles completion
            // queue entries accordingly.
            tokio::task::spawn_local(IoUringAsync::listen(uring.clone()));

            let cqe = uring.push(Nop::new().build()).await;
            assert!(cqe.result() >= 0, "nop error: {}", cqe.result());
        }).await;
    });
}

依赖项

~2–10MB
~92K SLoC