in source/core_mqtt_agent.c [1038:1077]
MQTTStatus_t MQTTAgent_ResumeSession( MQTTAgentContext_t * pMqttAgentContext,
bool sessionPresent )
{
MQTTStatus_t statusResult = MQTTSuccess;
/* If the packet ID is zero then the MQTT context has not been initialized as 0
* is the initial value but not a valid packet ID. */
if( ( pMqttAgentContext != NULL ) &&
( pMqttAgentContext->mqttContext.nextPacketId != MQTT_PACKET_ID_INVALID ) )
{
/* Resend publishes if session is present. NOTE: It's possible that some
* of the operations that were in progress during the network interruption
* were subscribes. In that case, we would want to mark those operations
* as completing with error and remove them from the list of operations, so
* that the calling task can try subscribing again. */
if( sessionPresent )
{
/* The session has resumed, so clear any SUBSCRIBE/UNSUBSCRIBE operations
* that were pending acknowledgments in the previous connection. */
clearPendingAcknowledgments( pMqttAgentContext, true );
statusResult = resendPublishes( pMqttAgentContext );
}
/* If we wanted to resume a session but none existed with the broker, we
* should mark all in progress operations as errors so that the tasks that
* created them can try again. */
else
{
/* We have a clean session, so clear all operations pending acknowledgments. */
clearPendingAcknowledgments( pMqttAgentContext, false );
}
}
else
{
statusResult = MQTTBadParameter;
}
return statusResult;
}