// recv_loop reads packets from sock. If the packet is a Fuchsia mdns packet, a
// corresponding mdns event is published to the queue. All other packets are
// silently discarded.
recv_loop reads packets from sock. If the packet is a Fuchsia mdns packet, a
corresponding mdns event is published to the queue. All other packets are
silently discarded.
recv_loop reads packets from sock . If the packet is a Fuchsia mdns packet a corresponding mdns event is published to the queue . All other packets are silently discarded .
async fn recv_loop(sock: Arc<UdpSocket>, e: events::Queue<DaemonEvent>) {
    loop {
        let mut buf = &mut [0u8; 1500][..];
        let addr = match sock.recv_from(&mut buf).await {
            Ok((sz, addr)) => {
                buf = &mut buf[..sz];
                addr
            }
            Err(err) => {
                log::info!("listen socket recv error: {}, mdns listener closed", err);
                return;
            }
        };
        let msg = match buf.parse::<dns::Message<_>>() {
            Ok(msg) => msg,
            _ => continue,
        };
        // Note: important, otherwise non-local responders could add themselves.
        if !addr.ip().is_local_addr() {
            continue;
        }
        if !is_fuchsia_response(&msg) {
            continue;
        }
        if let Ok(info) = msg.try_into_target_info(addr) {
            log::trace!(
                "packet from {} ({}) on {}",
                addr,
                info.nodename.clone().unwrap_or("<unknown>".to_string()),
                sock.local_addr().unwrap()
            );
            e.push(DaemonEvent::WireTraffic(WireTrafficType::Mdns(info)))
                .unwrap_or_else(|err| log::debug!("mdns discovery was unable to publish: {}", err));
        }
    }
}
async fn recv_loop ( sock : Arc < UdpSocket > , e : events :: Queue < DaemonEvent > ) { loop { let mut buf = & mut [ 0u8 ; 1500 ] [ .. ] ; let addr = match sock . recv_from ( & mut buf ) . await { Ok ( ( sz , addr ) ) => { buf = & mut buf [ .. sz ] ; addr } Err ( err ) => { log :: info ! ( " " err ) ; return ; } } ; let msg = match buf . parse :: < dns :: Message < _ > > ( ) { Ok ( msg ) => msg , _ => continue , } ; // Note: important, otherwise non-local responders could add themselves. if ! addr . ip ( ) . is_local_addr ( ) { continue ; } if ! is_fuchsia_response ( & msg ) { continue ; } if let Ok ( info ) = msg . try_into_target_info ( addr ) { log :: trace ! ( " " addr info nodename clone ( ) unwrap_or ( " " to_string ( ) ) sock local_addr ( ) unwrap ( ) ) ; e . push ( DaemonEvent :: WireTraffic ( WireTrafficType :: Mdns ( info ) ) ) . unwrap_or_else ( | err | log :: debug ! ( " " err ) ) ; } } }
recv_loop reads packets from sock.
recv_loop reads packets from sock .
sock
Arc<UdpSocket>
e
events::Queue<DaemonEvent>