listener_poll

Crates.iolistener_poll
lib.rslistener_poll
version0.1.1
created_at2025-05-09 16:09:58.829252+00
updated_at2025-06-28 15:09:42.690728+00
descriptionPoll with timeout for TcpListener and UnixListener
homepage
repositoryhttps://github.com/AlexanderSchuetz97/listener_poll
max_upload_size
id1667284
size22,015
Alexander Schütz (AlexanderSchuetz97)

documentation

README

listener_poll

Adds polling functionality with timeout to TcpListener and UnixListener

Example

use std::{io, thread};
use std::net::TcpListener;
use std::sync::Arc;

use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::SeqCst;
use std::time::Duration;

use listener_poll::PollEx;

fn handle_accept(listener: TcpListener, active: Arc<AtomicBool>) -> io::Result<()> {
    loop {
        if !active.load(SeqCst) {
            return Ok(());
        }
        if !listener.poll(Some(Duration::from_secs(5)))? {
            continue;
        }
        let (_sock, _addr) = listener.accept()?;
        //... probably thread::spawn or mpsc Sender::send
    }
}

Tested targets

  • |i686, x86_64, sparc64, powerpc, s390x|-unknown-linux-gnu
  • |i686, x86_64|-unknown-linux-musl
  • |i686, x86_64|-pc-windows-gnu
  • x86_64-unknown-freebsd
  • x86_64-unknown-openbsd

Untested targets that probably work

Compilation is tested!

  • |x86_64, aarch64|-apple-darwin
  • x86_64-unknown-netbsd
Commit count: 1

cargo fmt