Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nanpuyue/tokio-fd

Non-blocking Read and Write a Linux/Unix File Descriptor
https://github.com/nanpuyue/tokio-fd

async linux mio non-blocking rust tokio

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

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

[![Crates.io](https://img.shields.io/crates/v/tokio-fd?color=green)](https://crates.io/crates/tokio-fd)

## Example

```rust
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

* [Apache License, Version 2.0](https://github.com/nanpuyue/tokio-fd/blob/master/LICENSE-APACHE)
* [MIT License](https://github.com/nanpuyue/tokio-fd/blob/master/LICENSE-MIT)

at your option.