diff --git a/src/multipart.rs b/src/multipart.rs index 898a7f194..45126a2a6 100644 --- a/src/multipart.rs +++ b/src/multipart.rs @@ -130,7 +130,7 @@ impl InnerMultipart where S: Stream { fn read_headers(payload: &mut PayloadHelper) -> Poll { - match payload.readuntil(b"\r\n\r\n")? { + match payload.read_until(b"\r\n\r\n")? { Async::NotReady => Ok(Async::NotReady), Async::Ready(None) => Err(MultipartError::Incomplete), Async::Ready(Some(bytes)) => { @@ -469,13 +469,13 @@ impl InnerField where S: Stream { fn read_stream(payload: &mut PayloadHelper, boundary: &str) -> Poll, MultipartError> { - match payload.readuntil(b"\r")? { + match payload.read_until(b"\r")? { Async::NotReady => Ok(Async::NotReady), Async::Ready(None) => Err(MultipartError::Incomplete), Async::Ready(Some(mut chunk)) => { if chunk.len() == 1 { payload.unread_data(chunk); - match payload.readexactly(boundary.len() + 4)? { + match payload.read_exact(boundary.len() + 4)? { Async::NotReady => Ok(Async::NotReady), Async::Ready(None) => Err(MultipartError::Incomplete), Async::Ready(Some(chunk)) => { diff --git a/src/payload.rs b/src/payload.rs index 512d56f1e..d32e85a4f 100644 --- a/src/payload.rs +++ b/src/payload.rs @@ -313,7 +313,7 @@ impl PayloadHelper where S: Stream { } #[inline] - pub fn readexactly(&mut self, size: usize) -> Poll, PayloadError> { + pub fn read_exact(&mut self, size: usize) -> Poll, PayloadError> { if size <= self.len { self.len -= size; let mut chunk = self.items.pop_front().unwrap(); @@ -341,7 +341,7 @@ impl PayloadHelper where S: Stream { } } else { match self.poll_stream()? { - Async::Ready(true) => self.readexactly(size), + Async::Ready(true) => self.read_exact(size), Async::Ready(false) => Ok(Async::Ready(None)), Async::NotReady => Ok(Async::NotReady), } @@ -387,7 +387,7 @@ impl PayloadHelper where S: Stream { } } - pub fn readuntil(&mut self, line: &[u8]) -> Poll, PayloadError> { + pub fn read_until(&mut self, line: &[u8]) -> Poll, PayloadError> { let mut idx = 0; let mut num = 0; let mut offset = 0; @@ -436,14 +436,14 @@ impl PayloadHelper where S: Stream { } match self.poll_stream()? { - Async::Ready(true) => self.readuntil(line), + Async::Ready(true) => self.read_until(line), Async::Ready(false) => Ok(Async::Ready(None)), Async::NotReady => Ok(Async::NotReady), } } pub fn readline(&mut self) -> Poll, PayloadError> { - self.readuntil(b"\n") + self.read_until(b"\n") } pub fn unread_data(&mut self, data: Bytes) { diff --git a/src/ws/frame.rs b/src/ws/frame.rs index 52a20e50a..c17437979 100644 --- a/src/ws/frame.rs +++ b/src/ws/frame.rs @@ -198,6 +198,7 @@ impl Frame { -> Poll, ProtocolError> where S: Stream { + // try to parse ws frame md from one chunk let result = match pl.get_chunk()? { Async::NotReady => return Ok(Async::NotReady), Async::Ready(Some(chunk)) => Frame::read_chunk_md(chunk, server, max_size)?, @@ -205,6 +206,7 @@ impl Frame { }; let (idx, finished, opcode, length, mask) = match result { + // we may need to join several chunks Async::NotReady => match Frame::read_copy_md(pl, server, max_size)? { Async::NotReady => return Ok(Async::NotReady), Async::Ready(Some(item)) => item, @@ -228,7 +230,7 @@ impl Frame { finished, opcode, payload: Binary::from("") }))); } - let data = match pl.readexactly(length)? { + let data = match pl.read_exact(length)? { Async::Ready(Some(buf)) => buf, Async::Ready(None) => return Ok(Async::Ready(None)), Async::NotReady => panic!(),