AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
IotMqtt_Disconnect

Closes an MQTT connection and frees resources.

uint32_t flags );

This function closes an MQTT connection and should only be called once the MQTT connection is no longer needed. Its exact behavior depends on the flags parameter.

Normally, flags should be 0. This gracefully shuts down an MQTT connection by sending an MQTT DISCONNECT packet. Any network close function provided when the connection was established will also be called. Note that because the MQTT server will not acknowledge a DISCONNECT packet, the client has no way of knowing if the server received the DISCONNECT packet. In the case where the DISCONNECT packet is lost in transport, any Last Will and Testament (LWT) message established with the connection may be published. However, if the DISCONNECT reaches the MQTT server, the LWT message will be discarded and not published.

Should the underlying network connection become unusable, this function should be called with flags set to IOT_MQTT_FLAG_CLEANUP_ONLY. In this case, no DISCONNECT packet will be sent, though the network close function will still be called. This function will only free the resources used by the MQTT connection; it still must be called even if the network is offline to avoid leaking resources.

IotMqtt_Disconnect modifies mqttConnection, so it shouldn't be used after calling this function.

Parameters
[in]mqttConnectionThe MQTT connection to close and clean up.
[in]flagsFlags which modify the behavior of this function. See MQTT Function Flags.