FreeRTOS / coreMQTT

Client implementation of the MQTT 3.1.1 specification for embedded devices
MIT License
140 stars 100 forks source link

MQTT Connection Status Thread Safety #305

Closed DakshitBabbar closed 1 week ago

DakshitBabbar commented 1 month ago

Description

Following is a brief summary of changes:

  1. Check the connected flag before doing any send operation on the connection
  2. Make all the APIs that do send operations, thread safe
  3. Update the connected flag within MQTT_Disconnect regardless of the return status of the send operation

Following are the specifics of the changes:

  1. Add 3 new MQTTStatus_t values: MQTTStatusConnected, MQTTStatusNotConnected and MQTTStatusDisconnectPending
  2. Added 1 new MQTTConnectionStatus_t value: MQTTDisconnectPending
  3. Update the MQTT_Status_strerror function to handle the new MQTTStatus_t values
  4. Add a new API function MQTT_CheckConnectStatus() that will check the value of the context→connectStatus flag safely.
  5. Add this API to the core_mqtt.h file to make it available to users
  6. Check the connected flag before doing any Send operation (following API's are updated) a. sendPublishAcks b. MQTT_Connect c. MQTT_Subscribe d. MQTT_Publish e. MQTT_Ping f. MQTT_Unsubscribe g. MQTT_Disconnect
  7. Use the MQTT_PRE_STATE_UPDATE_HOOK() and MQTT_POST_STATE_UPDATE_HOOK() to make the send APIs thread safe
  8. The connect status is set to MQTTDisconnectPending whenever a transport send or receive function returns a negative error code
  9. const keyword for the the MQTTStatus_t is removed in the input parameters for the receive functions as we need to update the connection status when the receive function returns a negative error code

Relevant Explanations

Pending Tasks

DakshitBabbar commented 3 weeks ago

/bot run formatting

DakshitBabbar commented 1 week ago

/bot run formatting