Go to file
Taiki Endo 5bb8f1cde2
Merge pull request #10 from smol-rs/next
Bump to v1.0.4
2021-03-20 17:21:44 +09:00
.github/workflows bump MSRV 2021-01-11 13:45:31 +01:00
src update socket2 to 0.4.0 2021-03-16 13:32:09 +01:00
.gitignore Initial commit 2020-09-16 11:20:09 +02:00
CHANGELOG.md Bump to v1.0.4 2021-03-20 17:13:32 +09:00
Cargo.toml Bump to v1.0.4 2021-03-20 17:13:32 +09:00
LICENSE-APACHE Initial commit 2020-09-16 11:20:09 +02:00
LICENSE-MIT Initial commit 2020-09-16 11:20:09 +02:00
README.md Update license badge to match Cargo.toml 2021-02-14 13:37:07 +09:00

README.md

nb-connect

Build License Cargo Documentation

Non-blocking TCP or Unix connect.

This crate allows you to create a TcpStream or a UnixStream in a non-blocking way, without waiting for the connection to become fully established.

Examples

use polling::{Event, Poller};
use std::time::Duration;

// Create a pending TCP connection.
let stream = nb_connect::tcp(([127, 0, 0, 1], 80))?;

// Create a poller that waits for the stream to become writable.
let poller = Poller::new()?;
poller.add(&stream, Event::writable(0))?;

// Wait for at most 1 second.
if poller.wait(&mut Vec::new(), Some(Duration::from_secs(1)))? == 0 {
    println!("timeout");
} else if let Some(err) = stream.take_error()? {
    println!("error: {}", err);
} else {
    println!("connected");
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.