• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rng-dynamics / ping-fox / 3861426833

pending completion
3861426833

Pull #19

github

GitHub
<a href="https://github.com/rng-dynamics/ping-fox/commit/<a class=hub.com/rng-dynamics/ping-fox/commit/08f4965244a8761edc80a7a0a76e4c49a3dc0b54">08f496524<a href="https://github.com/rng-dynamics/ping-fox/commit/08f4965244a8761edc80a7a0a76e4c49a3dc0b54">">Merge </a><a class="double-link" href="https://github.com/rng-dynamics/ping-fox/commit/<a class="double-link" href="https://github.com/rng-dynamics/ping-fox/commit/f3ad7b25b8822e68d3d10a5c961c065152050cbb">f3ad7b25b</a>">f3ad7b25b</a><a href="https://github.com/rng-dynamics/ping-fox/commit/08f4965244a8761edc80a7a0a76e4c49a3dc0b54"> into e61b23b64">e61b23b64</a>
Pull Request #19: feat: configurable socket types

78 of 78 new or added lines in 3 files covered. (100.0%)

606 of 678 relevant lines covered (89.38%)

3.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.44
/src/ping_data_buffer.rs
1
use std::collections::HashMap;
2
use std::net::IpAddr;
3
use std::time::Instant;
4

5
use crate::event::{
6
    PingReceiveEvent, PingReceiveEventData, PingReceiveEventReceiver, PingSendEvent,
7
    PingSendEventReceiver,
8
};
9
use crate::ping_output::{PingOutput, PingOutputSender};
10

11
pub(crate) struct PingDataBuffer {
12
    ping_send_event_rx: PingSendEventReceiver,
13
    ping_receive_event_rx: PingReceiveEventReceiver,
14

15
    ping_output_tx: PingOutputSender,
16
    // ping_output_rx: mpsc::Receiver<PingOutput>,
17
    send_events: HashMap<(u16, IpAddr), (usize, Instant)>,
18
}
19

20
impl PingDataBuffer {
21
    pub(crate) fn new(
2✔
22
        ping_send_event_rx: PingSendEventReceiver,
2✔
23
        ping_receive_event_rx: PingReceiveEventReceiver,
2✔
24
        ping_output_tx: PingOutputSender,
2✔
25
    ) -> Self {
2✔
26
        Self {
2✔
27
            ping_send_event_rx,
2✔
28
            ping_receive_event_rx,
2✔
29
            ping_output_tx,
2✔
30
            // ping_output_rx,
2✔
31
            send_events: HashMap::new(),
2✔
32
        }
2✔
33
    }
2✔
34
    pub(crate) fn update(&mut self) {
2✔
35
        self.process_send_events();
2✔
36
        self.process_receive_events();
2✔
37
    }
2✔
38

39
    fn process_send_events(&mut self) {
2✔
40
        while let Ok(send_event) = self.ping_send_event_rx.try_recv() {
4✔
41
            let PingSendEvent {
2✔
42
                payload_size,
2✔
43
                ip_addr,
2✔
44
                sequence_number,
2✔
45
                send_time,
2✔
46
            } = send_event;
2✔
47
            self.send_events
2✔
48
                .insert((sequence_number, ip_addr), (payload_size, send_time));
2✔
49
        }
2✔
50
    }
2✔
51

52
    fn process_receive_events(&mut self) {
2✔
53
        while let Ok(ping_receive_event) = self.ping_receive_event_rx.try_recv() {
4✔
54
            match ping_receive_event {
2✔
55
                PingReceiveEvent::Data(receive_data) => {
2✔
56
                    let PingReceiveEventData {
2✔
57
                        package_size,
2✔
58
                        ip_addr,
2✔
59
                        sequence_number,
2✔
60
                        receive_time,
2✔
61
                    } = receive_data;
2✔
62
                    match self.send_events.get(&(sequence_number, ip_addr)) {
2✔
63
                        None => {
64
                            tracing::error!("could not find matching data in send-events buffer");
×
65
                            // TODO
66
                        }
67
                        Some(&(_payload_size, send_time)) => {
2✔
68
                            let send_result = self.ping_output_tx.send(PingOutput {
2✔
69
                                package_size,
2✔
70
                                ip_addr,
2✔
71
                                sequence_number,
2✔
72
                                ping_duration: receive_time - send_time,
2✔
73
                            });
2✔
74
                            if let Err(e) = send_result {
2✔
75
                                tracing::error!("failed to send on PingOutput channel: {}", e);
×
76
                            }
2✔
77
                            self.send_events.remove(&(sequence_number, ip_addr));
2✔
78
                        }
79
                    }
80
                }
81
                PingReceiveEvent::Timeout => {
82
                    tracing::warn!("timeout");
×
83
                    // TODO
84
                }
85
            }
86
        }
87
    }
2✔
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc