-
Notifications
You must be signed in to change notification settings - Fork 656
Open
Labels
Description
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) whenReadUntil::poll()
returnsPoll::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 theself
object, which may be a Guard (MutexGuard
,RefMut
, or etc.) object. - the
ReadUntil::poll()
method may call the underlyingpoll_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 ofReadUntil
(theBufRead
part (maybe Guard), and thebuffer
(maybeVec<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