Skip to content

Commit

Permalink
add capability to send bulk commands via udp
Browse files Browse the repository at this point in the history
  • Loading branch information
lilioid committed Mar 26, 2024
1 parent a7f6348 commit df070a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,10 @@ where
.write_all(buf.get_ref())
.await
.expect("Could not write commands to server"),
_ => panic!("Chosen client implementation can only send one command at a time"),
DynClient::Udp(udp) => udp
.send_bulk(buf.get_ref())
.await
.expect("Could not send commands to server"),
}

// abort loop if only one iteration is requested
Expand Down
10 changes: 10 additions & 0 deletions src/net/clients/udp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ impl UdpClient {
let response = self.await_response().await?;
Ok(response)
}

/// Send pre-encoded commands in bulk
///
/// Note that because UDP is an unreliable transport mechanism, not all bytes might actually be sent.
/// If the buffer size is larger than the maximum size supported by UDP or the maximum transmission unit of the
/// underlying network layer, the packet might even be discarded completely.
pub async fn send_bulk(&mut self, buf: &[u8]) -> std::io::Result<()> {
let _ = self.socket.send(buf).await?;
Ok(())
}
}

0 comments on commit df070a0

Please sign in to comment.