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

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

#402 in Unix APIs

Download history 565/week @ 2023-11-18 1787/week @ 2023-11-25 1954/week @ 2023-12-02 1173/week @ 2023-12-09 1117/week @ 2023-12-16 367/week @ 2023-12-23 1456/week @ 2023-12-30 1766/week @ 2024-01-06 1876/week @ 2024-01-13 1768/week @ 2024-01-20 1489/week @ 2024-01-27 1373/week @ 2024-02-03 1980/week @ 2024-02-10 1109/week @ 2024-02-17 1411/week @ 2024-02-24 1904/week @ 2024-03-02

6,544 downloads per month
Used in 11 crates (4 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–12MB
~106K SLoC