3 stable releases

1.2.0 May 1, 2021
1.1.0 Mar 20, 2021
1.0.3 Feb 14, 2021
1.0.2 Oct 4, 2020
1.0.1 Sep 29, 2020

#2056 in Asynchronous

Download history 5845/week @ 2023-12-14 3936/week @ 2023-12-21 3566/week @ 2023-12-28 5473/week @ 2024-01-04 6030/week @ 2024-01-11 6385/week @ 2024-01-18 4113/week @ 2024-01-25 5072/week @ 2024-02-01 5019/week @ 2024-02-08 5236/week @ 2024-02-15 5467/week @ 2024-02-22 4747/week @ 2024-02-29 6206/week @ 2024-03-07 5105/week @ 2024-03-14 5776/week @ 2024-03-21 5727/week @ 2024-03-28

23,445 downloads per month

Apache-2.0 OR MIT

9KB
55 lines

nb-connect (deprecated)

Build License Cargo Documentation

This crate is now deprecated in favor of socket2.

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.

Dependencies

~250–465KB