mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-02 20:51:21 +00:00
muxers/mplex/benches: Use combinators to reduce nesting (#2688)
This commit is contained in:
parent
bd9834aab4
commit
fcc987e0f6
@ -104,26 +104,24 @@ fn run(transport: &mut BenchTransport, payload: &Vec<u8>, listen_addr: &Multiadd
|
|||||||
}
|
}
|
||||||
transport::ListenerEvent::Upgrade { upgrade, .. } => {
|
transport::ListenerEvent::Upgrade { upgrade, .. } => {
|
||||||
let (_peer, conn) = upgrade.await.unwrap();
|
let (_peer, conn) = upgrade.await.unwrap();
|
||||||
match poll_fn(|cx| conn.poll_event(cx)).await {
|
let mut s = poll_fn(|cx| conn.poll_event(cx))
|
||||||
Ok(muxing::StreamMuxerEvent::InboundSubstream(mut s)) => {
|
.await
|
||||||
let mut buf = vec![0u8; payload_len];
|
.expect("unexpected error")
|
||||||
let mut off = 0;
|
.into_inbound_substream()
|
||||||
loop {
|
.expect("Unexpected muxer event");
|
||||||
// Read in typical chunk sizes of up to 8KiB.
|
|
||||||
let end = off + std::cmp::min(buf.len() - off, 8 * 1024);
|
let mut buf = vec![0u8; payload_len];
|
||||||
let n = poll_fn(|cx| {
|
let mut off = 0;
|
||||||
conn.read_substream(cx, &mut s, &mut buf[off..end])
|
loop {
|
||||||
})
|
// Read in typical chunk sizes of up to 8KiB.
|
||||||
.await
|
let end = off + std::cmp::min(buf.len() - off, 8 * 1024);
|
||||||
.unwrap();
|
let n = poll_fn(|cx| conn.read_substream(cx, &mut s, &mut buf[off..end]))
|
||||||
off += n;
|
.await
|
||||||
if off == buf.len() {
|
.unwrap();
|
||||||
return;
|
off += n;
|
||||||
}
|
if off == buf.len() {
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
Ok(_) => panic!("Unexpected muxer event"),
|
|
||||||
Err(e) => panic!("Unexpected error: {:?}", e),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => panic!("Unexpected listener event"),
|
_ => panic!("Unexpected listener event"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user