pub struct ConnectionEmbedded<T>{ /* private fields */ }Expand description
Implementations§
Source§impl<T> ConnectionEmbedded<T>
impl<T> ConnectionEmbedded<T>
Trait Implementations§
Source§impl<T> Connection for ConnectionEmbedded<T>
impl<T> Connection for ConnectionEmbedded<T>
async fn send(&mut self, buf: &[u8]) -> Result<(), PacketWriteError>
async fn receive(&mut self, buf: &mut [u8]) -> Result<(), PacketReadError>
Source§async fn receive_if_ready(
&mut self,
buf: &mut [u8],
) -> Result<bool, PacketReadError>
async fn receive_if_ready( &mut self, buf: &mut [u8], ) -> Result<bool, PacketReadError>
If no data at all is ready, then return immediately with
Ok(false),
leaving the underlying stream and buf unaltered.
If any data is ready then receive into buffer, waiting to fill it,
then return Ok(true).
Note that this method can still await data, because it is only required
to return Ok(false) in the case where no data at all is ready. If less
data is available than buf.len(), the method may still proceed, reading
the available data and then waiting for more to fill buf.
This is fairly well suited to MQTT packets - first call receive_if_ready
with a buf of length 1 - if this returns Ok(false) then sleep for
a reasonable interval and try again. If it returns Ok(true), continue
reading a whole packet using receive, using larger buffers if possible.
While this may lead to an indefinite await for the rest of the packet, this
should only occur in the case of a malicious server or poor connection, not
in the most common case where there is a long gap between incoming packets,
but once the first byte of a packet is received the rest is received quickly
afterwards.
This approach is used to make it easier to use a variety of underlying streams,
since we only need something like embedded-async’s ReadReady trait, or
tokio’s TCPStream.try_read
More sophisticated approaches are definitely possible.Auto Trait Implementations§
impl<T> Freeze for ConnectionEmbedded<T>where
T: Freeze,
impl<T> RefUnwindSafe for ConnectionEmbedded<T>where
T: RefUnwindSafe,
impl<T> Send for ConnectionEmbedded<T>where
T: Send,
impl<T> Sync for ConnectionEmbedded<T>where
T: Sync,
impl<T> Unpin for ConnectionEmbedded<T>where
T: Unpin,
impl<T> UnsafeUnpin for ConnectionEmbedded<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for ConnectionEmbedded<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more