From e8d94e012943bd3c858cc62ac98773605b29c8de Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Wed, 11 Dec 2024 13:35:01 +0000 Subject: [PATCH] wait_readable flag; waiting for the socket is now turned off by default due to suspicions that it does not work quite right with embassy-net --- edge-mdns/src/io.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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