-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make it easy to consume a
DmaStreamReader
without copying (#474)
* soft fail when crossing buffer boundaries in `get_buffer_aligned` The `get_buffer_aligned` API could be better. It relies on user code to be aware of buffer boundaries locations. This makes user code more complicated and brittle because the buffer size will generally be a configurable knob, subject to change. Fear not, however, for there is a better way! Instead of failing when reading too much in `get_buffer_aligned,` read whatever we can from the current buffer. This allows the following: * If the read fits inside a buffer, the user can consume the result directly without any copy; * If the read crosses buffer boundaries and the user can consume partial results, it can do so in a loop without any copies; * If the read crosses buffer boundaries and the user needs a complete result, `get_buffer_aligned` may be used trivially in a loop that concatenates the results in a reusable user-allocated buffer. The following commit will replace the `AsyncRead::poll_read` implementation with a simple loop calling `get_buffer_aligned.` * enforce `max_pos` stream config in `poll_get_buffer_aligned` 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. * use `poll_get_buffer_aligned` in `DmaStreamReader::poll_read` Massive simplification; Oh Yeah!!
- Loading branch information
Showing
1 changed file
with
69 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters