mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-23 16:11:19 +00:00
Add missing check for read of 0 bytes. (#194)
Forgot this one in PR #178.
This commit is contained in:
parent
86a21fc43e
commit
15540a34c2
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user