pub struct HeartbeatState {
pub connection_id: String,
pub last_ping_at: Option<i64>,
pub last_pong_at: Option<i64>,
pub missed_count: u32,
pub total_pings: u64,
pub total_pongs: u64,
pub is_dead: bool,
}Expand description
单连接的心跳状态
Fields§
§connection_id: String连接 ID
last_ping_at: Option<i64>上次发送 Ping 的时间戳(毫秒),None 表示尚未发送
last_pong_at: Option<i64>上次收到 Pong 的时间戳(毫秒)
missed_count: u32连续未收到 Pong 的次数
total_pings: u64总共发送的 Ping 次数
total_pongs: u64总共收到的 Pong 次数
is_dead: bool是否被判定为失活
Implementations§
Source§impl HeartbeatState
impl HeartbeatState
pub fn new(connection_id: impl Into<String>) -> Self
Sourcepub fn record_ping(&mut self, now_ms: i64)
pub fn record_ping(&mut self, now_ms: i64)
记录发送了一次 Ping
Sourcepub fn record_pong(&mut self, now_ms: i64) -> bool
pub fn record_pong(&mut self, now_ms: i64) -> bool
记录收到了一次 Pong。返回是否清除了未应答计数。
Sourcepub fn check_timeout(&mut self, now_ms: i64, config: &HeartbeatConfig) -> bool
pub fn check_timeout(&mut self, now_ms: i64, config: &HeartbeatConfig) -> bool
检查是否超时未收到 Pong。 返回 true 表示本次检查新增了一次未应答。
Sourcepub fn awaiting_pong(&self) -> bool
pub fn awaiting_pong(&self) -> bool
是否正在等待 Pong 应答
Trait Implementations§
Source§impl Clone for HeartbeatState
impl Clone for HeartbeatState
Source§fn clone(&self) -> HeartbeatState
fn clone(&self) -> HeartbeatState
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 HeartbeatState
impl RefUnwindSafe for HeartbeatState
impl Send for HeartbeatState
impl Sync for HeartbeatState
impl Unpin for HeartbeatState
impl UnsafeUnpin for HeartbeatState
impl UnwindSafe for HeartbeatState
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