Skip to content

Commit 68ee2e4

Browse files
authored
Update CRT to v0.4.6 for better error handling (#51)
1 parent 42ec5c5 commit 68ee2e4

File tree

6 files changed

+25
-32
lines changed

6 files changed

+25
-32
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ is provided by code that been generated from a model of the service.
3131

3232
## Build from source
3333
```
34-
git clone --branch v0.4.5 https://github.com/awslabs/aws-crt-cpp.git
34+
git clone --branch v0.4.6 https://github.com/awslabs/aws-crt-cpp.git
3535
git clone https://github.com/awslabs/aws-iot-device-sdk-cpp-v2.git
3636
mkdir aws-crt-cpp-build
3737
cd aws-crt-cpp-build

codebuild/common-posix.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fi
1717

1818
# build aws-crt-cpp
1919
pushd $BUILD_PATH
20-
git clone --branch v0.4.5 https://github.com/awslabs/aws-crt-cpp.git
20+
git clone --branch v0.4.6 https://github.com/awslabs/aws-crt-cpp.git
2121
cd aws-crt-cpp
2222
cmake $CMAKE_ARGS -DBUILD_DEPS=ON ./
2323
cmake --build . --target install

codebuild/common-windows.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mkdir %INSTALL_DIR%
88
@rem build aws-crt-cpp
99
mkdir %BUILDS_DIR%\aws-crt-cpp-build
1010
cd %BUILDS_DIR%\aws-crt-cpp-build
11-
git clone --branch v0.4.5 https://github.com/awslabs/aws-crt-cpp.git
11+
git clone --branch v0.4.6 https://github.com/awslabs/aws-crt-cpp.git
1212
cmake %CMAKE_ARGS% -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%" -DCMAKE_PREFIX_PATH="%INSTALL_DIR%" -DCMAKE_BUILD_TYPE="Release" -DBUILD_DEPS=ON aws-crt-cpp || goto error
1313
cmake --build . --target install || goto error
1414

samples/greengrass/basic_discovery/main.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ char *s_getCmdOption(char **begin, char **end, const String &option)
6565
int main(int argc, char *argv[])
6666
{
6767
/************************ Setup the Lib ****************************/
68-
/*
69-
* These make debug output via ErrorDebugString() work.
70-
*/
71-
LoadErrorStrings();
72-
7368
/*
7469
* Do the global initialization for the API.
7570
*/
@@ -124,6 +119,7 @@ int main(int argc, char *argv[])
124119
stderr, "Event Loop Group Creation failed with error %s\n", ErrorDebugString(eventLoopGroup.LastError()));
125120
exit(-1);
126121
}
122+
127123
/*
128124
* We're using Mutual TLS for Mqtt, so we need to load our client certificates
129125
*/
@@ -168,10 +164,6 @@ int main(int argc, char *argv[])
168164

169165
DiscoveryClient discoveryClient(clientConfig);
170166

171-
GGGroup groupToUse;
172-
Aws::Iot::MqttClientConnectionConfigBuilder connectionConfigBuilder(certificatePath.c_str(), keyPath.c_str());
173-
Aws::Iot::MqttClientConnectionConfig connectionConfig;
174-
175167
Aws::Iot::MqttClient mqttClient(bootstrap);
176168
std::shared_ptr<Mqtt::MqttConnection> connection(nullptr);
177169

@@ -183,10 +175,7 @@ int main(int argc, char *argv[])
183175
discoveryClient.Discover(thingName, [&](DiscoverResponse *response, int error, int httpResponseCode) {
184176
if (!error && response->GGGroups)
185177
{
186-
groupToUse = std::move(response->GGGroups->at(0));
187-
ByteCursor caCursor = ByteCursorFromArray(
188-
reinterpret_cast<const uint8_t *>(groupToUse.CAs->at(0).data()), groupToUse.CAs->at(0).length());
189-
connectionConfigBuilder.WithCertificateAuthority(caCursor);
178+
auto groupToUse = std::move(response->GGGroups->at(0));
190179

191180
auto connectivityInfo = groupToUse.Cores->at(0).Connectivity->at(0);
192181

@@ -198,10 +187,18 @@ int main(int argc, char *argv[])
198187
connectivityInfo.HostAddress->c_str(),
199188
(int)connectivityInfo.Port.value());
200189

201-
connectionConfigBuilder.WithPortOverride(connectivityInfo.Port.value());
202-
connectionConfigBuilder.WithEndpoint(connectivityInfo.HostAddress.value());
203-
connectionConfig = connectionConfigBuilder.Build();
204-
connection = mqttClient.NewConnection(connectionConfig);
190+
connection = mqttClient.NewConnection(
191+
Aws::Iot::MqttClientConnectionConfigBuilder(certificatePath.c_str(), keyPath.c_str())
192+
.WithCertificateAuthority(groupToUse.CAs->at(0).c_str())
193+
.WithPortOverride(connectivityInfo.Port.value())
194+
.WithEndpoint(connectivityInfo.HostAddress.value())
195+
.Build());
196+
197+
if (!connection)
198+
{
199+
fprintf(stderr, "Connection setup failed with error %s", ErrorDebugString(mqttClient.LastError()));
200+
exit(-1);
201+
}
205202

206203
connection->OnConnectionCompleted =
207204
[&, connectivityInfo](

samples/jobs/describe_job_execution/main.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ char *s_getCmdOption(char **begin, char **end, const String &option)
7070
int main(int argc, char *argv[])
7171
{
7272
/************************ Setup the Lib ****************************/
73-
/*
74-
* These make debug output via ErrorDebugString() work.
75-
*/
76-
LoadErrorStrings();
77-
7873
/*
7974
* Do the global initialization for the API.
8075
*/
@@ -136,7 +131,10 @@ int main(int argc, char *argv[])
136131

137132
if (!clientConfig)
138133
{
139-
fprintf(stderr, "Client Configuration initialization failed with error %s\n", ErrorDebugString(LastError()));
134+
fprintf(
135+
stderr,
136+
"Client Configuration initialization failed with error %s\n",
137+
ErrorDebugString(clientConfig.LastError()));
140138
exit(-1);
141139
}
142140

samples/shadow/shadow_sync/main.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ static void s_changeShadowValue(
110110
int main(int argc, char *argv[])
111111
{
112112
/************************ Setup the Lib ****************************/
113-
/*
114-
* These make debug output via ErrorDebugString() work.
115-
*/
116-
LoadErrorStrings();
117-
118113
/*
119114
* Do the global initialization for the API.
120115
*/
@@ -176,7 +171,10 @@ int main(int argc, char *argv[])
176171

177172
if (!clientConfig)
178173
{
179-
fprintf(stderr, "Client Configuration initialization failed with error %s\n", ErrorDebugString(LastError()));
174+
fprintf(
175+
stderr,
176+
"Client Configuration initialization failed with error %s\n",
177+
ErrorDebugString(clientConfig.LastError()));
180178
exit(-1);
181179
}
182180

0 commit comments

Comments
 (0)