Crates.io | listener_poll |
lib.rs | listener_poll |
version | 0.1.1 |
created_at | 2025-05-09 16:09:58.829252+00 |
updated_at | 2025-06-28 15:09:42.690728+00 |
description | Poll with timeout for TcpListener and UnixListener |
homepage | |
repository | https://github.com/AlexanderSchuetz97/listener_poll |
max_upload_size | |
id | 1667284 |
size | 22,015 |
Adds polling functionality with timeout to TcpListener
and UnixListener
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
}
}
Compilation is tested!