Skip to content

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

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

nanpuyue/tokio-fd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages