send a lot of hello worlds

This commit is contained in:
Milo Turner 2020-03-08 01:29:23 -05:00
parent 15b865a803
commit 3118726d81
1 changed files with 17 additions and 3 deletions

View File

@ -65,11 +65,25 @@ fn parse_args(mut args: impl Iterator<Item = String>) -> Result<SocketAddrV4, Er
}
async fn upload(
_log: &mut Logger,
log: &mut Logger,
mut sock: tokio::net::UdpSocket,
targ_addr: SocketAddrV4,
) -> Result<(), Error> {
sock.send_to("Hello, ".as_bytes(), targ_addr).await?;
sock.send_to("world!".as_bytes(), targ_addr).await?;
let contents: String = (0..100).flat_map(|_| "Hello world ".chars()).collect();
for i in 0.. {
let (idx, part) = {
let width = 50;
let lo = i * width;
let hi = std::cmp::min((i + 1) * width, contents.len());
if lo >= contents.len() {
break;
};
(lo, &contents[lo..hi])
};
sock.send_to(part.as_bytes(), targ_addr).await?;
log.send_data(idx, part.len()).await;
}
Ok(())
}