diff --git a/monoio-rustls/src/safe_io.rs b/monoio-rustls/src/safe_io.rs index 11b196a..012d816 100644 --- a/monoio-rustls/src/safe_io.rs +++ b/monoio-rustls/src/safe_io.rs @@ -213,6 +213,9 @@ impl SafeWrite { impl io::Write for SafeWrite { fn write(&mut self, buf: &[u8]) -> io::Result { + if self.buffer.is_none() { + return Err(io::ErrorKind::WriteZero.into()); + } // if there is too much data inside the buffer, return WoundBlock let buffer = self.buffer.as_mut().expect("buffer mut expected"); if !matches!(self.status, WriteStatus::Ok) { @@ -233,6 +236,9 @@ impl io::Write for SafeWrite { } fn flush(&mut self) -> io::Result<()> { + if self.buffer.is_none() { + return Err(io::ErrorKind::WriteZero.into()); + } let buffer = self.buffer.as_mut().expect("buffer mut expected"); if !matches!(self.status, WriteStatus::Ok) { match std::mem::replace(&mut self.status, WriteStatus::Ok) {