Found bug. poll_read needs rewrite. Dunno how to write it tho.

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

@ -235,38 +235,7 @@ 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>> {
let this = self.get_mut();
//XXX: Pinning then polling this future is causing BUG... Ffs...
let fut = async {
use tokio::prelude::*;
let mut w = 0;
/*if this.buffer.is_empty()
{
this.fill_buffer().await?;
}*/
while w < buf.len() {
match this.try_take_buffer(&mut &mut buf[w..]) {
0 => {
if !this.fill_buffer().await?
&& this.buffer.is_empty()
{
println!("Buffer empty");
break;
} else {
println!("Buffer filled");
}
},
x => w+=x,
}
}
println!("Done: {}", w);
Result::<usize, io::Error>::Ok(w)
};
tokio::pin!(fut);
fut.poll(cx)
todo!("Convert `read_test` method to a polling function. It is NOT possible to pin the future on the stack and poll it. causes bug.")
}
}
@ -329,8 +298,8 @@ mod tests
let mut output = vec![0u8; DATA.len()*2];
// Bug found! Pinning and polling that stack future in `poll_read` does NOT work!
// The exact same works as a real async function.
assert_eq!(rx.read_test(&mut output[..DATA.len()]).await?, DATA.len());
assert_eq!(rx.read_test(&mut output[DATA.len()..]).await?, DATA.len());
assert_eq!(rx.read(&mut output[..DATA.len()]).await?, DATA.len());
assert_eq!(rx.read(&mut output[DATA.len()..]).await?, DATA.len());
back.await.expect("Back panick")?;

Loading…
Cancel
Save