diff options
Diffstat (limited to 'azalea-protocol/src/connect.rs')
| -rwxr-xr-x | azalea-protocol/src/connect.rs | 19 |
1 files changed, 18 insertions, 1 deletions
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<Option<R>, Box<ReadPacketError>> { + try_read_packet::<R, _>( + &mut self.read_stream, + &mut self.buffer, + self.compression_threshold, + &mut self.dec_cipher, + ) + } } impl<W> WriteConnection<W> 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<Option<R>, Box<ReadPacketError>> { + 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 |
