Skip to content

Commit

Permalink
Slightly improve performance
Browse files Browse the repository at this point in the history
- Only try to decode packet when new data arrives.
  • Loading branch information
lukas0008 committed Aug 18, 2024
1 parent 17535bd commit 3e1d103
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions pumpkin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,23 +385,28 @@ impl Client {
self.kick(&e.to_string()).await;
break;
}
};
loop {
match self.dec.decode() {
Ok(Some(packet)) => {
self.add_packet(packet);
let mut server = server.write().await;
self.process_packets(&mut server).await;
continue;
}
Ok(None) => break,
Err(err) => {
self.kick(&err.to_string()).await;
break;
},
};
}

},
_ = tokio::time::sleep(Duration::from_millis(100)) => {
// Handle timeout (optional)
}
}

match self.dec.decode() {
Ok(packet) => {
if let Some(packet) = packet {
self.add_packet(packet);
let mut server = server.write().await;
self.process_packets(&mut server).await;
}
}
Err(err) => self.kick(&err.to_string()).await,
}
}
}

Expand Down

0 comments on commit 3e1d103

Please sign in to comment.