#async #fd #io #non-blocking #tokio

tokio-fd

Non-blocking Read and Write a Linux File Descriptor

3 releases (breaking)

0.3.0 Jan 6, 2021
0.2.1 Nov 20, 2020
0.2.0 Nov 19, 2020
0.1.0 Feb 11, 2020

#332 in Unix APIs

Download history 1511/week @ 2023-02-01 1143/week @ 2023-02-08 1357/week @ 2023-02-15 1111/week @ 2023-02-22 2059/week @ 2023-03-01 2614/week @ 2023-03-08 1968/week @ 2023-03-15 2488/week @ 2023-03-22 2392/week @ 2023-03-29 1685/week @ 2023-04-05 2129/week @ 2023-04-12 1183/week @ 2023-04-19 835/week @ 2023-04-26 2438/week @ 2023-05-03 2215/week @ 2023-05-10 1512/week @ 2023-05-17

7,075 downloads per month
Used in 9 crates (3 directly)

MIT/Apache

7KB
92 lines

Non-blocking Read and Write a Linux/Unix File Descriptor

Crates.io

Example

use std::convert::TryFrom;
use std::io::Result;

use tokio::prelude::*;
use tokio_fd::AsyncFd;

#[tokio::main]
async fn main() -> Result<()> {
    let mut stdin = AsyncFd::try_from(libc::STDIN_FILENO)?;
    let mut stdout = AsyncFd::try_from(libc::STDOUT_FILENO)?;
    let mut buf = vec![0; 1024];

    while let Ok(n) = stdin.read(&mut buf).await {
        stdout.write(&buf[..n]).await?;
    }
    Ok(())
}

License

This project is licensed under either of

at your option.

Dependencies

~2.2–7MB
~103K SLoC