Conn

Struct Conn 

Source
pub struct Conn {
    pub(crate) stream: TcpStream,
    pub(crate) reader: PacketReader<GrowBuffer>,
}
Expand description

A single scripted broker-side connection.

Fields§

§stream: TcpStream§reader: PacketReader<GrowBuffer>

Implementations§

Source§

impl Conn

Source

pub async fn read_packet(&mut self) -> RecvPacket

Reads the next packet from the client.

§Panics

Panics if no packet arrives within 10 s or the connection closes.

Source

pub async fn try_read_packet(&mut self, dur: Duration) -> Option<RecvPacket>

Reads the next packet, returning None on timeout or if the client closed the connection cleanly.

§Panics

Panics on I/O errors or if the connection drops mid-packet.

Source

pub(crate) async fn read_packet_or_eof(&mut self) -> Option<RecvPacket>

Reads one packet; None on a clean EOF before the next packet starts.

Source

pub async fn write_packet(&mut self, pkt: &Packet<'_>)

Encodes and writes a packet to the client.

§Panics

Panics if encoding or the socket write fails.

Source

pub async fn write_raw(&mut self, bytes: &[u8])

Writes raw bytes to the client, bypassing packet encoding.

Useful for hand-crafted or deliberately malformed wire data, e.g. a fixed header that announces a body which is never sent.

§Panics

Panics if the socket write fails.

Source

pub async fn try_write_raw(&mut self, bytes: &[u8]) -> Result<()>

Writes raw bytes to the client, returning any socket error instead of panicking.

Use this when the client is expected to apply backpressure or close the connection, so the write failing (or never returning) is part of what the test observes.

§Errors

Returns the underlying I/O error if the socket write fails.

Source

pub async fn expect_connect(&mut self) -> RecvPacket

Reads the next packet and asserts it is a CONNECT.

§Panics

Panics if the next packet is not a CONNECT.

Source

pub async fn send_connack( &mut self, session_present: bool, props: &[Property<'_>], )

Sends a successful CONNACK with the given properties.

§Panics

Panics if a property is not valid for CONNACK.

Source

pub async fn handshake(&mut self, props: &[Property<'_>])

Performs the broker side of the connection handshake: reads CONNECT, replies with a successful CONNACK (session_present = false) carrying the given properties.

Source

pub async fn send_puback(&mut self, packet_id: PacketId)

Acknowledges a QoS 1 PUBLISH with a successful PUBACK.

Source

pub async fn send_suback( &mut self, packet_id: PacketId, reason_codes: &[ReasonCode], )

Acknowledges a SUBSCRIBE with one reason code per requested filter.

Source

pub async fn expect_publish(&mut self) -> RecvPacket

Reads packets until a PUBLISH arrives, transparently answering PINGREQ with PINGRESP. Returns the PUBLISH packet.

§Panics

Panics if a packet other than PUBLISH or PINGREQ arrives, or if no PUBLISH arrives within 10 s.

Source

pub async fn expect_subscribe(&mut self) -> RecvPacket

Reads packets until a SUBSCRIBE arrives, transparently answering PINGREQ with PINGRESP. Returns the SUBSCRIBE packet.

§Panics

Panics if a packet other than SUBSCRIBE or PINGREQ arrives, or if no SUBSCRIBE arrives within 10 s.

Source

pub(crate) async fn expect_packet(&mut self, want: PacketType) -> RecvPacket

Reads packets until one of type want arrives, transparently answering PINGREQ with PINGRESP.

§Panics

Panics if a packet other than want or PINGREQ arrives, or if no matching packet arrives within 10 s.

Auto Trait Implementations§

§

impl !Freeze for Conn

§

impl RefUnwindSafe for Conn

§

impl Send for Conn

§

impl Sync for Conn

§

impl Unpin for Conn

§

impl UnwindSafe for Conn

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.