@@ -348,7 +348,7 @@ public virtual bool Send(Message message)
348348 {
349349 message . Header . RemoveField ( Fields . Tags . PossDupFlag ) ;
350350 message . Header . RemoveField ( Fields . Tags . OrigSendingTime ) ;
351- return SendRaw ( message , 0 ) ;
351+ return SendRaw ( message ) ;
352352 }
353353
354354 /// <summary>
@@ -948,8 +948,19 @@ public bool Verify(Message msg, bool checkTooHigh = true, bool checkTooLow = tru
948948 else if ( msgSeqNum >= range . ChunkEndSeqNo )
949949 {
950950 Log . OnEvent ( "Chunked ResendRequest for messages FROM: " + range . BeginSeqNo + " TO: " + range . ChunkEndSeqNo + " has been satisfied." ) ;
951+ SeqNumType newStart = range . ChunkEndSeqNo + 1 ;
951952 SeqNumType newChunkEndSeqNo = Math . Min ( range . EndSeqNo , range . ChunkEndSeqNo + MaxMessagesInResendRequest ) ;
952- GenerateResendRequestRange ( msg . Header . GetString ( Tags . BeginString ) , range . ChunkEndSeqNo + 1 , newChunkEndSeqNo ) ;
953+
954+ Message resendRequest = CreateResendRequest ( msg . Header . GetString ( Tags . BeginString ) ,
955+ newStart , newChunkEndSeqNo ) ;
956+ if ( EnableLastMsgSeqNumProcessed )
957+ resendRequest . Header . SetField ( new LastMsgSeqNumProcessed ( msgSeqNum ) ) ;
958+
959+ if ( SendRaw ( resendRequest ) )
960+ Log . OnEvent ( $ "Sent ResendRequest FROM: { newStart } TO: { newChunkEndSeqNo } ") ;
961+ else
962+ Log . OnEvent ( $ "Error sending ResendRequest ({ newStart } , { newChunkEndSeqNo } )") ;
963+
953964 range . ChunkEndSeqNo = newChunkEndSeqNo ;
954965 }
955966 }
@@ -1145,28 +1156,18 @@ protected void GenerateBusinessMessageReject(Message message, int err, int field
11451156
11461157 reject . SetField ( new Text ( reason ) ) ;
11471158 Log . OnEvent ( "Reject sent for Message: " + msgSeqNum + " Reason:" + reason ) ;
1148- SendRaw ( reject , 0 ) ;
1159+ SendRaw ( reject ) ;
11491160 }
11501161
1151- protected bool GenerateResendRequestRange ( string beginString , SeqNumType startSeqNum , SeqNumType endSeqNum )
1162+ private Message CreateResendRequest ( string beginString , SeqNumType startSeqNum , SeqNumType endSeqNum )
11521163 {
11531164 Message resendRequest = _msgFactory . Create ( beginString , MsgType . RESEND_REQUEST ) ;
1154-
1155- resendRequest . SetField ( new Fields . BeginSeqNo ( startSeqNum ) ) ;
1156- resendRequest . SetField ( new Fields . EndSeqNo ( endSeqNum ) ) ;
1157-
1165+ resendRequest . SetField ( new BeginSeqNo ( startSeqNum ) ) ;
1166+ resendRequest . SetField ( new EndSeqNo ( endSeqNum ) ) ;
11581167 InitializeHeader ( resendRequest ) ;
1159- if ( SendRaw ( resendRequest , 0 ) )
1160- {
1161- Log . OnEvent ( "Sent ResendRequest FROM: " + startSeqNum + " TO: " + endSeqNum ) ;
1162- return true ;
1163- }
1164-
1165- Log . OnEvent ( "Error sending ResendRequest (" + startSeqNum + " ," + endSeqNum + ")" ) ;
1166- return false ;
1168+ return resendRequest ;
11671169 }
11681170
1169- // internal so it can be unit tested
11701171 internal void GenerateResendRequest ( string beginString , SeqNumType msgSeqNum )
11711172 {
11721173 SeqNumType beginSeqNum = _state . NextTargetMsgSeqNum ;
@@ -1185,18 +1186,26 @@ internal void GenerateResendRequest(string beginString, SeqNumType msgSeqNum)
11851186 endChunkSeqNum = endRangeSeqNum ;
11861187 }
11871188
1188- if ( ! GenerateResendRequestRange ( beginString , beginSeqNum , endChunkSeqNum ) ) {
1189+ Message resendRequest = CreateResendRequest ( beginString , beginSeqNum , endChunkSeqNum ) ;
1190+
1191+ if ( EnableLastMsgSeqNumProcessed )
1192+ resendRequest . Header . SetField ( new LastMsgSeqNumProcessed ( msgSeqNum ) ) ;
1193+
1194+ if ( SendRaw ( resendRequest ) )
1195+ {
1196+ Log . OnEvent ( $ "Sent ResendRequest FROM: { beginSeqNum } TO: { endChunkSeqNum } ") ;
1197+ _state . SetResendRange ( beginSeqNum , endRangeSeqNum , endChunkSeqNum ) ;
11891198 return ;
11901199 }
11911200
1192- _state . SetResendRange ( beginSeqNum , endRangeSeqNum , endChunkSeqNum ) ;
1201+ Log . OnEvent ( "Error sending ResendRequest (" + beginSeqNum + " ," + endChunkSeqNum + ")" ) ;
11931202 }
11941203
11951204 /// <summary>
11961205 /// Create and send a logon
11971206 /// </summary>
11981207 /// <returns>true of logon was successfully sent</returns>
1199- protected bool GenerateLogon ( )
1208+ internal bool GenerateLogon ( )
12001209 {
12011210 Message logon = _msgFactory . Create ( SessionID . BeginString , Fields . MsgType . LOGON ) ;
12021211 logon . SetField ( new Fields . EncryptMethod ( 0 ) ) ;
@@ -1214,7 +1223,7 @@ protected bool GenerateLogon()
12141223 InitializeHeader ( logon ) ;
12151224 _state . LastReceivedTimeDT = DateTime . UtcNow ;
12161225 _state . TestRequestCounter = 0 ;
1217- _state . SentLogon = SendRaw ( logon , 0 ) ;
1226+ _state . SentLogon = SendRaw ( logon ) ;
12181227 return _state . SentLogon ;
12191228 }
12201229
@@ -1230,7 +1239,7 @@ protected bool GenerateLogon(Message otherLogon)
12301239 logon . Header . SetField ( new Fields . LastMsgSeqNumProcessed ( otherLogon . Header . GetULong ( Tags . MsgSeqNum ) ) ) ;
12311240
12321241 InitializeHeader ( logon ) ;
1233- _state . SentLogon = SendRaw ( logon , 0 ) ;
1242+ _state . SentLogon = SendRaw ( logon ) ;
12341243 return _state . SentLogon ;
12351244 }
12361245
@@ -1239,7 +1248,7 @@ public void GenerateTestRequest(string id)
12391248 Message testRequest = _msgFactory . Create ( SessionID . BeginString , Fields . MsgType . TEST_REQUEST ) ;
12401249 InitializeHeader ( testRequest ) ;
12411250 testRequest . SetField ( new Fields . TestReqID ( id ) ) ;
1242- SendRaw ( testRequest , 0 ) ;
1251+ SendRaw ( testRequest ) ;
12431252 }
12441253
12451254 /// <summary>
@@ -1294,14 +1303,14 @@ private void ImplGenerateLogout(Message? other = null, string? text = null)
12941303 Log . OnEvent ( "Error: No message sequence number: " + other ) ;
12951304 }
12961305 }
1297- _state . SentLogout = SendRaw ( logout , 0 ) ;
1306+ _state . SentLogout = SendRaw ( logout ) ;
12981307 }
12991308
13001309 public void GenerateHeartbeat ( )
13011310 {
13021311 Message heartbeat = _msgFactory . Create ( SessionID . BeginString , Fields . MsgType . HEARTBEAT ) ;
13031312 InitializeHeader ( heartbeat ) ;
1304- SendRaw ( heartbeat , 0 ) ;
1313+ SendRaw ( heartbeat ) ;
13051314 }
13061315
13071316 public void GenerateHeartbeat ( Message testRequest )
@@ -1318,7 +1327,7 @@ public void GenerateHeartbeat(Message testRequest)
13181327 }
13191328 catch ( FieldNotFoundException )
13201329 { }
1321- SendRaw ( heartbeat , 0 ) ;
1330+ SendRaw ( heartbeat ) ;
13221331 }
13231332
13241333 internal void GenerateReject ( MessageBuilder msgBuilder , FixValues . SessionRejectReason reason , int field )
@@ -1391,7 +1400,7 @@ public void GenerateReject(Message message, FixValues.SessionRejectReason reason
13911400 if ( ! _state . ReceivedLogon )
13921401 throw new QuickFIXException ( "Tried to send a reject while not logged on" ) ;
13931402
1394- SendRaw ( reject , 0 ) ;
1403+ SendRaw ( reject ) ;
13951404 }
13961405
13971406 protected void PopulateSessionRejectReason ( Message reject , int field , string text , bool includeFieldInfo )
@@ -1541,7 +1550,13 @@ private static bool IsAdminMessage(Message msg)
15411550 return AdminMsgTypes . Contains ( msgType ) ;
15421551 }
15431552
1544- protected bool SendRaw ( Message message , SeqNumType seqNum )
1553+ /// <summary>
1554+ /// Update the header as needed and send the message
1555+ /// </summary>
1556+ /// <param name="message"></param>
1557+ /// <param name="seqNum">if non-zero, set this seqno in the message (else leave existing value alone)</param>
1558+ /// <returns></returns>
1559+ protected bool SendRaw ( Message message , SeqNumType seqNum = 0UL )
15451560 {
15461561 lock ( _sync )
15471562 {
@@ -1586,7 +1601,7 @@ protected bool SendRaw(Message message, SeqNumType seqNum)
15861601 }
15871602
15881603 string messageString = message . ConstructString ( ) ;
1589- if ( 0 == seqNum )
1604+ if ( 0UL == seqNum )
15901605 Persist ( message , messageString ) ;
15911606 return Send ( messageString ) ;
15921607 }
0 commit comments