Skip to content

Commit

Permalink
Merge pull request bparli#35 from rcloran/destructure
Browse files Browse the repository at this point in the history
Destructure ReceivedPing without match
  • Loading branch information
bparli authored Sep 7, 2023
2 parents be5ed3a + d836be7 commit 431e2bb
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions src/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,40 +134,34 @@ pub fn send_pings(
.recv_timeout(Duration::from_millis(100))
{
Ok(ping_result) => {
match ping_result {
ReceivedPing {
addr,
identifier,
sequence_number,
rtt: _,
} => {
// Update the address to the ping response being received
if let Some(ping) = targets.lock().unwrap().get_mut(&addr) {
if ping.get_identifier() == identifier
&& ping.get_sequence_number() == sequence_number
{
ping.seen = true;
// Send the ping result over the client channel
match results_sender.send(PingResult::Receive {
addr: ping_result.addr,
rtt: ping_result.rtt,
}) {
Ok(_) => {}
Err(e) => {
if !*stop.lock().unwrap() {
error!(
"Error sending ping result on channel: {}",
e
)
}
}
// match ping_result {
let ReceivedPing {
addr,
identifier,
sequence_number,
rtt: _,
} = ping_result;
// Update the address to the ping response being received
if let Some(ping) = targets.lock().unwrap().get_mut(&addr) {
if ping.get_identifier() == identifier
&& ping.get_sequence_number() == sequence_number
{
ping.seen = true;
// Send the ping result over the client channel
match results_sender.send(PingResult::Receive {
addr: ping_result.addr,
rtt: ping_result.rtt,
}) {
Ok(_) => {}
Err(e) => {
if !*stop.lock().unwrap() {
error!("Error sending ping result on channel: {}", e)
}
} else {
debug!("Received echo reply from target {}, but sequence_number (expected {} but got {}) and identifier (expected {} but got {}) don't match", addr, ping.get_sequence_number(), sequence_number, ping.get_identifier(), identifier);
}
}
} else {
debug!("Received echo reply from target {}, but sequence_number (expected {} but got {}) and identifier (expected {} but got {}) don't match", addr, ping.get_sequence_number(), sequence_number, ping.get_identifier(), identifier);
}
_ => {}
}
}
Err(_) => {
Expand Down

0 comments on commit 431e2bb

Please sign in to comment.