Skip to content

Commit

Permalink
fix: panic_on_option_buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingtous committed Oct 17, 2022
1 parent e3d9b3d commit 7ec466e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions monoio-rustls/src/safe_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ impl SafeRead {

impl io::Read for SafeRead {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if self.buffer.is_none() {
return Err(io::ErrorKind::Other.into());
}
// if buffer is empty, return WoundBlock.
let buffer = self.buffer.as_mut().expect("buffer mut expected");
if buffer.is_empty() {
Expand Down Expand Up @@ -213,6 +216,9 @@ impl SafeWrite {

impl io::Write for SafeWrite {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
if self.buffer.is_none() {
return Err(io::ErrorKind::Other.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) {
Expand All @@ -233,6 +239,9 @@ impl io::Write for SafeWrite {
}

fn flush(&mut self) -> io::Result<()> {
if self.buffer.is_none() {
return Err(io::ErrorKind::Other.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) {
Expand Down

0 comments on commit 7ec466e

Please sign in to comment.