@@ -24,7 +24,11 @@ pub enum SessionState {
2424 /// We are awaiting the target to resend the gap we have.
2525 AwaitingResend ( AwaitingResendState ) ,
2626 /// We are in the process of gracefully logging out
27- AwaitingLogout { writer : WriterRef } , // we need the writer so we can disconnect it on successful logout
27+ AwaitingLogout {
28+ writer : WriterRef , // we need the writer so we can disconnect it on successful logout
29+ logout_timeout : Instant ,
30+ reconnect : bool , // we carry this forward for the subsequent disconnected state
31+ } ,
2832 /// The session is active, we have connected and mutually logged on.
2933 Active ( ActiveState ) ,
3034 /// The TCP connection has been dropped.
@@ -87,7 +91,7 @@ impl SessionState {
8791 _ => error ! ( "invalid outgoing message for AwaitingLogon state" ) ,
8892 }
8993 }
90- Self :: AwaitingLogout { writer } => {
94+ Self :: AwaitingLogout { writer, .. } => {
9195 // Logout messages are allowed because we first transition into AwaitingLogout
9296 // and only then send the logout message
9397 if message_type == b"5" {
@@ -102,7 +106,7 @@ impl SessionState {
102106 match self {
103107 Self :: Active ( ActiveState { writer, .. } )
104108 | Self :: AwaitingLogon { writer, .. }
105- | Self :: AwaitingLogout { writer }
109+ | Self :: AwaitingLogout { writer, .. }
106110 | Self :: AwaitingResend ( AwaitingResendState { writer, .. } ) => writer. disconnect ( ) . await ,
107111 _ => debug ! ( "disconnecting an already disconnected session" ) ,
108112 }
@@ -112,13 +116,17 @@ impl SessionState {
112116 match self {
113117 Self :: Active ( ActiveState { writer, .. } )
114118 | Self :: AwaitingLogon { writer, .. }
115- | Self :: AwaitingLogout { writer }
119+ | Self :: AwaitingLogout { writer, .. }
116120 | Self :: AwaitingResend ( AwaitingResendState { writer, .. } ) => Some ( writer) ,
117121 _ => None ,
118122 }
119123 }
120124
121- pub fn try_transition_to_awaiting_logout ( & mut self ) -> bool {
125+ pub fn try_transition_to_awaiting_logout (
126+ & mut self ,
127+ logout_timeout : Duration ,
128+ reconnect : bool ,
129+ ) -> bool {
122130 if matches ! ( self , SessionState :: AwaitingLogout { .. } ) {
123131 debug ! ( "already in awaiting logout state" ) ;
124132 return false ;
@@ -127,6 +135,8 @@ impl SessionState {
127135 if let Some ( writer) = self . get_writer ( ) {
128136 * self = SessionState :: AwaitingLogout {
129137 writer : writer. clone ( ) ,
138+ logout_timeout : Instant :: now ( ) + logout_timeout,
139+ reconnect,
130140 } ;
131141 true
132142 } else {
@@ -220,6 +230,7 @@ impl SessionState {
220230 match self {
221231 Self :: Active ( ActiveState { peer_deadline, .. } ) => Some ( peer_deadline) ,
222232 Self :: AwaitingLogon { logon_timeout, .. } => Some ( logon_timeout) ,
233+ Self :: AwaitingLogout { logout_timeout, .. } => Some ( logout_timeout) ,
223234 _ => None ,
224235 }
225236 }
@@ -268,6 +279,10 @@ impl SessionState {
268279 matches ! ( self , SessionState :: AwaitingLogon { .. } )
269280 }
270281
282+ pub fn is_awaiting_logout ( & self ) -> bool {
283+ matches ! ( self , SessionState :: AwaitingLogout { .. } )
284+ }
285+
271286 pub fn as_status ( & self ) -> SessionInfoStatus {
272287 match self {
273288 SessionState :: AwaitingLogon { .. } => SessionInfoStatus :: AwaitingLogon ,
@@ -427,6 +442,8 @@ mod tests {
427442 fn test_awaiting_resend_transition_when_awaiting_logout_is_prevented ( ) {
428443 let mut state = SessionState :: AwaitingLogout {
429444 writer : create_writer_ref ( ) ,
445+ logout_timeout : Instant :: now ( ) ,
446+ reconnect : false ,
430447 } ;
431448
432449 let result = state. try_transition_to_awaiting_resend ( 1 , 5 ) ;
0 commit comments