From 5cbd5b8aa0c4e03b3006c4231b576e0618c9effa Mon Sep 17 00:00:00 2001 From: quininer Date: Fri, 17 Aug 2018 09:18:53 +0800 Subject: [PATCH] fix: handle Stream non-blocking write --- src/common.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/common.rs b/src/common.rs index f9900ff..9e3cb5c 100644 --- a/src/common.rs +++ b/src/common.rs @@ -100,7 +100,6 @@ impl<'a, S: Session, IO: Read + Write> Read for Stream<'a, S, IO> { break } } - self.session.read(buf) } } @@ -108,7 +107,13 @@ impl<'a, S: Session, IO: Read + Write> Read for Stream<'a, S, IO> { impl<'a, S: Session, IO: Read + Write> io::Write for Stream<'a, S, IO> { fn write(&mut self, buf: &[u8]) -> io::Result { let len = self.session.write(buf)?; - self.complete_io()?; + while self.session.wants_write() { + match self.complete_io() { + Ok(_) => (), + Err(ref err) if err.kind() == io::ErrorKind::WouldBlock && len != 0 => break, + Err(err) => return Err(err) + } + } Ok(len) }