From 4a7bc298105f8cf123c529d1c0b8cf8a78f4148f Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Wed, 7 Apr 2021 08:21:54 -1000 Subject: [PATCH] Users don't need to hold the payload until publish complete (#252) - underlying lib updated to keep deep copy of the publish payload, thus we don't need to keep the payload alive until publish complete --- crt/aws-crt-cpp | 2 +- samples/mqtt/basic_pub_sub/main.cpp | 7 ++----- samples/mqtt/raw_pub_sub/main.cpp | 7 ++----- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/crt/aws-crt-cpp b/crt/aws-crt-cpp index faf2cabe0..1a551c7bc 160000 --- a/crt/aws-crt-cpp +++ b/crt/aws-crt-cpp @@ -1 +1 @@ -Subproject commit faf2cabe0abe92b5c7e1dc62ccc3f3d0d16a92fc +Subproject commit 1a551c7bc8b1b1ca29ac5288eeade6c4a4d59b0e diff --git a/samples/mqtt/basic_pub_sub/main.cpp b/samples/mqtt/basic_pub_sub/main.cpp index 24b0eec17..2754ff45e 100644 --- a/samples/mqtt/basic_pub_sub/main.cpp +++ b/samples/mqtt/basic_pub_sub/main.cpp @@ -540,12 +540,9 @@ int main(int argc, char *argv[]) break; } - ByteBuf payload = ByteBufNewCopy(DefaultAllocator(), (const uint8_t *)input.data(), input.length()); - ByteBuf *payloadPtr = &payload; - - auto onPublishComplete = [payloadPtr](Mqtt::MqttConnection &, uint16_t packetId, int errorCode) { - aws_byte_buf_clean_up(payloadPtr); + ByteBuf payload = ByteBufFromArray((const uint8_t *)input.data(), input.length()); + auto onPublishComplete = [](Mqtt::MqttConnection &, uint16_t packetId, int errorCode) { if (packetId) { fprintf(stdout, "Operation on packetId %d Succeeded\n", packetId); diff --git a/samples/mqtt/raw_pub_sub/main.cpp b/samples/mqtt/raw_pub_sub/main.cpp index 7262edde5..0a39efabc 100644 --- a/samples/mqtt/raw_pub_sub/main.cpp +++ b/samples/mqtt/raw_pub_sub/main.cpp @@ -413,12 +413,9 @@ int main(int argc, char *argv[]) break; } - ByteBuf payload = ByteBufNewCopy(DefaultAllocator(), (const uint8_t *)input.data(), input.length()); - ByteBuf *payloadPtr = &payload; - - auto onPublishComplete = [payloadPtr](Mqtt::MqttConnection &, uint16_t packetId, int errorCode) { - aws_byte_buf_clean_up(payloadPtr); + ByteBuf payload = ByteBufFromArray((const uint8_t *)input.data(), input.length()); + auto onPublishComplete = [](Mqtt::MqttConnection &, uint16_t packetId, int errorCode) { if (packetId) { fprintf(stdout, "Operation on packetId %d Succeeded\n", packetId);