Skip to content

Commit

Permalink
fix(conn): handle when pre-emptive flushing closes the write state
Browse files Browse the repository at this point in the history
Closes #1391
  • Loading branch information
seanmonstar committed Dec 6, 2017
1 parent eb9590e commit 8f938d9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/proto/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ where I: AsyncRead + AsyncWrite,
}

},
Reading::Init | Reading::KeepAlive | Reading::Closed => unreachable!()
_ => unreachable!("read_body invalid state: {:?}", self.state.reading),
};

self.state.reading = reading;
ret
}
Expand Down Expand Up @@ -324,6 +325,14 @@ where I: AsyncRead + AsyncWrite,

if self.has_queued_body() {
try!(self.flush());

if !self.can_write_body() {
if chunk.as_ref().map(|c| c.as_ref().len()).unwrap_or(0) == 0 {
return Ok(AsyncSink::NotReady(chunk));
} else {
return Ok(AsyncSink::Ready);
}
}
}

let state = match self.state.writing {
Expand Down Expand Up @@ -369,8 +378,9 @@ where I: AsyncRead + AsyncWrite,
}
}
},
_ => unreachable!(),
_ => unreachable!("write_body invalid state: {:?}", self.state.writing),
};

self.state.writing = state;
Ok(AsyncSink::Ready)
}
Expand Down

0 comments on commit 8f938d9

Please sign in to comment.