Add missing check for read of 0 bytes. (#194)

Forgot this one in PR #178.
This commit is contained in:
Toralf Wittner 2018-05-17 15:29:27 +02:00 committed by GitHub
parent 86a21fc43e
commit 15540a34c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -101,6 +101,7 @@ fn block_on_wrong_stream<T: AsyncRead, Buf: Array<Item = u8>>(
}); });
let mut out_consumed = 0; let mut out_consumed = 0;
let mut stream_eof = false;
if let Some((tasks, cache)) = lock.open_streams if let Some((tasks, cache)) = lock.open_streams
.entry(substream_id) .entry(substream_id)
.or_insert_with(|| SubstreamMetadata::new_open()) .or_insert_with(|| SubstreamMetadata::new_open())
@ -130,6 +131,10 @@ fn block_on_wrong_stream<T: AsyncRead, Buf: Array<Item = u8>>(
match lock.stream.read(buf_prefix) { match lock.stream.read(buf_prefix) {
Ok(consumed) => { Ok(consumed) => {
if consumed == 0 && !buf_prefix.is_empty() {
stream_eof = true
}
let new_remaining = remaining_bytes - consumed; let new_remaining = remaining_bytes - consumed;
assert!(cache.extend_from_slice(&buf_prefix[..consumed])); assert!(cache.extend_from_slice(&buf_prefix[..consumed]));
@ -158,6 +163,10 @@ fn block_on_wrong_stream<T: AsyncRead, Buf: Array<Item = u8>>(
} }
} }
if stream_eof {
lock.close()
}
Ok(out_consumed) Ok(out_consumed)
} }