#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

#98 in Unix APIs

Download history 36/week @ 2020-12-24 81/week @ 2020-12-31 54/week @ 2021-01-07 29/week @ 2021-01-14 14/week @ 2021-01-21 13/week @ 2021-01-28 19/week @ 2021-02-04 53/week @ 2021-02-11 43/week @ 2021-02-18 35/week @ 2021-02-25 14/week @ 2021-03-04 32/week @ 2021-03-11 17/week @ 2021-03-18 30/week @ 2021-03-25 13/week @ 2021-04-01 18/week @ 2021-04-08

167 downloads per month
Used in trsh

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.5MB
~38K SLoC