1 unstable release

0.1.1 Apr 15, 2019
0.1.0 Apr 11, 2019

#14 in #tcp-listener

Download history 87/week @ 2024-11-16 71/week @ 2024-11-23 104/week @ 2024-11-30 41/week @ 2024-12-07 24/week @ 2024-12-14 4/week @ 2024-12-28 17/week @ 2025-01-04 13/week @ 2025-01-11 25/week @ 2025-01-18 12/week @ 2025-01-25 33/week @ 2025-02-01 60/week @ 2025-02-08 48/week @ 2025-02-15 99/week @ 2025-02-22 85/week @ 2025-03-01

297 downloads per month

MIT/Apache

49KB
963 lines

cancellable-io

A crate implementing cancellable synchronous network I/O.

This crate exposes structs TcpStream, TcpListener and UdpSocket that are similar to their std::net variants, except that I/O operations can be cancelled through Canceller objects created with them.

Most methods work as they do in the std::net implementations, and you should refer to the original documentation for details and examples.

Main differences with the original std::net implementations :

Example

use cancellable_io::*;
let (listener, canceller) = TcpListener::bind("127.0.0.1:0").unwrap();
let handle = std::thread::spawn(move || {
    println!("Waiting for connections.");
    let r = listener.accept();
    assert!(is_cancelled(&r.unwrap_err()));
    println!("Server cancelled.");
});

std::thread::sleep(std::time::Duration::from_secs(2));
canceller.cancel().unwrap();
handle.join().unwrap();

License: MIT/Apache-2.0

Dependencies

~0.6–1MB
~14K SLoC