cancellable-io 0.1.1

Synchronous network I/O that can be interrupted.
Documentation
  • Coverage
  • 98.41%
    62 out of 63 items documented1 out of 62 items with examples
  • Size
  • Source code size: 66.46 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 5.22 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 33s Average build duration of successful builds.
  • all releases: 33s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Emm54321/cancellable-io
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Emm54321

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