Failure: Keeping buffer read/size state between pendings STILL doesn"t work...

Fortune for rsh's current commit: Small blessing − 小吉
sock-buffering
Avril 3 years ago
parent 019bdee5c1
commit ed69a8f187
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -232,22 +232,43 @@ impl<T: ?Sized + Unpin, const SIZE: usize> AsyncRead for Buffered<T, SIZE>
where T: AsyncRead
{
fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
use futures::ready;
let this = self.get_mut();
let mut w =0;
Poll::Ready(loop {
let read = if this.buffer.len() < SIZE
{
let st = this.buffer.len();
this.buffer.resize(SIZE, 0);
let mut done=0;
let mut done=st;
let mut r=0;
//XXX: Same issue even trying to save buffer length state over Pendings... Wtf is going on here?
macro_rules! ready {
(try $poll:expr) => {
match $poll {
Poll::Pending => {
this.buffer.resize(done, 0);
return Poll::Pending;
},
Poll::Ready(Ok(x)) => x,
err => {
this.buffer.resize(done, 0);
return err;
}
}
}
}
// XXX: V Same issue, runs the above code twice when re-polling after Pending. We need to make sure we jump back to this point in the code following a Pending poll to `stream.poll_read`, but I have no fucking clue how to do this? Eh...... We'll probably need to design the code differently. There is a lot of state that gets lost here and idk how to preserve it.... I hate this.
while done < SIZE && {r = ready!(Pin::new(&mut this.stream).poll_read(cx, &mut this.buffer[done..]))?; r > 0}
while done < SIZE && {r = ready!(try Pin::new(&mut this.stream).poll_read(cx, &mut this.buffer[done..])); r > 0}
{
done +=r;
}
// This causes early eof (0)
//println!("Done: {}", done);
//this.buffer.resize(done, 0);
done
} else {
SIZE
@ -318,7 +339,13 @@ mod tests
let mut output = vec![0u8; DATA.len()*2];
// Bug found! Pinning and polling that stack future in `poll_read` does NOT work!
// (we unrolled the async function to a poll based one and we're STILL losing state.... FFS!)
// The exact same works as a real async function.
/*
rx.read(&mut output[..DATA.len()]).await?;
rx.read(&mut output[DATA.len()..]).await?;
*/
assert_eq!(rx.read(&mut output[..DATA.len()]).await?, DATA.len());
assert_eq!(rx.read(&mut output[DATA.len()..]).await?, DATA.len());

Loading…
Cancel
Save