@@ -451,8 +451,7 @@ static MQTTStatus_t handleUncleanSessionResumption( MQTTContext_t * pContext );
451451 *
452452 * @param[in] pContext Initialized MQTT context.
453453 *
454- * @return #MQTTPublishClearAllFailed if clearing all the copied publishes fails;
455- * #MQTTSuccess otherwise.
454+ * @return #MQTTSuccess always otherwise.
456455 */
457456static MQTTStatus_t handleCleanSession ( MQTTContext_t * pContext );
458457
@@ -1609,10 +1608,9 @@ static MQTTStatus_t handlePublishAcks( MQTTContext_t * pContext,
16091608 if ( ( ackType == MQTTPuback ) || ( ackType == MQTTPubrec ) )
16101609 {
16111610 if ( ( status == MQTTSuccess ) &&
1612- ( pContext -> clearFunction != NULL ) &&
1613- ( pContext -> clearFunction ( pContext , packetIdentifier ) != true ) )
1611+ ( pContext -> clearFunction != NULL ) )
16141612 {
1615- LogWarn ( ( "Failed to clear copied publish on receiving an ack.\n" ) );
1613+ pContext -> clearFunction ( pContext , packetIdentifier );
16161614 }
16171615 }
16181616
@@ -2584,6 +2582,8 @@ static MQTTStatus_t handleUncleanSessionResumption( MQTTContext_t * pContext )
25842582static MQTTStatus_t handleCleanSession ( MQTTContext_t * pContext )
25852583{
25862584 MQTTStatus_t status = MQTTSuccess ;
2585+ MQTTStateCursor_t cursor = MQTT_STATE_CURSOR_INITIALIZER ;
2586+ uint16_t packetId = MQTT_PACKET_ID_INVALID ;
25872587
25882588 assert ( pContext != NULL );
25892589
@@ -2606,10 +2606,22 @@ static MQTTStatus_t handleCleanSession( MQTTContext_t * pContext )
26062606 pContext -> incomingPublishRecordMaxCount * sizeof ( * pContext -> incomingPublishRecords ) );
26072607 }
26082608
2609- if ( ( pContext -> clearAllFunction != NULL ) &&
2610- ( pContext -> clearAllFunction ( pContext ) != true ) )
2609+ if ( pContext -> clearFunction != NULL )
26112610 {
2612- status = MQTTPublishClearAllFailed ;
2611+ cursor = MQTT_STATE_CURSOR_INITIALIZER ;
2612+
2613+ /* Resend all the PUBLISH for which PUBACK/PUBREC is not received
2614+ * after session is reestablished. */
2615+ do
2616+ {
2617+ packetId = MQTT_PublishToResend ( pContext , & cursor );
2618+
2619+ if ( packetId != MQTT_PACKET_ID_INVALID )
2620+ {
2621+ pContext -> clearFunction ( pContext , packetId );
2622+ }
2623+ } while ( ( packetId != MQTT_PACKET_ID_INVALID ) &&
2624+ ( status == MQTTSuccess ) );
26132625 }
26142626
26152627 return status ;
@@ -2780,8 +2792,7 @@ MQTTStatus_t MQTT_InitStatefulQoS( MQTTContext_t * pContext,
27802792MQTTStatus_t MQTT_InitRetransmits ( MQTTContext_t * pContext ,
27812793 MQTTStorePacketForRetransmit storeFunction ,
27822794 MQTTRetrievePacketForRetransmit retrieveFunction ,
2783- MQTTClearPacketForRetransmit clearFunction ,
2784- MQTTClearAllPacketsForRetransmit clearAllFunction )
2795+ MQTTClearPacketForRetransmit clearFunction )
27852796{
27862797 MQTTStatus_t status = MQTTSuccess ;
27872798
@@ -2806,17 +2817,11 @@ MQTTStatus_t MQTT_InitRetransmits( MQTTContext_t * pContext,
28062817 LogError ( ( "Invalid parameter: clearFunction is NULL" ) );
28072818 status = MQTTBadParameter ;
28082819 }
2809- else if ( clearAllFunction == NULL )
2810- {
2811- LogError ( ( "Invalid parameter: clearAllFunction is NULL" ) );
2812- status = MQTTBadParameter ;
2813- }
28142820 else
28152821 {
28162822 pContext -> storeFunction = storeFunction ;
28172823 pContext -> retrieveFunction = retrieveFunction ;
28182824 pContext -> clearFunction = clearFunction ;
2819- pContext -> clearAllFunction = clearAllFunction ;
28202825 }
28212826
28222827 return status ;
@@ -3711,10 +3716,6 @@ const char * MQTT_Status_strerror( MQTTStatus_t status )
37113716 str = "MQTTPublishRetrieveFailed" ;
37123717 break ;
37133718
3714- case MQTTPublishClearAllFailed :
3715- str = "MQTTPublishClearAllFailed" ;
3716- break ;
3717-
37183719 default :
37193720 str = "Invalid MQTT Status code" ;
37203721 break ;
0 commit comments