pub struct ConnectionStateMachine { /* private fields */ }Expand description
Connection state machine managing the lifecycle of a network connection.
Implementations§
Source§impl ConnectionStateMachine
impl ConnectionStateMachine
pub fn new(config: TransportConfig) -> Self
pub fn state(&self) -> ConnectionState
pub fn is_connected(&self) -> bool
pub fn session_id(&self) -> u64
Sourcepub fn on_accepted(&mut self, now: Instant)
pub fn on_accepted(&mut self, now: Instant)
Handle acceptance of our connection.
Sourcepub fn on_packet_received(&mut self, now: Instant)
pub fn on_packet_received(&mut self, now: Instant)
Handle an incoming packet (any type) to update keep-alive tracking.
Sourcepub fn on_packet_sent(&mut self, now: Instant)
pub fn on_packet_sent(&mut self, now: Instant)
Mark that we sent a packet.
Sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
Initiate graceful disconnection.
Sourcepub fn on_disconnect_complete(&mut self)
pub fn on_disconnect_complete(&mut self)
Complete disconnection (after sending disconnect packet).
Sourcepub fn on_remote_disconnect(&mut self, reason: DisconnectReason)
pub fn on_remote_disconnect(&mut self, reason: DisconnectReason)
Handle remote disconnect.
Sourcepub fn update(&mut self, now: Instant) -> bool
pub fn update(&mut self, now: Instant) -> bool
Tick the state machine. Returns true if a connect retry is needed.
Sourcepub fn needs_keepalive(&self) -> bool
pub fn needs_keepalive(&self) -> bool
Whether a keepalive should be sent.
Sourcepub fn drain_events(&mut self) -> Vec<ConnectionEvent>
pub fn drain_events(&mut self) -> Vec<ConnectionEvent>
Drain pending events.
Sourcepub fn force_disconnect(&mut self, reason: DisconnectReason)
pub fn force_disconnect(&mut self, reason: DisconnectReason)
Force transition to disconnected.
pub fn reset(&mut self)
Sourcepub fn time_since_last_received(&self, now: Instant) -> Option<Duration>
pub fn time_since_last_received(&self, now: Instant) -> Option<Duration>
Time since last received packet.
Auto Trait Implementations§
impl Freeze for ConnectionStateMachine
impl RefUnwindSafe for ConnectionStateMachine
impl Send for ConnectionStateMachine
impl Sync for ConnectionStateMachine
impl Unpin for ConnectionStateMachine
impl UnsafeUnpin for ConnectionStateMachine
impl UnwindSafe for ConnectionStateMachine
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.