Skip to content

Commit

Permalink
enforce max_pos stream config in poll_get_buffer_aligned
Browse files Browse the repository at this point in the history
We need to make sure the stream can't return any bytes beyond the
`max_pos` offset. Right now, `poll_read` respects this while
`poll_get_buffer_aligned` doesn't. This commit makes sure we are
consistent across the two.
  • Loading branch information
HippoBaro committed Nov 29, 2021
1 parent b8d5e07 commit a5b8f1f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion glommio/src/io/dma_file_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,18 @@ impl DmaStreamReader {
pub fn poll_get_buffer_aligned(
&mut self,
cx: &mut Context<'_>,
len: u64,
mut len: u64,
) -> Poll<Result<(ReadResult, u64)>> {
let (start_id, buffer_len, remaining) = {
let state = self.state.borrow();
let start_id = state.buffer_id(self.current_pos);
let offset = state.offset_of(self.current_pos);

// enforce max_pos
if self.current_pos + len > state.max_pos {
len = state.max_pos - self.current_pos;
}

let buffer_len = (self.buffer_size - offset as u64).min(len);
(start_id, buffer_len, len - buffer_len)
};
Expand Down

0 comments on commit a5b8f1f

Please sign in to comment.