Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MQTT Connection Status Thread Safety (#305)
<!--- Title --> Description ----------- <!--- Describe your changes in detail. --> 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 --------------- - MQTT_PRE_SEND_HOOK(): The Pre and Post Send hook Macros are not required now, as the sending logic will be within the pre and post state update hook itself. (because we cannot allow other threads to change the connection state of the application until a send operation is complete). - I have split the handleSessionResumption function. The part of that function which was handling the clean session has been added within the mutex calls in the [MQTT_Connect API](https://github.com/FreeRTOS/coreMQTT/pull/305/files#diff-2534a3c0229ae9af3801f2a5c6a24eeef2cd0a686671f0371a11d2718ba4fdd6R2828) and the unclean session part is handled by this new function that is [called outside the mutex calls](https://github.com/FreeRTOS/coreMQTT/pull/305/files#diff-2534a3c0229ae9af3801f2a5c6a24eeef2cd0a686671f0371a11d2718ba4fdd6R2866). Pending Tasks --------------- - [ ] Doxygen example for the new API - [x] Unit Test Updates - [x] CBMC Proof --------- Co-authored-by: Dakshit Babbar <[email protected]> Co-authored-by: GitHub Action <[email protected]>
- Loading branch information