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
impl Conn
Sourcepub async fn read_packet(&mut self) -> RecvPacket
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.
Sourcepub async fn try_read_packet(&mut self, dur: Duration) -> Option<RecvPacket>
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.
Sourcepub(crate) async fn read_packet_or_eof(&mut self) -> Option<RecvPacket>
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.
Sourcepub async fn write_packet(&mut self, pkt: &Packet<'_>)
pub async fn write_packet(&mut self, pkt: &Packet<'_>)
Sourcepub async fn write_raw(&mut self, bytes: &[u8])
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.
Sourcepub async fn try_write_raw(&mut self, bytes: &[u8]) -> Result<()>
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.
Sourcepub async fn expect_connect(&mut self) -> RecvPacket
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.
Sourcepub async fn send_connack(
&mut self,
session_present: bool,
props: &[Property<'_>],
)
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.
Sourcepub async fn handshake(&mut self, props: &[Property<'_>])
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.
Sourcepub async fn send_puback(&mut self, packet_id: PacketId)
pub async fn send_puback(&mut self, packet_id: PacketId)
Acknowledges a QoS 1 PUBLISH with a successful PUBACK.
Sourcepub async fn send_suback(
&mut self,
packet_id: PacketId,
reason_codes: &[ReasonCode],
)
pub async fn send_suback( &mut self, packet_id: PacketId, reason_codes: &[ReasonCode], )
Acknowledges a SUBSCRIBE with one reason code per requested filter.
Sourcepub async fn expect_publish(&mut self) -> RecvPacket
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.
Sourcepub async fn expect_subscribe(&mut self) -> RecvPacket
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.
Sourcepub(crate) async fn expect_packet(&mut self, want: PacketType) -> RecvPacket
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.