shut down on broken pipe

This commit is contained in:
mat 2022-11-09 18:18:55 -06:00
parent ad8b1b7b24
commit f2d21ad813

View file

@ -11,6 +11,7 @@ use crate::write::write_packet;
use azalea_auth::sessionserver::SessionServerError;
use azalea_crypto::{Aes128CfbDec, Aes128CfbEnc};
use bytes::BytesMut;
use log::info;
use std::fmt::Debug;
use std::marker::PhantomData;
use std::net::SocketAddr;
@ -131,13 +132,22 @@ where
{
/// Write a packet to the server.
pub async fn write(&mut self, packet: W) -> std::io::Result<()> {
write_packet(
if let Err(e) = write_packet(
&packet,
&mut self.write_stream,
self.compression_threshold,
&mut self.enc_cipher,
)
.await
{
// detect broken pipe
if e.kind() == std::io::ErrorKind::BrokenPipe {
info!("Broken pipe, shutting down connection.")
self.shutdown();
}
return Err(e);
}
Ok(())
}
/// End the connection.