From 23416561734c925ba678284d02b4e4c56b11a699 Mon Sep 17 00:00:00 2001 From: "Robert G. Jakabosky" Date: Sat, 1 Sep 2018 01:41:38 +0800 Subject: [PATCH] Simplify buffer reading logic. Remove duplicate code. --- src/client/parser.rs | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/client/parser.rs b/src/client/parser.rs index 5dd163395..7348de32a 100644 --- a/src/client/parser.rs +++ b/src/client/parser.rs @@ -38,20 +38,17 @@ impl HttpResponseParser { where T: IoStream, { - // if buf is empty parse_message will always return NotReady, let's avoid that - if buf.is_empty() { + loop { match io.read_available(buf) { - Ok(Async::Ready((true, true))) => (), Ok(Async::Ready((false, true))) => { return Err(HttpResponseParserError::Disconnect) } - Ok(Async::Ready((_, false))) => (), + Ok(Async::Ready(_)) => (), Ok(Async::NotReady) => return Ok(Async::NotReady), - Err(err) => return Err(HttpResponseParserError::Error(err.into())), + Err(err) => { + return Err(HttpResponseParserError::Error(err.into())) + } } - } - - loop { match HttpResponseParser::parse_message(buf) .map_err(HttpResponseParserError::Error)? { @@ -63,17 +60,6 @@ impl HttpResponseParser { if buf.capacity() >= MAX_BUFFER_SIZE { return Err(HttpResponseParserError::Error(ParseError::TooLarge)); } - match io.read_available(buf) { - Ok(Async::Ready((true, true))) => (), - Ok(Async::Ready((false, true))) => { - return Err(HttpResponseParserError::Disconnect) - } - Ok(Async::Ready((_, false))) => (), - Ok(Async::NotReady) => return Ok(Async::NotReady), - Err(err) => { - return Err(HttpResponseParserError::Error(err.into())) - } - } } } }