Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a poll variant to DmaStreamReader::get_buffer_aligned #449

Merged
merged 2 commits into from
Nov 4, 2021

Commits on Nov 4, 2021

  1. add a poll variant to DmaStreamReader::get_buffer_aligned

    Since `DmaStreamReader` is a stream, we have to play well with other
    streams and make our functions easy to use from a polling context.
    `get_buffer_aligned` is an async function and, as such, is hard to use
    from there (not impossible, just hard).
    
    If we look at the `AsyncRead` trait, one may see that it defines only
    poll functions. Async functions are then built on top in the
    `AsyncReadExt.` This is done because creating a future from a poll
    function is trivial, while the other way around is hard.
    
    Therefore, we create a new function `poll_get_buffer_aligned` and we
    reimplement `get_buffer_aligned` as a wrapper around it:
    
    ```rust
    pub async fn get_buffer_aligned(&mut self, len: u64) -> Result<ReadResult> {
        poll_fn(|cx| self.poll_get_buffer_aligned(cx, len)).await
    }
    ```
    HippoBaro committed Nov 4, 2021
    Configuration menu
    Copy the full SHA
    87ce95c View commit details
    Browse the repository at this point in the history
  2. rename get_buffer to poll_get_buffer for consistency

    Function returning `std::task::Poll` enums are usually called `poll_*`
    to tell them apart from their async variants.
    HippoBaro committed Nov 4, 2021
    Configuration menu
    Copy the full SHA
    5850658 View commit details
    Browse the repository at this point in the history