FUCKING FAILURE: For FUCKs sake. NO MATTER HOW MUCH STATE I ADD TO THE DAMN THING, IT STILL FAILS TO READ PROPERLY AT SOME ARBITRARY POINT IN THE BUFFER.

I DONT FUCKING GET IT!!!)I")"(*)Q("*£

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

@ -20,6 +20,7 @@ pub struct Buffered<T: ?Sized, const SIZE: usize>
/// Current internal buffer
/// When it's full to `SIZE`, it should be written to `stream` at once then cleared when it's been written.
buffer: SmallVec<[u8; SIZE]>, //TODO: Can we have a non-spilling stack vec?
pending: usize, w: usize,
#[pin] stream: T
}
@ -32,6 +33,7 @@ where [(); SIZE]: Sized, // This isn't checked?
assert!(SIZE > 0, "Size of buffer cannot be 0");
Self {
buffer: SmallVec::new(),
pending: 0, w: 0,
stream,
}
}
@ -235,12 +237,11 @@ where T: AsyncRead
let this = self.get_mut();
let mut w =0;
Poll::Ready(loop {
let res = loop {
let read = if this.buffer.len() < SIZE
let read = if this.buffer.len() < SIZE || this.pending > 0
{
let st = this.buffer.len();
let st = if this.pending > 0 {this.pending-1} else { this.buffer.len() };
this.buffer.resize(SIZE, 0);
let mut done=st;
@ -250,12 +251,13 @@ where T: AsyncRead
(try $poll:expr) => {
match $poll {
Poll::Pending => {
this.buffer.resize(done, 0);
this.pending = st+1;
//this.buffer.resize(done, 0);
return Poll::Pending;
},
Poll::Ready(Ok(x)) => x,
err => {
this.buffer.resize(done, 0);
//this.buffer.resize(done, 0);
return err;
}
}
@ -266,18 +268,21 @@ where T: AsyncRead
{
done +=r;
}
this.pending = 0;
// This causes early eof (0)
//println!("Done: {}", done);
//this.buffer.resize(done, 0);
done
} else {
SIZE
this.buffer.len()
};
match this.try_take_buffer(&mut &mut buf[w..]) {
0 => break Ok(w),
x => w+=x,
match this.try_take_buffer(&mut &mut buf[this.w..]) {
0 => break Ok(this.w),
x => this.w+=x,
}
})
};
this.w = 0;
Poll::Ready(res)
}
}
@ -346,8 +351,8 @@ mod tests
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());
assert_eq!(rx.read_exact(&mut output[..DATA.len()]).await?, DATA.len());
assert_eq!(rx.read_exact(&mut output[DATA.len()..]).await?, DATA.len());
back.await.expect("Back panick")?;

Loading…
Cancel
Save