@@ -31,7 +31,7 @@ use crate::message::sequence_reset::SequenceReset;
3131use crate :: message:: test_request:: TestRequest ;
3232use crate :: message_utils:: is_admin;
3333use crate :: session:: event:: AwaitingActiveSessionResponse ;
34- use crate :: session:: state:: AwaitingResendState ;
34+ use crate :: session:: state:: { AwaitingResendState , TestRequestId } ;
3535use crate :: session_schedule:: SessionSchedule ;
3636use event:: SessionEvent ;
3737use hotfix_message:: parsed_message:: ParsedMessage ;
@@ -44,8 +44,6 @@ pub struct SessionRef<M> {
4444 sender : mpsc:: Sender < SessionEvent < M > > ,
4545}
4646
47- type TestRequestId = String ;
48-
4947impl < M : FixMessage > SessionRef < M > {
5048 pub fn new (
5149 config : SessionConfig ,
@@ -117,7 +115,6 @@ struct Session<M, S> {
117115 state : SessionState ,
118116 application : ApplicationRef < M > ,
119117 store : S ,
120- awaiting_test_response : Option < TestRequestId > ,
121118 schedule_check_timer : Pin < Box < Sleep > > ,
122119}
123120
@@ -142,7 +139,6 @@ impl<M: FixMessage, S: MessageStore> Session<M, S> {
142139 state : SessionState :: new_disconnected ( true , "initialising" ) ,
143140 application,
144141 store,
145- awaiting_test_response : None ,
146142 schedule_check_timer : Box :: pin ( schedule_check_timer) ,
147143 }
148144 }
@@ -159,7 +155,7 @@ impl<M: FixMessage, S: MessageStore> Session<M, S> {
159155
160156 async fn on_incoming ( & mut self , raw_message : RawFixMessage ) -> Result < ( ) > {
161157 debug ! ( "received message: {}" , raw_message) ;
162- if self . awaiting_test_response . is_none ( ) {
158+ if ! self . state . is_expecting_test_response ( ) {
163159 // if we are not awaiting a specific test response, any message can reset the timer
164160 // otherwise, only a heartbeat with the corresponding TestReqID can
165161 self . reset_peer_timer ( None ) ;
@@ -398,7 +394,7 @@ impl<M: FixMessage, S: MessageStore> Session<M, S> {
398394
399395 async fn on_heartbeat ( & mut self , message : & Message ) {
400396 if let ( Some ( expected_req_id) , Ok ( message_req_id) ) = (
401- & self . awaiting_test_response ,
397+ & self . state . expected_test_response_id ( ) ,
402398 message. get :: < & str > ( fix44:: TEST_REQ_ID ) ,
403399 ) {
404400 if expected_req_id. as_str ( ) == message_req_id {
@@ -536,9 +532,9 @@ impl<M: FixMessage, S: MessageStore> Session<M, S> {
536532 . reset_heartbeat_timer ( self . config . heartbeat_interval ) ;
537533 }
538534
539- fn reset_peer_timer ( & mut self , awaiting_req_id : Option < TestRequestId > ) {
540- self . awaiting_test_response = awaiting_req_id ;
541- self . state . reset_peer_timer ( self . config . heartbeat_interval ) ;
535+ fn reset_peer_timer ( & mut self , test_request_id : Option < TestRequestId > ) {
536+ self . state
537+ . reset_peer_timer ( self . config . heartbeat_interval , test_request_id ) ;
542538 }
543539
544540 async fn send_message ( & mut self , message : impl FixMessage ) {
@@ -651,7 +647,7 @@ impl<M: FixMessage, S: MessageStore> Session<M, S> {
651647 }
652648
653649 async fn handle_peer_timeout ( & mut self ) {
654- if self . awaiting_test_response . is_some ( ) {
650+ if self . state . is_expecting_test_response ( ) {
655651 warn ! ( "peer didn't respond, terminating.." ) ;
656652 self . logout_and_terminate ( "peer timeout" ) . await ;
657653 } else {
0 commit comments