Skip to content

Commit e5834d8

Browse files
author
Dakshit Babbar
committed
Clear publish copy after state update on receiving ACK
1 parent 853b6f4 commit e5834d8

File tree

3 files changed

+14
-31
lines changed

3 files changed

+14
-31
lines changed

source/core_mqtt.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,16 +1573,6 @@ static MQTTStatus_t handlePublishAcks( MQTTContext_t * pContext,
15731573
status = MQTT_DeserializeAck( pIncomingPacket, &packetIdentifier, NULL );
15741574
LogInfo( ( "Ack packet deserialized with result: %s.",
15751575
MQTT_Status_strerror( status ) ) );
1576-
1577-
if( ( ackType == MQTTPuback ) || ( ackType == MQTTPubrec ) )
1578-
{
1579-
if( ( status == MQTTSuccess ) &&
1580-
( pContext->clearFunction != NULL ) &&
1581-
( pContext->clearFunction( pContext, packetIdentifier) != true ) )
1582-
{
1583-
status = MQTTPublishClearFailed;
1584-
}
1585-
}
15861576

15871577
if( status == MQTTSuccess )
15881578
{
@@ -1610,6 +1600,16 @@ static MQTTStatus_t handlePublishAcks( MQTTContext_t * pContext,
16101600
}
16111601
}
16121602

1603+
if( ( ackType == MQTTPuback ) || ( ackType == MQTTPubrec ) )
1604+
{
1605+
if( ( status == MQTTSuccess ) &&
1606+
( pContext->clearFunction != NULL ) &&
1607+
( pContext->clearFunction( pContext, packetIdentifier) != true ) )
1608+
{
1609+
LogWarn( ( "Clear callback function failed\n" ) );
1610+
}
1611+
}
1612+
16131613
if( status == MQTTSuccess )
16141614
{
16151615
/* Set fields of deserialized struct. */
@@ -3708,10 +3708,6 @@ const char * MQTT_Status_strerror( MQTTStatus_t status )
37083708
str = "MQTTPublishRetrieveFailed";
37093709
break;
37103710

3711-
case MQTTPublishClearFailed:
3712-
str = "MQTTPublishClearFailed";
3713-
break;
3714-
37153711
case MQTTPublishClearAllFailed:
37163712
str = "MQTTPublishClearAllFailed";
37173713
break;

source/include/core_mqtt_serializer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ typedef enum MQTTStatus
106106
has failed */
107107
MQTTPublishRetrieveFailed, /**< User provided API to retrieve the copy of a publish while reconnecting
108108
with an unclean session has failed */
109-
MQTTPublishClearFailed, /**< User provided API to clear the copy of a publish on receiving a PUBACK has failed */
110109
MQTTPublishClearAllFailed /**< User provided API to clear all the copies of publishes while connecting with a clean
111110
session has failed */
112111
} MQTTStatus_t;

test/unit-test/core_mqtt_utest.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,14 +1235,6 @@ static void expectProcessLoopCalls( MQTTContext_t * const pContext,
12351235
}
12361236
}
12371237

1238-
if(expectMoreCalls)
1239-
{
1240-
if(pContext->clearFunction == publishClearCallbackFailed)
1241-
{
1242-
expectMoreCalls = false;
1243-
}
1244-
}
1245-
12461238
/* Update state based on the packet type (PUB or ACK) being received. */
12471239
if( expectMoreCalls )
12481240
{
@@ -4744,17 +4736,17 @@ void test_MQTT_ProcessLoop_handleIncomingAck_Clear_Publish_Copies( void )
47444736
currentPacketType = MQTT_PACKET_TYPE_PUBACK;
47454737
/* Set expected return values in the loop. */
47464738
resetProcessLoopParams( &expectParams );
4747-
expectParams.stateAfterDeserialize = MQTTPubAckPending;
4748-
expectParams.processLoopStatus = MQTTPublishClearFailed;
4739+
expectParams.stateAfterDeserialize = MQTTPublishDone;
4740+
expectParams.stateAfterSerialize = MQTTPublishDone;
47494741
expectProcessLoopCalls( &context, &expectParams );
47504742

47514743
/* Mock the receiving of a PUBREC packet type and expect the appropriate
47524744
* calls made from the process loop. */
47534745
currentPacketType = MQTT_PACKET_TYPE_PUBREC;
47544746
/* Set expected return values in the loop. */
47554747
resetProcessLoopParams( &expectParams );
4756-
expectParams.stateAfterDeserialize = MQTTPubRecPending;
4757-
expectParams.processLoopStatus = MQTTPublishClearFailed;
4748+
expectParams.stateAfterDeserialize = MQTTPubRelSend;
4749+
expectParams.stateAfterSerialize = MQTTPubCompPending;
47584750
expectProcessLoopCalls( &context, &expectParams );
47594751

47604752
}
@@ -7095,10 +7087,6 @@ void test_MQTT_Status_strerror( void )
70957087
str = MQTT_Status_strerror( status );
70967088
TEST_ASSERT_EQUAL_STRING( "MQTTPublishRetrieveFailed", str );
70977089

7098-
status = MQTTPublishClearFailed;
7099-
str = MQTT_Status_strerror( status );
7100-
TEST_ASSERT_EQUAL_STRING( "MQTTPublishClearFailed", str );
7101-
71027090
status = MQTTPublishClearAllFailed;
71037091
str = MQTT_Status_strerror( status );
71047092
TEST_ASSERT_EQUAL_STRING( "MQTTPublishClearAllFailed", str );

0 commit comments

Comments
 (0)