#file-descriptor #reader #async-io #data-file #non-blocking #named-pipe #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

#709 in Asynchronous

Download history 1042/week @ 2024-11-25 1329/week @ 2024-12-02 1113/week @ 2024-12-09 1223/week @ 2024-12-16 447/week @ 2024-12-23 466/week @ 2024-12-30 1636/week @ 2025-01-06 1816/week @ 2025-01-13 1762/week @ 2025-01-20 1604/week @ 2025-01-27 1445/week @ 2025-02-03 1853/week @ 2025-02-10 1657/week @ 2025-02-17 2230/week @ 2025-02-24 2147/week @ 2025-03-03 2589/week @ 2025-03-10

8,693 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

~44KB