Skip to content

Commit

Permalink
Fix core dump
Browse files Browse the repository at this point in the history
  • Loading branch information
alfred2g committed Nov 30, 2023
1 parent 1b6077b commit f2bce51
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions servicetests/tests/JobsExecution/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ int main(int argc, char *argv[])
*/
std::promise<bool> connectionCompletedPromise;
std::promise<void> connectionClosedPromise;

Aws::Iot::MqttClientConnectionConfigBuilder clientConfigBuilder;
std::shared_ptr<Aws::Crt::Mqtt::MqttConnection> connection;

Aws::Iot::Mqtt5ClientBuilder *builder = Aws::Iot::Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromPath(
Expand All @@ -79,12 +77,9 @@ int main(int argc, char *argv[])
return -1;
}
// Create Mqtt5Client
std::shared_ptr<Aws::Crt::Mqtt5::Mqtt5Client> client = builder->Build();

if (cmdData.input_mqtt_version == 5UL)
{
// Create the MQTT5 builder and populate it with data from cmdData.

// Setup connection options
std::shared_ptr<Mqtt5::ConnectPacket> connectOptions = std::make_shared<Mqtt5::ConnectPacket>();
connectOptions->WithClientId(cmdData.input_clientId);
Expand All @@ -93,7 +88,6 @@ int main(int argc, char *argv[])
{
builder->WithPort(static_cast<uint16_t>(cmdData.input_port));
}

// Setup lifecycle callbacks
builder->WithClientConnectionSuccessCallback(
[&connectionCompletedPromise](const Mqtt5::OnConnectionSuccessEventData &eventData) {
Expand All @@ -111,18 +105,27 @@ int main(int argc, char *argv[])
});
builder->WithClientStoppedCallback([&connectionClosedPromise](const Mqtt5::OnStoppedEventData &) {
fprintf(stdout, "Mqtt5 Client stopped.\n");
connectionClosedPromise.set_value();
connectionClosedPromise.set_value();
});

std::shared_ptr<Aws::Crt::Mqtt5::Mqtt5Client> client5 = builder->Build();
delete builder;
//client5 = builder->Build();
if (client5 == nullptr) {
fprintf(
stdout, "Failed to Init Mqtt5Client with error code %d: %s", LastError(), ErrorDebugString(LastError()));
return -1;
}
fprintf(stdout, "Connecting...\n");
if (!client->Start())
if (!client5->Start())
{
fprintf(stderr, "MQTT5 Connection failed to start");
exit(-1);
}
}
else if (cmdData.input_mqtt_version == 3UL)
{
Aws::Iot::MqttClientConnectionConfigBuilder clientConfigBuilder;
// Create the MQTT builder and populate it with data from cmdData.
clientConfigBuilder =
Aws::Iot::MqttClientConnectionConfigBuilder(cmdData.input_cert.c_str(), cmdData.input_key.c_str());
Expand Down Expand Up @@ -426,9 +429,9 @@ int main(int argc, char *argv[])
if (cmdData.input_mqtt_version == 5UL)
{
// Disconnect
if (client->Stop() == true)
//if (client5->Stop() == true)
{
connectionClosedPromise.get_future().wait();
connectionClosedPromise.get_future().wait();
}
}
else
Expand Down

0 comments on commit f2bce51

Please sign in to comment.