Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

muxers/mplex/benches: Use combinators to reduce nesting #2688

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 17 additions & 19 deletions muxers/mplex/benches/split_send_size.rs
Expand Up @@ -104,26 +104,24 @@ fn run(transport: &mut BenchTransport, payload: &Vec<u8>, listen_addr: &Multiadd
}
transport::ListenerEvent::Upgrade { upgrade, .. } => {
let (_peer, conn) = upgrade.await.unwrap();
match poll_fn(|cx| conn.poll_event(cx)).await {
Ok(muxing::StreamMuxerEvent::InboundSubstream(mut s)) => {
let mut buf = vec![0u8; payload_len];
let mut off = 0;
loop {
// Read in typical chunk sizes of up to 8KiB.
let end = off + std::cmp::min(buf.len() - off, 8 * 1024);
let n = poll_fn(|cx| {
conn.read_substream(cx, &mut s, &mut buf[off..end])
})
.await
.unwrap();
off += n;
if off == buf.len() {
return;
}
}
let mut s = poll_fn(|cx| conn.poll_event(cx))
.await
.expect("unexpected error")
.into_inbound_substream()
.expect("Unexpected muxer event");

let mut buf = vec![0u8; payload_len];
let mut off = 0;
loop {
// Read in typical chunk sizes of up to 8KiB.
let end = off + std::cmp::min(buf.len() - off, 8 * 1024);
let n = poll_fn(|cx| conn.read_substream(cx, &mut s, &mut buf[off..end]))
.await
.unwrap();
off += n;
if off == buf.len() {
return;
}
Ok(_) => panic!("Unexpected muxer event"),
Err(e) => panic!("Unexpected error: {:?}", e),
}
}
_ => panic!("Unexpected listener event"),
Expand Down