Forward max_length argument from high-level API

This commit is contained in:
Dirkjan Ochtman
2021-01-25 10:39:47 +01:00
committed by Benjamin Saunders
parent ce67167968
commit 0654eb254e
3 changed files with 24 additions and 11 deletions
+6 -2
View File
@@ -904,8 +904,12 @@ where
}
/// Read the next ordered chunk from the given recv stream
pub fn read_chunk(&mut self, id: StreamId) -> Result<Option<Bytes>, ReadError> {
let result = self.streams.read_chunk(id);
pub fn read_chunk(
&mut self,
id: StreamId,
max_length: usize,
) -> Result<Option<Bytes>, ReadError> {
let result = self.streams.read_chunk(id, max_length);
self.post_read(id, &result);
Ok(result?.map(|x| x.result))
}
+4 -4
View File
@@ -203,8 +203,8 @@ impl Streams {
self.try_read(id, |rs| rs.read_unordered())
}
pub(crate) fn read_chunk(&mut self, id: StreamId) -> ReadResult<Bytes> {
self.try_read(id, |rs| rs.read_chunk())
pub(crate) fn read_chunk(&mut self, id: StreamId, max_length: usize) -> ReadResult<Bytes> {
self.try_read(id, |rs| rs.read_chunk(max_length))
}
pub(crate) fn read_chunks(
@@ -1139,8 +1139,8 @@ impl Recv {
}
}
fn read_chunk(&mut self) -> StreamReadResult<Bytes> {
match self.assembler.read_chunk(usize::MAX)? {
fn read_chunk(&mut self, max_length: usize) -> StreamReadResult<Bytes> {
match self.assembler.read_chunk(max_length)? {
Some(bytes) => Ok(Some(bytes)),
None => self.read_blocked().map(|()| None),
}
+14 -5
View File
@@ -389,13 +389,20 @@ where
///
/// Slightly more efficient than `read` due to not copying. Chunk boundaries
/// do not correspond to peer writes, and hence cannot be used as framing.
pub fn read_chunk(&mut self) -> ReadChunk<'_, S> {
ReadChunk { stream: self }
pub fn read_chunk(&mut self, max_length: usize) -> ReadChunk<'_, S> {
ReadChunk {
stream: self,
max_length,
}
}
/// Foundation of [`read_chunk()`]: RecvStream::read_chunk
fn poll_read_chunk(&mut self, cx: &mut Context) -> Poll<Result<Option<Bytes>, ReadError>> {
self.poll_read_generic(cx, |conn, stream| conn.inner.read_chunk(stream))
fn poll_read_chunk(
&mut self,
cx: &mut Context,
max_length: usize,
) -> Poll<Result<Option<Bytes>, ReadError>> {
self.poll_read_generic(cx, |conn, stream| conn.inner.read_chunk(stream, max_length))
}
/// Read the next segments of data
@@ -812,6 +819,7 @@ where
S: proto::crypto::Session,
{
stream: &'a mut RecvStream<S>,
max_length: usize,
}
impl<'a, S> Future for ReadChunk<'a, S>
@@ -820,7 +828,8 @@ where
{
type Output = Result<Option<Bytes>, ReadError>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
self.stream.poll_read_chunk(cx)
let max_length = self.max_length;
self.stream.poll_read_chunk(cx, max_length)
}
}