Skip to content

Commit 5b1367f

Browse files
committed
Push on_disconnect down to SessionState
1 parent 77820f5 commit 5b1367f

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

crates/hotfix/src/session.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -333,21 +333,8 @@ where
333333
}
334334

335335
async fn on_disconnect(&mut self, reason: String) {
336-
let transition = match self.state {
337-
SessionState::Active(_)
338-
| SessionState::AwaitingLogon(_)
339-
| SessionState::AwaitingResend(_) => {
340-
self.state.disconnect_writer().await;
341-
TransitionResult::TransitionTo(SessionState::new_disconnected(true, &reason))
342-
}
343-
SessionState::Disconnected(_) => {
344-
warn!("disconnect message was received, but the session is already disconnected");
345-
TransitionResult::Stay
346-
}
347-
SessionState::AwaitingLogout(AwaitingLogoutState { reconnect, .. }) => {
348-
TransitionResult::TransitionTo(SessionState::new_disconnected(reconnect, &reason))
349-
}
350-
};
336+
self.state.disconnect_writer().await;
337+
let transition = self.state.on_disconnect(&reason);
351338
self.apply_transition(transition).await;
352339
}
353340

crates/hotfix/src/session/state.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ impl SessionState {
6363
})
6464
}
6565

66+
/// Returns the transition to apply when the transport layer reports a disconnect.
67+
/// Each state determines its own reconnect policy.
68+
pub(crate) fn on_disconnect(&self, reason: &str) -> TransitionResult {
69+
match self {
70+
Self::Active(_) | Self::AwaitingLogon(_) | Self::AwaitingResend(_) => {
71+
TransitionResult::TransitionTo(Self::new_disconnected(true, reason))
72+
}
73+
Self::AwaitingLogout(AwaitingLogoutState { reconnect, .. }) => {
74+
TransitionResult::TransitionTo(Self::new_disconnected(*reconnect, reason))
75+
}
76+
Self::Disconnected(_) => {
77+
warn!("disconnect message was received, but the session is already disconnected");
78+
TransitionResult::Stay
79+
}
80+
}
81+
}
82+
6683
/// Let the current state decide whether an inbound message should be processed,
6784
/// queued for later, or rejected before verification and dispatch.
6885
pub(crate) fn pre_process_inbound(&mut self, message: Message) -> PreProcessDecision {

0 commit comments

Comments
 (0)