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: 3 months ago
JSON representation
Non-blocking Read and Write a Linux/Unix File Descriptor
- Host: GitHub
- URL: https://github.com/nanpuyue/tokio-fd
- Owner: nanpuyue
- License: apache-2.0
- Created: 2020-01-31T06:04:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-06T14:18:34.000Z (over 5 years ago)
- Last Synced: 2024-10-30T18:42:50.067Z (over 1 year ago)
- Topics: async, linux, mio, non-blocking, rust, tokio
- Language: Rust
- Homepage:
- Size: 11.7 KB
- Stars: 18
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Non-blocking Read and Write a Linux/Unix File Descriptor
[](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.