diff --git a/edge-mdns/src/io.rs b/edge-mdns/src/io.rs index 2eb61c9..56a3a22 100644 --- a/edge-mdns/src/io.rs +++ b/edge-mdns/src/io.rs @@ -143,6 +143,7 @@ where send_buf: SB, rand: fn(&mut [u8]), broadcast_signal: &'a Signal, + wait_readable: bool, } impl<'a, M, R, S, RB, SB> Mdns<'a, M, R, S, RB, SB> @@ -174,9 +175,17 @@ where send_buf, rand, broadcast_signal, + wait_readable: false, } } + /// Sets whether the mDNS service should wait for the socket to be readable before reading. + /// + /// Setting this to `true` is only useful when the read buffer is shared with other tasks + pub fn wait_readable(&mut self, wait_readable: bool) { + self.wait_readable = wait_readable; + } + /// Runs the mDNS service, handling queries and responding to them, as well as broadcasting /// mDNS answers and handling responses to our own queries. /// @@ -280,7 +289,9 @@ where let mut recv = self.recv.lock().await; loop { - recv.readable().await.map_err(MdnsIoError::IoError)?; + if self.wait_readable { + recv.readable().await.map_err(MdnsIoError::IoError)?; + } { let mut recv_buf = self