Skip to content

impl AsyncBufReadExt for ReadHalf #2223

@fogti

Description

@fogti

previous, outdated issue: #2172.

well, after trying multiple options I realized that the underlying problem is currently not easily solvable without reimplementing a bigger chunk of futures-util (or alternatives with an AsyncBufReadExt::read_until fn), because:

  • the future returned by the read_until method contains state (buffered bytes), thus, we can't simply discard it (+ retry) when ReadUntil::poll() returns Poll::Pending
  • that future needs mutable access to the underlying object (at least to the BufRead part)
  • the AsyncBufRead::poll_fill_buf method returns a reference in the success case, this reference is bound to the self object, which may be a Guard (MutexGuard, RefMut, or etc.) object.
  • the ReadUntil::poll() method may call the underlying poll_fill_buf multiple times, but if one of these call yield, I would want to release the Guard and re-aquire it on the next try, but this doesn't work because the two components of ReadUntil (the BufRead part (maybe Guard), and the buffer (maybe Vec<u8>)) are thightly coupled together, althrough they don't need to be.

Thus I propose the following solution:
Duplicate the relevant parts of the code of impl AsyncBufReadExt, remove the trait bound AsyncBufReadExt: AsyncBufRead, impl<T: AsyncBufRead> AsyncBufReadExt for ReadHalf<T>, decouple the buffer and "underlying I/O container" from each other, at least a bit...
implementation suggestion:
https://github.com/YZITE/encsess2/blob/9d10160c47290da2795644c213cb46e4d9825ac0/demo-zsittle/server/src/main.rs#L32-L95

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions