Failure: Converted `read_test` to a poll-based function, it still loses state required to maintain the buffer location. There"s no way to make this code keep the state. We need to re-design the function to something completely different.

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

@ -199,17 +199,14 @@ impl<T: AsyncRead + Unpin + ?Sized, const SIZE: usize> Buffered<T, SIZE>
self.buffer.drain(..copy);
copy
}
pub async fn read_test(&mut self, buf: &mut [u8]) -> io::Result<usize>
// async-based impl of `read`. there as a reference for when we find out how to write `poll_read`. Sigh...
async fn read_test(&mut self, buf: &mut [u8]) -> io::Result<usize>
{
use tokio::prelude::*;
let mut w = 0;
/*if self.buffer.is_empty()
{
self.fill_buffer().await?;
}*/
while w < buf.len() {
match self.try_take_buffer(&mut &mut buf[w..]) {
0 => {
@ -235,7 +232,31 @@ 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>> {
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.")
use futures::ready;
let this = self.get_mut();
let mut w =0;
Poll::Ready(loop {
let read = if this.buffer.len() < SIZE
{
this.buffer.resize(SIZE, 0);
let mut done=0;
let mut r=0;
// 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}
{
done +=r;
}
done
} else {
SIZE
};
match this.try_take_buffer(&mut &mut buf[w..]) {
0 => break Ok(w),
x => w+=x,
}
})
}
}

Loading…
Cancel
Save