Crate listener_poll

Crate listener_poll 

Source
Expand description

§listener_poll1

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
    }
}

Traits§

PollEx
extension Trait for TcpListener and UnixListener