commit 77555a0e01b71ee148dc2a1b53f0e9b12e85859c
parent 56c72c5d0549c00c80b4da0f4b15d4777ea51b31
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 1 Jan 2026 12:48:50 +0000
extract common code into send_message method
Diffstat:
1 file changed, 19 insertions(+), 30 deletions(-)
diff --git a/ecu-esp32/src/wifi.rs b/ecu-esp32/src/wifi.rs
@@ -139,6 +139,23 @@ impl<'a> MdnsResponder<'a> {
}
}
+ async fn send_message(&self, message: Message<'_, '_>, endpoint: IpEndpoint) {
+ let mut data_buf = [0; 4096];
+ // Serialize the message into the buffer
+ assert!(message.space_needed() <= data_buf.len());
+
+ match message.write(&mut data_buf) {
+ Result::Ok(len) => {
+ if let Result::Err(x) = self.sock.send_to(&data_buf[..len], endpoint).await {
+ info!("sock.send failed: {:?}", x);
+ }
+ },
+ Result::Err(err) => {
+ error!("message.write {:?}", err);
+ }
+ };
+ }
+
async fn send_probe(&self) {
info!("sending probe at {}", Instant::now().as_millis());
@@ -167,20 +184,7 @@ impl<'a> MdnsResponder<'a> {
&mut [],
&mut []);
- let mut data_buf = [0; 4096];
- // Serialize the message into the buffer
- assert!(message.space_needed() <= data_buf.len());
-
- match message.write(&mut data_buf) {
- Result::Ok(len) => {
- if let Result::Err(x) = self.sock.send_to(&data_buf[..len], MDNS_ENDPOINT).await {
- info!("sock.send failed: {:?}", x);
- }
- },
- Result::Err(err) => {
- error!("message.write {:?}", err);
- }
- }
+ self.send_message(message, MDNS_ENDPOINT).await;
}
async fn advertise(&self) {
@@ -249,22 +253,7 @@ impl<'a> MdnsResponder<'a> {
&mut [],
&mut additional);
- let mut data_buf = [0; 4096];
- // Serialize the message into the buffer
- assert!(message.space_needed() <= data_buf.len());
-
- info!("ready to send to {:?}", endpoint);
-
- match message.write(&mut data_buf) {
- Result::Ok(len) => {
- if let Result::Err(x) = self.sock.send_to(&data_buf[..len], endpoint).await {
- info!("sock.send failed: {:?}", x);
- }
- },
- Result::Err(err) => {
- error!("message.write {:?}", err);
- }
- }
+ self.send_message(message, endpoint).await;
}
pub fn increment_serial(&mut self) {