launch exception if closing a closed TCP stream #1046

This commit is contained in:
Adrián Arroyo Calle
2021-09-28 22:48:51 +02:00
parent 5d2b0377d8
commit 4d0998ef72
2 changed files with 38 additions and 5 deletions

View File

@@ -164,10 +164,10 @@ impl Drop for StreamInstance {
fn drop(&mut self) {
match self {
StreamInstance::TcpStream(_, ref mut tcp_stream) => {
tcp_stream.shutdown(Shutdown::Both).unwrap();
tcp_stream.shutdown(Shutdown::Both).unwrap_or(())
}
StreamInstance::TlsStream(_, ref mut tls_stream) => {
tls_stream.shutdown().unwrap();
tls_stream.shutdown().unwrap_or(());
}
_ => {}
}
@@ -636,6 +636,20 @@ impl Stream {
}
}
pub(crate) fn is_closed(&self) -> bool {
match self.stream_inst.0.borrow_mut().stream_inst {
StreamInstance::Null => true,
StreamInstance::TcpStream(_, ref mut tcp_stream) => {
let mut buf = [0;8];
match tcp_stream.peek(&mut buf) {
Ok(n_bytes) => n_bytes == 0,
Err(_) => true
}
},
_ => false
}
}
fn unpause_stream(&mut self) {
let stream_inst = match self.stream_inst.0.borrow_mut().stream_inst {
StreamInstance::PausedPrologStream(ref put_back, ref mut stream_inst)