Skip to content

Commit 5d65d5b

Browse files
committed
split dupe correlation token check into its own function and fail operation with aws_last_error()
1 parent 3901ba2 commit 5d65d5b

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

source/request-response/request_response_client.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,18 +1233,22 @@ static int s_add_request_operation_to_response_path_table(
12331233
return AWS_OP_SUCCESS;
12341234
}
12351235

1236-
static int s_add_request_operation_to_correlation_token_table(
1236+
static bool s_is_correlation_token_in_use(
12371237
struct aws_mqtt_request_response_client *client,
12381238
struct aws_mqtt_rr_client_operation *operation) {
1239-
1240-
// First inspect whether the correlation token is already in use
12411239
struct aws_hash_element *elem = NULL;
12421240
aws_hash_table_find(
12431241
&client->operations_by_correlation_tokens,
12441242
&operation->storage.request_storage.options.correlation_token,
12451243
&elem);
1246-
if (elem != NULL) {
1247-
// correlation token is already in use. Return appropriate error.
1244+
return elem == NULL;
1245+
}
1246+
1247+
static int s_add_request_operation_to_correlation_token_table(
1248+
struct aws_mqtt_request_response_client *client,
1249+
struct aws_mqtt_rr_client_operation *operation) {
1250+
1251+
if (s_is_correlation_token_in_use(client, operation)) {
12481252
aws_raise_error(AWS_ERROR_MQTT_REQUEST_RESPONSE_DUPLICATE_CORRELATION_TOKEN);
12491253
return AWS_OP_ERR;
12501254
}
@@ -1291,7 +1295,7 @@ static void s_handle_operation_subscribe_result(
12911295
}
12921296

12931297
if (s_add_in_progress_operation_to_tracking_tables(client, operation)) {
1294-
s_request_response_fail_operation(operation, AWS_ERROR_MQTT_REQUEST_RESPONSE_INTERNAL_ERROR);
1298+
s_request_response_fail_operation(operation, aws_last_error());
12951299
return;
12961300
}
12971301

tests/request-response/request_response_client_tests.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3336,7 +3336,7 @@ static int s_rrc_request_response_failure_duplicate_correlation_token_fn(struct
33363336
NULL,
33373337
false));
33383338

3339-
struct aws_byte_cursor record_key_2 = aws_byte_cursor_from_c_str("testkey");
3339+
struct aws_byte_cursor record_key_2 = aws_byte_cursor_from_c_str("testkey2");
33403340
ASSERT_SUCCESS(s_rrc_test_submit_test_request(
33413341
&fixture,
33423342
RRC_PHDT_FAILURE_DUPLICATE_CORRELATION_TOKEN,

0 commit comments

Comments
 (0)