aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/connect.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-07-16 05:50:02 -0500
committermat <git@matdoes.dev>2023-07-16 05:50:02 -0500
commit0a83dc73b4c06b9300b8e16f8a30d512374262cd (patch)
tree62ecc67501300bb7ef6c1996cefc440a94f826ee /azalea-protocol/src/connect.rs
parent509c154b4d90515f8964f5a1a732106cb7fa0288 (diff)
downloadazalea-drasl-0a83dc73b4c06b9300b8e16f8a30d512374262cd.tar.xz
add try_read to connection
Diffstat (limited to 'azalea-protocol/src/connect.rs')
-rwxr-xr-xazalea-protocol/src/connect.rs19
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