From 6e9db53d14e1bb5fa17ebf44ccf32e5a39ee6ff7 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 25 Jan 2021 12:30:02 +0100 Subject: [PATCH] quinn-proto: rename Assembler::read_chunk() to read() --- quinn-proto/src/connection/assembler.rs | 35 +++++++++++-------------- quinn-proto/src/connection/mod.rs | 2 +- quinn-proto/src/connection/streams.rs | 6 ++--- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/quinn-proto/src/connection/assembler.rs b/quinn-proto/src/connection/assembler.rs index 1e2c3ba77..fcf70c3e6 100644 --- a/quinn-proto/src/connection/assembler.rs +++ b/quinn-proto/src/connection/assembler.rs @@ -45,10 +45,7 @@ impl Assembler { } // Get the the next ordered chunk - pub(crate) fn read_chunk( - &mut self, - max_length: usize, - ) -> Result, IllegalOrderedRead> { + pub(crate) fn read(&mut self, max_length: usize) -> Result, IllegalOrderedRead> { if let State::Unordered { .. } = self.state { return Err(IllegalOrderedRead); } @@ -422,14 +419,14 @@ mod test { x.insert(7, Bytes::from_static(b"hij")); x.insert(11, Bytes::from_static(b"lmn")); x.defragment(); - assert_matches!(x.read_chunk(usize::MAX), Ok(Some(ref y)) if &y[..] == b"abcdef"); + assert_matches!(x.read(usize::MAX), Ok(Some(ref y)) if &y[..] == b"abcdef"); x.insert(5, Bytes::from_static(b"fghijklmn")); - assert_matches!(x.read_chunk(usize::MAX), Ok(Some(ref y)) if &y[..] == b"ghijklmn"); + assert_matches!(x.read(usize::MAX), Ok(Some(ref y)) if &y[..] == b"ghijklmn"); x.insert(13, Bytes::from_static(b"nopq")); - assert_matches!(x.read_chunk(usize::MAX), Ok(Some(ref y)) if &y[..] == b"opq"); + assert_matches!(x.read(usize::MAX), Ok(Some(ref y)) if &y[..] == b"opq"); x.insert(15, Bytes::from_static(b"pqrs")); - assert_matches!(x.read_chunk(usize::MAX), Ok(Some(ref y)) if &y[..] == b"rs"); - assert_matches!(x.read_chunk(usize::MAX), Ok(None)); + assert_matches!(x.read(usize::MAX), Ok(Some(ref y)) if &y[..] == b"rs"); + assert_matches!(x.read(usize::MAX), Ok(None)); } #[test] @@ -470,36 +467,36 @@ mod test { fn chunks_dedup() { let mut x = Assembler::new(); x.insert(3, Bytes::from_static(b"def")); - assert_eq!(x.read_chunk(usize::MAX).unwrap(), None); + assert_eq!(x.read(usize::MAX).unwrap(), None); x.insert(0, Bytes::from_static(b"a")); x.insert(1, Bytes::from_static(b"bcdefghi")); x.insert(0, Bytes::from_static(b"abcd")); assert_eq!( - x.read_chunk(usize::MAX).unwrap(), + x.read(usize::MAX).unwrap(), Some(Bytes::from_static(b"abcd")) ); assert_eq!( - x.read_chunk(usize::MAX).unwrap(), + x.read(usize::MAX).unwrap(), Some(Bytes::from_static(b"efghi")) ); - assert_eq!(x.read_chunk(usize::MAX).unwrap(), None); + assert_eq!(x.read(usize::MAX).unwrap(), None); x.insert(8, Bytes::from_static(b"ijkl")); assert_eq!( - x.read_chunk(usize::MAX).unwrap(), + x.read(usize::MAX).unwrap(), Some(Bytes::from_static(b"jkl")) ); - assert_eq!(x.read_chunk(usize::MAX).unwrap(), None); + assert_eq!(x.read(usize::MAX).unwrap(), None); x.insert(12, Bytes::from_static(b"mno")); assert_eq!( - x.read_chunk(usize::MAX).unwrap(), + x.read(usize::MAX).unwrap(), Some(Bytes::from_static(b"mno")) ); - assert_eq!(x.read_chunk(usize::MAX).unwrap(), None); + assert_eq!(x.read(usize::MAX).unwrap(), None); x.insert(2, Bytes::from_static(b"cde")); - assert_eq!(x.read_chunk(usize::MAX).unwrap(), None); + assert_eq!(x.read(usize::MAX).unwrap(), None); } fn next(x: &mut Assembler, size: usize) -> Option { - x.read_chunk(size).unwrap() + x.read(size).unwrap() } } diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index d5bc84322..a41840180 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -1757,7 +1757,7 @@ where space .crypto_stream .insert(crypto.offset, crypto.data.clone()); - while let Some(buf) = space.crypto_stream.read_chunk(usize::MAX).unwrap() { + while let Some(buf) = space.crypto_stream.read(usize::MAX).unwrap() { trace!("consumed {} CRYPTO bytes", buf.len()); if self.crypto.read_handshake(&buf)? { self.events.push_back(Event::HandshakeDataReady); diff --git a/quinn-proto/src/connection/streams.rs b/quinn-proto/src/connection/streams.rs index df223e1ad..21058b7c5 100644 --- a/quinn-proto/src/connection/streams.rs +++ b/quinn-proto/src/connection/streams.rs @@ -1121,7 +1121,7 @@ impl Recv { } let mut read = 0; - while let Some(chunk) = self.assembler.read_chunk(buf.len() - read)? { + while let Some(chunk) = self.assembler.read(buf.len() - read)? { (&mut buf[read..read + chunk.len()]).copy_from_slice(&chunk); read += chunk.len(); if read == buf.len() { @@ -1149,7 +1149,7 @@ impl Recv { } fn read_chunk(&mut self, max_length: usize) -> StreamReadResult { - match self.assembler.read_chunk(max_length)? { + match self.assembler.read(max_length)? { Some(bytes) => Ok(Some(bytes)), None => self.read_blocked().map(|()| None), } @@ -1161,7 +1161,7 @@ impl Recv { return Ok(Some(out)); } - while let Some(bytes) = self.assembler.read_chunk(usize::MAX)? { + while let Some(bytes) = self.assembler.read(usize::MAX)? { chunks[out.bufs] = bytes; out.read += chunks[out.bufs].len(); out.bufs += 1;