mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-07 00:00:09 +02:00
io: do not treat zero-length reads as EOF in Chain (#8251)
This commit is contained in:
@@ -94,7 +94,9 @@ where
|
||||
if !*me.done_first {
|
||||
let rem = buf.remaining();
|
||||
ready!(me.first.poll_read(cx, buf))?;
|
||||
if buf.remaining() == rem {
|
||||
// A read that fills nothing only indicates EOF if the buffer
|
||||
// had capacity to begin with.
|
||||
if buf.remaining() == rem && rem != 0 {
|
||||
*me.done_first = true;
|
||||
} else {
|
||||
return Poll::Ready(Ok(()));
|
||||
|
||||
@@ -14,3 +14,15 @@ async fn chain() {
|
||||
assert_ok!(rd.read_to_end(&mut buf).await);
|
||||
assert_eq!(buf, b"hello world");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn empty_read_does_not_skip_first() {
|
||||
let mut buf = Vec::new();
|
||||
let rd1: &[u8] = b"hello ";
|
||||
let rd2: &[u8] = b"world";
|
||||
|
||||
let mut rd = rd1.chain(rd2);
|
||||
assert_eq!(assert_ok!(rd.read(&mut []).await), 0);
|
||||
assert_ok!(rd.read_to_end(&mut buf).await);
|
||||
assert_eq!(buf, b"hello world");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user