in source/iot/MqttClient.cpp [392:437]
std::shared_ptr<Crt::Mqtt::MqttConnection> MqttClient::NewConnection(
const MqttClientConnectionConfig &config) noexcept
{
if (!config)
{
m_lastError = config.LastError();
return nullptr;
}
bool useWebsocket = config.m_webSocketInterceptor.operator bool();
auto newConnection = m_client.NewConnection(
config.m_endpoint.c_str(), config.m_port, config.m_socketOptions, config.m_context, useWebsocket);
if (!newConnection)
{
m_lastError = m_client.LastError();
return nullptr;
}
if (!(*newConnection))
{
m_lastError = newConnection->LastError();
return nullptr;
}
if (!config.m_username.empty() || !config.m_password.empty())
{
if (!newConnection->SetLogin(config.m_username.c_str(), config.m_password.c_str()))
{
m_lastError = newConnection->LastError();
return nullptr;
}
}
if (useWebsocket)
{
newConnection->WebsocketInterceptor = config.m_webSocketInterceptor;
}
if (config.m_proxyOptions)
{
newConnection->SetHttpProxyOptions(config.m_proxyOptions.value());
}
return newConnection;
}