Skip to content

Commit

Permalink
Users don't need to hold the payload until publish complete (#252)
Browse files Browse the repository at this point in the history
- underlying lib updated to keep deep copy of the publish payload, thus we don't need to keep the payload alive until publish complete
  • Loading branch information
TingDaoK authored Apr 7, 2021
1 parent 6abdaa0 commit 4a7bc29
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
7 changes: 2 additions & 5 deletions samples/mqtt/basic_pub_sub/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions samples/mqtt/raw_pub_sub/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4a7bc29

Please sign in to comment.