From a7c24aace17a28f61bad1850f70e6e31ff297c6e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 14 Jan 2018 19:28:34 -0800 Subject: [PATCH] flush is useless --- src/pipeline.rs | 10 ---------- src/server/encoding.rs | 13 +++++-------- src/server/h1writer.rs | 18 ++++-------------- src/server/h2writer.rs | 5 ----- src/server/mod.rs | 2 -- src/server/shared.rs | 5 +++++ 6 files changed, 14 insertions(+), 39 deletions(-) diff --git a/src/pipeline.rs b/src/pipeline.rs index fbaf7399e..7335dec6a 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -575,16 +575,6 @@ impl ProcessResponse { if self.running == RunningState::Paused || self.drain.is_some() { match io.poll_completed(false) { Ok(Async::Ready(_)) => { - match io.flush() { - Ok(Async::Ready(_)) => (), - Ok(Async::NotReady) => return Err(PipelineState::Response(self)), - Err(err) => { - debug!("Error sending data: {}", err); - info.error = Some(err.into()); - return Ok(FinishingMiddlewares::init(info, self.resp)) - } - } - self.running.resume(); // resolve drain futures diff --git a/src/server/encoding.rs b/src/server/encoding.rs index 1c6ed7d76..e5b75c482 100644 --- a/src/server/encoding.rs +++ b/src/server/encoding.rs @@ -535,14 +535,10 @@ impl ContentEncoder { #[inline] pub fn is_eof(&self) -> bool { match *self { - ContentEncoder::Br(ref encoder) => - encoder.get_ref().is_eof(), - ContentEncoder::Deflate(ref encoder) => - encoder.get_ref().is_eof(), - ContentEncoder::Gzip(ref encoder) => - encoder.get_ref().is_eof(), - ContentEncoder::Identity(ref encoder) => - encoder.is_eof(), + ContentEncoder::Br(ref encoder) => encoder.get_ref().is_eof(), + ContentEncoder::Deflate(ref encoder) => encoder.get_ref().is_eof(), + ContentEncoder::Gzip(ref encoder) => encoder.get_ref().is_eof(), + ContentEncoder::Identity(ref encoder) => encoder.is_eof(), } } @@ -710,6 +706,7 @@ impl TransferEncoding { let mut buf = BytesMut::new(); write!(&mut buf, "{:X}\r\n", msg.len()) .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; + self.buffer.reserve(buf.len() + msg.len() + 2); self.buffer.extend(buf.into()); self.buffer.extend(msg); self.buffer.extend_from_slice(b"\r\n"); diff --git a/src/server/h1writer.rs b/src/server/h1writer.rs index 7f18170fe..e1212980e 100644 --- a/src/server/h1writer.rs +++ b/src/server/h1writer.rs @@ -66,6 +66,10 @@ impl H1Writer { fn write_to_stream(&mut self) -> io::Result { while !self.buffer.is_empty() { match self.stream.write(self.buffer.as_ref()) { + Ok(0) => { + self.disconnected(); + return Ok(WriterState::Done); + }, Ok(n) => { let _ = self.buffer.split_to(n); }, @@ -90,20 +94,6 @@ impl Writer for H1Writer { self.written } - #[inline] - fn flush(&mut self) -> Poll<(), io::Error> { - match self.stream.flush() { - Ok(_) => Ok(Async::Ready(())), - Err(e) => { - if e.kind() == io::ErrorKind::WouldBlock { - Ok(Async::NotReady) - } else { - Err(e) - } - } - } - } - fn start(&mut self, req: &mut HttpMessage, msg: &mut HttpResponse) -> io::Result { // prepare task self.flags.insert(Flags::STARTED); diff --git a/src/server/h2writer.rs b/src/server/h2writer.rs index 0701d028e..7ce05a629 100644 --- a/src/server/h2writer.rs +++ b/src/server/h2writer.rs @@ -108,11 +108,6 @@ impl Writer for H2Writer { self.written } - #[inline] - fn flush(&mut self) -> Poll<(), io::Error> { - Ok(Async::Ready(())) - } - fn start(&mut self, req: &mut HttpMessage, msg: &mut HttpResponse) -> io::Result { // prepare response self.flags.insert(Flags::STARTED); diff --git a/src/server/mod.rs b/src/server/mod.rs index a44d2835a..869788ddc 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -104,8 +104,6 @@ pub trait Writer { fn write_eof(&mut self) -> io::Result; - fn flush(&mut self) -> Poll<(), io::Error>; - fn poll_completed(&mut self, shutdown: bool) -> Poll<(), io::Error>; } diff --git a/src/server/shared.rs b/src/server/shared.rs index 15307e0fe..22851a10c 100644 --- a/src/server/shared.rs +++ b/src/server/shared.rs @@ -90,6 +90,11 @@ impl SharedBytes { self.get_mut().take() } + #[inline] + pub fn reserve(&self, cnt: usize) { + self.get_mut().reserve(cnt) + } + #[inline] #[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] pub fn extend(&self, data: Binary) {