diff options
| author | mat <git@matdoes.dev> | 2025-02-23 09:05:20 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-02-23 09:05:20 +0000 |
| commit | 21acf4c84687eb40cb52746bdf40c2bbe9ab325a (patch) | |
| tree | dd3d2e4bdcfb7d63d5390b6bc0c1c7838b0470d3 /azalea-client/src | |
| parent | dd557c8f293dbef3e2e881bcb1a85a7697a1ebbb (diff) | |
| download | azalea-drasl-21acf4c84687eb40cb52746bdf40c2bbe9ab325a.tar.xz | |
try to receive packets all at once before sending run_schedule_sender
Diffstat (limited to 'azalea-client/src')
| -rw-r--r-- | azalea-client/src/raw_connection.rs | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/azalea-client/src/raw_connection.rs b/azalea-client/src/raw_connection.rs index e3f35282..4a6587be 100644 --- a/azalea-client/src/raw_connection.rs +++ b/azalea-client/src/raw_connection.rs @@ -133,21 +133,39 @@ impl RawConnectionReader { /// Loop that reads from the connection and adds the packets to the queue + /// runs the schedule. pub async fn read_task(self, mut read_conn: RawReadConnection) { + fn log_for_error(error: &ReadPacketError) { + if !matches!(*error, ReadPacketError::ConnectionClosed) { + error!("Error reading packet from Client: {error:?}"); + } + } + loop { match read_conn.read().await { Ok(raw_packet) => { - self.incoming_packet_queue.lock().push(raw_packet); + let mut incoming_packet_queue = self.incoming_packet_queue.lock(); + + incoming_packet_queue.push(raw_packet); + loop { + let raw_packet = match read_conn.try_read() { + Ok(p) => p, + Err(err) => { + log_for_error(&err); + return; + } + }; + let Some(raw_packet) = raw_packet else { break }; + incoming_packet_queue.push(raw_packet); + } + // tell the client to run all the systems if self.run_schedule_sender.send(()).is_err() { // the client was dropped break; } } - Err(error) => { - if !matches!(*error, ReadPacketError::ConnectionClosed) { - error!("Error reading packet from Client: {error:?}"); - } - break; + Err(err) => { + log_for_error(&err); + return; } } } |
