pub struct HeartbeatTracker { /* private fields */ }Expand description
多连接心跳跟踪器
Implementations§
Source§impl HeartbeatTracker
impl HeartbeatTracker
pub fn new(config: HeartbeatConfig) -> Self
Sourcepub fn config(&self) -> &HeartbeatConfig
pub fn config(&self) -> &HeartbeatConfig
获取配置
Sourcepub async fn register_new(&self, connection_id: impl Into<String>)
pub async fn register_new(&self, connection_id: impl Into<String>)
注册一个连接(确保新建状态)
Sourcepub async fn unregister(&self, connection_id: &str) -> Option<HeartbeatState>
pub async fn unregister(&self, connection_id: &str) -> Option<HeartbeatState>
注销连接
Sourcepub async fn record_ping(&self, connection_id: &str, now_ms: i64) -> bool
pub async fn record_ping(&self, connection_id: &str, now_ms: i64) -> bool
记录发送 Ping
Sourcepub async fn record_pong(&self, connection_id: &str, now_ms: i64) -> bool
pub async fn record_pong(&self, connection_id: &str, now_ms: i64) -> bool
记录收到 Pong
Sourcepub async fn check_timeouts(&self, now_ms: i64) -> (Vec<String>, Vec<String>)
pub async fn check_timeouts(&self, now_ms: i64) -> (Vec<String>, Vec<String>)
检查所有连接的超时状态,返回 (本次新增超时的连接列表, 本次被判定为失活的连接列表)
Sourcepub async fn state(&self, connection_id: &str) -> Option<HeartbeatState>
pub async fn state(&self, connection_id: &str) -> Option<HeartbeatState>
获取指定连接的心跳状态
Sourcepub async fn dead_connections(&self) -> Vec<String>
pub async fn dead_connections(&self) -> Vec<String>
获取所有失活连接的 ID
Sourcepub async fn purge_dead(&self) -> usize
pub async fn purge_dead(&self) -> usize
清理所有失活连接,返回被清理的数量
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for HeartbeatTracker
impl !UnwindSafe for HeartbeatTracker
impl Freeze for HeartbeatTracker
impl Send for HeartbeatTracker
impl Sync for HeartbeatTracker
impl Unpin for HeartbeatTracker
impl UnsafeUnpin for HeartbeatTracker
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