Skip to content

Commit

Permalink
Read exactly 11 bytes
Browse files Browse the repository at this point in the history
Reading a stream to end is a tricky thing to do and may hang forever
in case the stream doesn't get closed by the other party. We know
exactly the message we want to receive so we can read exactly the
number of bytes.

With an upcoming refactoring where we introduce an opaque stream type,
the current code - for some reason - hangs forever :(
  • Loading branch information
thomaseizinger committed Jun 1, 2022
1 parent a135400 commit b6c91d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions muxers/mplex/tests/async_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ fn async_write() {
.await
.unwrap();

let mut buf = Vec::new();
outbound.read_to_end(&mut buf).await.unwrap();
let mut buf = vec![0u8; 11];
outbound.read_exact(&mut buf).await.unwrap();
assert_eq!(buf, b"hello world");
});

Expand Down
8 changes: 4 additions & 4 deletions muxers/mplex/tests/two_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ fn client_to_server_inbound() {
}
};

let mut buf = Vec::new();
inbound.read_to_end(&mut buf).await.unwrap();
let mut buf = vec![0u8; 11];
inbound.read_exact(&mut buf).await.unwrap();
assert_eq!(buf, b"hello world");
});

Expand Down Expand Up @@ -200,8 +200,8 @@ fn protocol_not_match() {
.await
.unwrap();

let mut buf = Vec::new();
outbound.read_to_end(&mut buf).await.unwrap();
let mut buf = vec![0u8; 11];
outbound.read_exact(&mut buf).await.unwrap();
assert_eq!(buf, b"hello world");
});

Expand Down

0 comments on commit b6c91d1

Please sign in to comment.