Skip to content

Commit

Permalink
Fix exchange lifetime management in BDXMessenger.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Jul 12, 2022
1 parent b726656 commit 7fa3055
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/app/clusters/ota-requestor/DefaultOTARequestor.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,14 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader::
{
sendFlags.Set(chip::Messaging::SendMessageFlags::kExpectResponse);
}
ReturnErrorOnFailure(mExchangeCtx->SendMessage(event.msgTypeData.ProtocolId, event.msgTypeData.MessageType,
event.MsgData.Retain(), sendFlags));
return CHIP_NO_ERROR;
CHIP_ERROR err = mExchangeCtx->SendMessage(event.msgTypeData.ProtocolId, event.msgTypeData.MessageType,
event.MsgData.Retain(), sendFlags);
if (err != CHIP_NO_ERROR)
{
Reset();
}

return err;
}

CHIP_ERROR OnMessageReceived(chip::Messaging::ExchangeContext * ec, const chip::PayloadHeader & payloadHeader,
Expand All @@ -150,13 +155,14 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader::
return CHIP_NO_ERROR;
}

mDownloader->OnMessageReceived(payloadHeader, payload.Retain());
mDownloader->OnMessageReceived(payloadHeader, std::move(payload));

// For a receiver using BDX Protocol, all received messages will require a response except for a StatusReport
if (!payloadHeader.HasMessageType(chip::Protocols::SecureChannel::MsgType::StatusReport))
{
ec->WillSendMessage();
}

return CHIP_NO_ERROR;
}

Expand All @@ -169,6 +175,8 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader::
}
}

void OnExchangeClosing(Messaging::ExchangeContext * ec) override { mExchangeCtx = nullptr; }

void Init(chip::BDXDownloader * downloader, chip::Messaging::ExchangeContext * ec)
{
mExchangeCtx = ec;
Expand Down

0 comments on commit 7fa3055

Please sign in to comment.