pub struct ConnectionHealth {
pub last_rx: Instant,
pub rtt: Option<Duration>,
pub seq_gaps: u64,
}Expand description
Receive-side health signals of one connection.
§Examples
use std::time::{Duration, Instant};
use brokapi_runtime::{ConnectionHealth, HealthClass};
let t0 = Instant::now();
let mut health = ConnectionHealth::new(t0);
let (degraded_after, dead_after) = (Duration::from_secs(15), Duration::from_secs(60));
assert_eq!(health.classify(t0 + Duration::from_secs(5), dead_after, degraded_after), HealthClass::Healthy);
assert_eq!(health.classify(t0 + Duration::from_secs(20), dead_after, degraded_after), HealthClass::Degraded);
assert_eq!(health.classify(t0 + Duration::from_secs(60), dead_after, degraded_after), HealthClass::Dead);
// A frame arrives: the silence timer restarts.
health.on_rx(t0 + Duration::from_secs(61));
assert_eq!(health.classify(t0 + Duration::from_secs(62), dead_after, degraded_after), HealthClass::Healthy);Fields§
§last_rx: InstantWhen the last frame arrived. Starts at the creation time.
rtt: Option<Duration>Round-trip time of the last ping, if the owner measures it. The runtime does not fill it.
seq_gaps: u64Number of sequence gaps seen on this connection. The runtime does not count them by itself.
Implementations§
Source§impl ConnectionHealth
impl ConnectionHealth
Sourcepub fn new(now: Instant) -> Self
pub fn new(now: Instant) -> Self
Creates the health record of a connection that is considered just heard from at now.
Sourcepub fn classify(
&self,
now: Instant,
dead_after: Duration,
degraded_after: Duration,
) -> HealthClass
pub fn classify( &self, now: Instant, dead_after: Duration, degraded_after: Duration, ) -> HealthClass
Classifies the connection by the time since the last frame.
Silence of dead_after or more gives HealthClass::Dead. Silence of degraded_after or
more gives HealthClass::Degraded. Otherwise HealthClass::Healthy. The caller should
pass degraded_after < dead_after, otherwise a connection is never reported as degraded.
A now earlier than last_rx counts as no silence.
Trait Implementations§
Source§impl Clone for ConnectionHealth
impl Clone for ConnectionHealth
Source§fn clone(&self) -> ConnectionHealth
fn clone(&self) -> ConnectionHealth
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ConnectionHealth
impl RefUnwindSafe for ConnectionHealth
impl Send for ConnectionHealth
impl Sync for ConnectionHealth
impl Unpin for ConnectionHealth
impl UnsafeUnpin for ConnectionHealth
impl UnwindSafe for ConnectionHealth
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more