pub async fn open_monitored(
        &mut self,
        rx: &mut Receiver,
        is_running: Option<Arc<AtomicBool>>,
    ) -> io::Result<()> {
        // Send gratuitous ARP
        if self.gw_ip_addr.is_some() {
            self.tx.lock().unwrap().send_gratuitous_arp()?;
        }

        loop {
            // Monitor
            if let Some(is_running) = &is_running {
                if !is_running.load(Ordering::Relaxed) {
                    return Ok(());
                }
            }
            match rx.next() {
                Ok(frame) => {
                    if let Some(ref indicator) = Indicator::from(frame) {
                        if let Some(t) = indicator.network_kind() {
                            match t {
                                LayerKinds::Arp => {
                                    if let Err(ref e) = self.handle_arp(indicator) {
                                        warn!("handle {}: {}", indicator.brief(), e);
                                    }
                                }
                                LayerKinds::Ipv4 => {
                                    if let Err(ref e) = self.handle_ipv4(indicator, frame).await {
                                        warn!("handle {}: {}", indicator.brief(), e);
                                    }
                                }
                                _ => unreachable!(),
                            }
                        }
                    };
                }
                Err(e) => {
                    if e.kind() == io::ErrorKind::TimedOut {
                        thread::sleep(Duration::from_millis(TIMEDOUT_WAIT));
                        continue;
                    }
                    return Err(e);
                }
            };
        }
    }
/// Opens an `Interface` for redirection and monitoring.
Opens an `Interface` for redirection and monitoring.
Opens an ` Interface ` for redirection and monitoring .
pub async fn open_monitored(
        &mut self,
        rx: &mut Receiver,
        is_running: Option<Arc<AtomicBool>>,
    ) -> io::Result<()> {
        // Send gratuitous ARP
        if self.gw_ip_addr.is_some() {
            self.tx.lock().unwrap().send_gratuitous_arp()?;
        }
        loop {
            // Monitor
            if let Some(is_running) = &is_running {
                if !is_running.load(Ordering::Relaxed) {
                    return Ok(());
                }
            }
            match rx.next() {
                Ok(frame) => {
                    if let Some(ref indicator) = Indicator::from(frame) {
                        if let Some(t) = indicator.network_kind() {
                            match t {
                                LayerKinds::Arp => {
                                    if let Err(ref e) = self.handle_arp(indicator) {
                                        warn!("handle {}: {}", indicator.brief(), e);
                                    }
                                }
                                LayerKinds::Ipv4 => {
                                    if let Err(ref e) = self.handle_ipv4(indicator, frame).await {
                                        warn!("handle {}: {}", indicator.brief(), e);
                                    }
                                }
                                _ => unreachable!(),
                            }
                        }
                    };
                }
                Err(e) => {
                    if e.kind() == io::ErrorKind::TimedOut {
                        thread::sleep(Duration::from_millis(TIMEDOUT_WAIT));
                        continue;
                    }
                    return Err(e);
                }
            };
        }
    }
pub async fn open_monitored ( & mut self , rx : & mut Receiver , is_running : Option < Arc < AtomicBool > > , ) -> io :: Result < ( ) > { // Send gratuitous ARP if self . gw_ip_addr . is_some ( ) { self . tx . lock ( ) . unwrap ( ) . send_gratuitous_arp ( ) ? ; } loop { // Monitor if let Some ( is_running ) = & is_running { if ! is_running . load ( Ordering :: Relaxed ) { return Ok ( ( ) ) ; } } match rx . next ( ) { Ok ( frame ) => { if let Some ( ref indicator ) = Indicator :: from ( frame ) { if let Some ( t ) = indicator . network_kind ( ) { match t { LayerKinds :: Arp => { if let Err ( ref e ) = self . handle_arp ( indicator ) { warn ! ( " " indicator brief ( ) e ) ; } } LayerKinds :: Ipv4 => { if let Err ( ref e ) = self . handle_ipv4 ( indicator , frame ) . await { warn ! ( " " indicator brief ( ) e ) ; } } _ => unreachable ! ( ) , } } } ; } Err ( e ) => { if e . kind ( ) == io :: ErrorKind :: TimedOut { thread :: sleep ( Duration :: from_millis ( TIMEDOUT_WAIT ) ) ; continue ; } return Err ( e ) ; } } ; } }
Opens an `Interface` for redirection and monitoring.
Opens an ` Interface ` for redirection and monitoring .
&mut self
rx
&mut Receiver
is_running
Option<Arc<AtomicBool>>
&mut self
rx
&mut Receiver
is_running
Option<Arc<AtomicBool>>