#file-descriptor #non-blocking #async-io #data-file #reader #io-read #o-nonblock

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

#884 in Asynchronous

Download history 2478/week @ 2024-08-18 2382/week @ 2024-08-25 2254/week @ 2024-09-01 2985/week @ 2024-09-08 2054/week @ 2024-09-15 2834/week @ 2024-09-22 1706/week @ 2024-09-29 2423/week @ 2024-10-06 2742/week @ 2024-10-13 2149/week @ 2024-10-20 1153/week @ 2024-10-27 2278/week @ 2024-11-03 1494/week @ 2024-11-10 1503/week @ 2024-11-17 956/week @ 2024-11-24 1471/week @ 2024-12-01

5,573 downloads per month
Used in 5 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

~43KB