in src/mqtt_client.c [1097:1136]
int mqtt_client_connect(MQTT_CLIENT_HANDLE handle, XIO_HANDLE xioHandle, MQTT_CLIENT_OPTIONS* mqttOptions)
{
int result;
/*SRS_MQTT_CLIENT_07_006: [If any of the parameters handle, ioHandle, or mqttOptions are NULL then mqtt_client_connect shall return a non-zero value.]*/
if (handle == NULL || mqttOptions == NULL || xioHandle == NULL)
{
LogError("mqtt_client_connect: NULL argument (handle = %p, mqttOptions = %p, xioHandle: %p)", handle, mqttOptions, xioHandle);
result = MU_FAILURE;
}
else
{
MQTT_CLIENT* mqtt_client = (MQTT_CLIENT*)handle;
mqtt_client->xioHandle = xioHandle;
mqtt_client->packetState = UNKNOWN_TYPE;
mqtt_client->qosValue = mqttOptions->qualityOfServiceValue;
mqtt_client->keepAliveInterval = mqttOptions->keepAliveInterval;
mqtt_client->maxPingRespTime = (DEFAULT_MAX_PING_RESPONSE_TIME < mqttOptions->keepAliveInterval/2) ? DEFAULT_MAX_PING_RESPONSE_TIME : mqttOptions->keepAliveInterval/2;
mqtt_client->timeSincePing = 0;
if (cloneMqttOptions(mqtt_client, mqttOptions) != 0)
{
LogError("Error: Clone Mqtt Options failed");
result = MU_FAILURE;
}
/*Codes_SRS_MQTT_CLIENT_07_008: [mqtt_client_connect shall open the XIO_HANDLE by calling into the xio_open interface.]*/
else if (xio_open(xioHandle, onOpenComplete, mqtt_client, onBytesReceived, mqtt_client, onIoError, mqtt_client) != 0)
{
/*Codes_SRS_MQTT_CLIENT_07_007: [If any failure is encountered then mqtt_client_connect shall return a non-zero value.]*/
LogError("Error: io_open failed");
result = MU_FAILURE;
mqtt_client->xioHandle = NULL;
// Remove cloned options
clear_mqtt_options(mqtt_client);
}
else
{
result = 0;
}
}
return result;
}