From 0a83dc73b4c06b9300b8e16f8a30d512374262cd Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 16 Jul 2023 05:50:02 -0500 Subject: add try_read to connection --- azalea-protocol/src/connect.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'azalea-protocol/src/connect.rs') diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs index cb837ba5..5df1d874 100755 --- a/azalea-protocol/src/connect.rs +++ b/azalea-protocol/src/connect.rs @@ -6,7 +6,7 @@ use crate::packets::login::clientbound_hello_packet::ClientboundHelloPacket; use crate::packets::login::{ClientboundLoginPacket, ServerboundLoginPacket}; use crate::packets::status::{ClientboundStatusPacket, ServerboundStatusPacket}; use crate::packets::ProtocolPacket; -use crate::read::{read_packet, ReadPacketError}; +use crate::read::{read_packet, try_read_packet, ReadPacketError}; use crate::write::write_packet; use azalea_auth::game_profile::GameProfile; use azalea_auth::sessionserver::{ClientSessionServerError, ServerSessionServerError}; @@ -140,6 +140,17 @@ where ) .await } + + /// Try to read a packet from the stream, or return Ok(None) if there's no + /// packet. + pub fn try_read(&mut self) -> Result, Box> { + try_read_packet::( + &mut self.read_stream, + &mut self.buffer, + self.compression_threshold, + &mut self.dec_cipher, + ) + } } impl WriteConnection where @@ -183,6 +194,12 @@ where self.reader.read().await } + /// Try to read a packet from the other side of the connection, or return + /// Ok(None) if there's no packet to read. + pub fn try_read(&mut self) -> Result, Box> { + self.reader.try_read() + } + /// Write a packet to the other side of the connection. pub async fn write(&mut self, packet: W) -> std::io::Result<()> { self.writer.write(packet).await -- cgit v1.2.3