mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-25 12:57:07 +00:00
quinn-proto: rename Assembler::read_chunk() to read()
This commit is contained in:
committed by
Benjamin Saunders
parent
6a58b3f542
commit
6e9db53d14
@@ -45,10 +45,7 @@ impl Assembler {
|
||||
}
|
||||
|
||||
// Get the the next ordered chunk
|
||||
pub(crate) fn read_chunk(
|
||||
&mut self,
|
||||
max_length: usize,
|
||||
) -> Result<Option<Bytes>, IllegalOrderedRead> {
|
||||
pub(crate) fn read(&mut self, max_length: usize) -> Result<Option<Bytes>, 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<Bytes> {
|
||||
x.read_chunk(size).unwrap()
|
||||
x.read(size).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Bytes> {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user