Skip to content

Commit 9fc51d8

Browse files
Merge pull request #5 from AniruddhaKanhere/reTransmit
Fix unit test and remove clearall function
2 parents 7eb3afa + f75c6a3 commit 9fc51d8

File tree

4 files changed

+251
-151
lines changed

4 files changed

+251
-151
lines changed

source/core_mqtt.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
457456
static 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 )
25842582
static 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,
27802792
MQTTStatus_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;

source/include/core_mqtt.h

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,10 @@ typedef bool ( * MQTTRetrievePacketForRetransmit)( struct MQTTContext * pContext
158158
* @return True if the clear is successful else false.
159159
*/
160160
/* @[define_mqtt_retransmitclearpacket] */
161-
typedef bool (* MQTTClearPacketForRetransmit)( struct MQTTContext * pContext,
161+
typedef void (* MQTTClearPacketForRetransmit)( struct MQTTContext * pContext,
162162
uint16_t packetId );
163163
/* @[define_mqtt_retransmitclearpacket] */
164164

165-
/**
166-
* @brief User defined callback used to clear all copied publish packets. Used to
167-
* when connecting with a clean session.
168-
*
169-
* @param[in] pContext Initialised MQTT Context.
170-
*
171-
* @return True if the clear all is successful else false.
172-
*/
173-
/* @[define_mqtt_retransmitclearallpackets] */
174-
typedef bool (* MQTTClearAllPacketsForRetransmit)( struct MQTTContext * pContext );
175-
/* @[define_mqtt_retransmitclearallpackets] */
176-
177165
/**
178166
* @ingroup mqtt_enum_types
179167
* @brief Values indicating if an MQTT connection exists.
@@ -335,11 +323,6 @@ typedef struct MQTTContext
335323
* @brief User defined API used to clear a particular copied publish packet.
336324
*/
337325
MQTTClearPacketForRetransmit clearFunction;
338-
339-
/**
340-
* @brief User defined API used to clear all copied publish packets.
341-
*/
342-
MQTTClearAllPacketsForRetransmit clearAllFunction;
343326
} MQTTContext_t;
344327

345328
/**
@@ -517,7 +500,6 @@ MQTTStatus_t MQTT_InitStatefulQoS( MQTTContext_t * pContext,
517500
* @param[in] storeFunction User defined API used to store outgoing publishes.
518501
* @param[in] retrieveFunction User defined API used to retreive a copied publish for resend operation.
519502
* @param[in] clearFunction User defined API used to clear a particular copied publish packet.
520-
* @param[in] clearAllFunction User defined API used to clear a particular copied publish packet.
521503
*
522504
* @return #MQTTBadParameter if invalid parameters are passed;
523505
* #MQTTSuccess otherwise.
@@ -599,8 +581,7 @@ MQTTStatus_t MQTT_InitStatefulQoS( MQTTContext_t * pContext,
599581
MQTTStatus_t MQTT_InitRetransmits( MQTTContext_t * pContext,
600582
MQTTStorePacketForRetransmit storeFunction,
601583
MQTTRetrievePacketForRetransmit retrieveFunction,
602-
MQTTClearPacketForRetransmit clearFunction,
603-
MQTTClearAllPacketsForRetransmit clearAllFunction );
584+
MQTTClearPacketForRetransmit clearFunction );
604585
/* @[declare_mqtt_initretransmits] */
605586

606587
/**
@@ -662,8 +643,6 @@ MQTTStatus_t MQTT_CheckConnectStatus( MQTTContext_t * pContext );
662643
* #MQTTStatusConnected if the connection is already established
663644
* #MQTTStatusDisconnectPending if the user is expected to call MQTT_Disconnect
664645
* before calling any other API
665-
* MQTTPublishClearAllFailed if on a clean session connection, clearing all the
666-
* previously copied publishes fails
667646
* MQTTPublishRetrieveFailed if on an unclean session connection, the copied
668647
* publishes are not retrieved successfully for retransmission
669648
* #MQTTSuccess otherwise.

source/include/core_mqtt_serializer.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,13 @@ typedef enum MQTTStatus
9999
MQTTNeedMoreBytes, /**< MQTT_ProcessLoop/MQTT_ReceiveLoop has received
100100
incomplete data; it should be called again (probably after
101101
a delay). */
102-
MQTTStatusConnected, /**< MQTT connection is established with the broker */
103-
MQTTStatusNotConnected, /**< MQTT connection is not established with the broker */
104-
MQTTStatusDisconnectPending, /**< Transport Interface has failed and MQTT connection needs to be closed */
102+
MQTTStatusConnected, /**< MQTT connection is established with the broker. */
103+
MQTTStatusNotConnected, /**< MQTT connection is not established with the broker. */
104+
MQTTStatusDisconnectPending, /**< Transport Interface has failed and MQTT connection needs to be closed. */
105105
MQTTPublishStoreFailed, /**< User provided API to store a copy of outgoing publish for retransmission purposes,
106-
has failed */
107-
MQTTPublishRetrieveFailed, /**< User provided API to retrieve the copy of a publish while reconnecting
108-
with an unclean session has failed */
109-
MQTTPublishClearAllFailed /**< User provided API to clear all the copies of publishes while connecting with a clean
110-
session has failed */
106+
has failed. */
107+
MQTTPublishRetrieveFailed /**< User provided API to retrieve the copy of a publish while reconnecting
108+
with an unclean session has failed. */
111109
} MQTTStatus_t;
112110

113111
/**

0 commit comments

Comments
 (0)