void IoTHubTransportMqtt_Destroy(TRANSPORT_HANDLE handle) { /* Codes_SRS_IOTHUB_MQTT_TRANSPORT_07_012: [IoTHubTransportMqtt_Destroy shall do nothing if parameter handle is NULL.] */ PMQTTTRANSPORT_HANDLE_DATA transportState = (PMQTTTRANSPORT_HANDLE_DATA)handle; if (transportState != NULL) { transportState->destroyCalled = true; DisconnectFromClient(transportState); //Empty the Waiting for Ack Messages. while (!DList_IsListEmpty(&transportState->waitingForAck)) { PDLIST_ENTRY currentEntry = DList_RemoveHeadList(&transportState->waitingForAck); MQTT_MESSAGE_DETAILS_LIST* mqttMsgEntry = containingRecord(currentEntry, MQTT_MESSAGE_DETAILS_LIST, entry); sendMsgComplete(mqttMsgEntry->iotHubMessageEntry, transportState, IOTHUB_BATCHSTATE_FAILED); free(mqttMsgEntry); } /* Codes_SRS_IOTHUB_MQTT_TRANSPORT_07_014: [IoTHubTransportMqtt_Destroy shall free all the resources currently in use.] */ mqtt_client_deinit(transportState->mqttClient); STRING_delete(transportState->mqttEventTopic); STRING_delete(transportState->mqttMessageTopic); STRING_delete(transportState->device_id); STRING_delete(transportState->device_key); STRING_delete(transportState->sasTokenSr); STRING_delete(transportState->hostAddress); STRING_delete(transportState->configPassedThroughUsername); tickcounter_destroy(g_msgTickCounter); free(transportState); } }
void mqtt_client_sample_run() { if (platform_init() != 0) { PrintLogFunction(LOG_LINE, "platform_init failed"); } else { MQTT_CLIENT_HANDLE mqttHandle = mqtt_client_init(OnRecvCallback, OnOperationComplete, NULL, PrintLogFunction); if (mqttHandle == NULL) { PrintLogFunction(LOG_LINE, "mqtt_client_init failed"); } else { MQTT_CLIENT_OPTIONS options = { 0 }; options.clientId = "azureiotclient"; options.willMessage = NULL; options.username = NULL; options.password = NULL; options.keepAliveInterval = 10; options.useCleanSession = true; options.qualityOfServiceValue = DELIVER_AT_MOST_ONCE; SOCKETIO_CONFIG config = {"test.mosquitto.org", PORT_NUM_UNENCRYPTED, NULL}; XIO_HANDLE xio = xio_create(socketio_get_interface_description(), &config, PrintLogFunction); if (xio == NULL) { PrintLogFunction(LOG_LINE, "xio_create failed"); } else { if (mqtt_client_connect(mqttHandle, xio, &options) != 0) { PrintLogFunction(LOG_LINE, "mqtt_client_connect failed"); } else { do { mqtt_client_dowork(mqttHandle); } while (g_continue); } xio_close(xio, OnCloseComplete, NULL); } mqtt_client_deinit(mqttHandle); } platform_deinit(); } #ifdef _CRT_DBG_MAP_ALLOC _CrtDumpMemoryLeaks(); #endif }
void prov_transport_common_mqtt_destroy(PROV_DEVICE_TRANSPORT_HANDLE handle) { /* Tests_PROV_TRANSPORT_MQTT_COMMON_07_005: [ If handle is NULL, prov_transport_common_mqtt_destroy shall do nothing. ] */ if (handle != NULL) { /* Tests_PROV_TRANSPORT_MQTT_COMMON_07_006: [ prov_transport_common_mqtt_destroy shall free all resources used in this module. ] */ PROV_TRANSPORT_MQTT_INFO* mqtt_info = (PROV_TRANSPORT_MQTT_INFO*)handle; mqtt_client_deinit(mqtt_info->mqtt_client); mqtt_info->mqtt_client = NULL; cleanup_mqtt_data(mqtt_info); } }