pub async fn query(
        &self,
        name: &str,
        mut close_query_signal: mpsc::Receiver<()>,
    ) -> Result<(ResourceHeader, SocketAddr), Error> {
        {
            if self.is_server_closed.load(atomic::Ordering::SeqCst) {
                return Err(ERR_CONNECTION_CLOSED.to_owned());
            }
        }

        let name_with_suffix = name.to_owned() + ".";

        let (query_tx, mut query_rx) = mpsc::channel(1);
        {
            let mut queries = self.queries.lock().await;
            queries.push(Query {
                name_with_suffix: name_with_suffix.clone(),
                query_result_chan: query_tx,
            });
        }

        log::trace!("Sending query");
        self.send_question(&name_with_suffix).await;

        loop {
            tokio::select! {
                _ = tokio::time::sleep(self.query_interval) => {
                    log::trace!("Sending query");
                    self.send_question(&name_with_suffix).await
                },

                _ = close_query_signal.recv() => {
                    log::info!("Query close signal received.");
                    return Err(ERR_CONNECTION_CLOSED.to_owned())
                },

                res_opt = query_rx.recv() =>{
                    log::info!("Received query result");
                    if let Some(res) = res_opt{
                        return Ok((res.answer, res.addr));
                    }
                }
            }
        }
    }
/// Query sends mDNS Queries for the following name until
/// either there's a close signalling or we get a result
Query sends mDNS Queries for the following name until
either there's a close signalling or we get a result
Query sends mDNS Queries for the following name until either there ' s a close signalling or we get a result
pub async fn query(
        &self,
        name: &str,
        mut close_query_signal: mpsc::Receiver<()>,
    ) -> Result<(ResourceHeader, SocketAddr), Error> {
        {
            if self.is_server_closed.load(atomic::Ordering::SeqCst) {
                return Err(ERR_CONNECTION_CLOSED.to_owned());
            }
        }
        let name_with_suffix = name.to_owned() + ".";
        let (query_tx, mut query_rx) = mpsc::channel(1);
        {
            let mut queries = self.queries.lock().await;
            queries.push(Query {
                name_with_suffix: name_with_suffix.clone(),
                query_result_chan: query_tx,
            });
        }
        log::trace!("Sending query");
        self.send_question(&name_with_suffix).await;
        loop {
            tokio::select! {
                _ = tokio::time::sleep(self.query_interval) => {
                    log::trace!("Sending query");
                    self.send_question(&name_with_suffix).await
                },
                _ = close_query_signal.recv() => {
                    log::info!("Query close signal received.");
                    return Err(ERR_CONNECTION_CLOSED.to_owned())
                },
                res_opt = query_rx.recv() =>{
                    log::info!("Received query result");
                    if let Some(res) = res_opt{
                        return Ok((res.answer, res.addr));
                    }
                }
            }
        }
    }
pub async fn query ( & self , name : & str , mut close_query_signal : mpsc :: Receiver < ( ) > , ) -> Result < ( ResourceHeader , SocketAddr ) , Error > { { if self . is_server_closed . load ( atomic :: Ordering :: SeqCst ) { return Err ( ERR_CONNECTION_CLOSED . to_owned ( ) ) ; } } let name_with_suffix = name . to_owned ( ) + " " ; let ( query_tx , mut query_rx ) = mpsc :: channel ( 1 ) ; { let mut queries = self . queries . lock ( ) . await ; queries . push ( Query { name_with_suffix : name_with_suffix . clone ( ) , query_result_chan : query_tx , } ) ; } log :: trace ! ( " " ) ; self . send_question ( & name_with_suffix ) . await ; loop { tokio :: select ! { tokio time sleep ( self query_interval ) { log trace ( " " ) self send_question ( name_with_suffix ) await } close_query_signal recv ( ) { log info ( " " ) return Err ( ERR_CONNECTION_CLOSED to_owned ( ) ) } res_opt query_rx recv ( ) { log info ( " " ) if let Some ( res ) res_opt { return Ok ( ( res answer res addr ) ) } } } } }
Query sends mDNS Queries for the following name until
either there's a close signalling or we get a result
Query sends mDNS Queries for the following name until either there ' s a close signalling or we get a result
&self
name
&str
close_query_signal
mpsc::Receiver<()>
&self
name
&str
close_query_signal
mpsc::Receiver<()>