#non-blocking #file-descriptor #reader #data-file #async-io #io-read #named-pipe

nonblock

Read available data from file descriptors without blocking (e.g. sockets, streams, child stdout, named pipes)

2 unstable releases

0.2.0 Jun 26, 2022
0.1.0 Apr 25, 2016

#1053 in Asynchronous

Download history 3086/week @ 2023-11-24 3252/week @ 2023-12-01 1837/week @ 2023-12-08 2753/week @ 2023-12-15 2541/week @ 2023-12-22 1921/week @ 2023-12-29 2211/week @ 2024-01-05 2944/week @ 2024-01-12 3145/week @ 2024-01-19 2132/week @ 2024-01-26 1538/week @ 2024-02-02 2112/week @ 2024-02-09 2163/week @ 2024-02-16 2981/week @ 2024-02-23 2100/week @ 2024-03-01 1058/week @ 2024-03-08

8,805 downloads per month
Used in 4 crates

MIT license

11KB
104 lines

nonblock-rs

Read available data from file descriptors without blocking

Documentation

Crates.io Build Status

Examples

See structure-stdio.rs for an example usage.

Build & Test

This project is built and tested with cargo:

cargo build
cargo test
cargo doc --no-deps

Pro-tip: before building docs, clone existing docs to track changes

git clone -b gh-pages git@github.com:anowell/nonblock-rs.git target/doc

lib.rs:

Read available data from file descriptors without blocking

Useful for nonblocking reads from sockets, named pipes, and child stdout/stderr

Example

use std::io::Read;
use std::process::{Command, Stdio};
use std::time::Duration;
use nonblock::NonBlockingReader;

let mut child = Command::new("some-executable")
                        .stdout(Stdio::piped())
                        .spawn().unwrap();
let stdout = child.stdout.take().unwrap();
let mut noblock_stdout = NonBlockingReader::from_fd(stdout).unwrap();
while !noblock_stdout.is_eof() {
    let mut buf = String::new();
    noblock_stdout.read_available_to_string(&mut buf).unwrap();
    std::thread::sleep(Duration::from_secs(5));
}

Dependencies

~42KB