Skip to content

Commit dc7de5f

Browse files
committed
ReadHandler changes for large payloads
When sending reports, if the session established with the peer supports large payloads, the ReadHandler will allocate a large buffer to, potentially, fit more attribute and event data.
1 parent 5ee4ef6 commit dc7de5f

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/app/InteractionModelEngine.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,11 @@ Protocols::InteractionModel::Status InteractionModelEngine::OnReadInitialRequest
853853
return Status::ResourceExhausted;
854854
}
855855

856+
if (apExchangeContext->GetSessionHandle()->AllowsLargePayload())
857+
{
858+
handler->UseLargePayloadBuffer();
859+
}
860+
856861
handler->OnInitialRequest(std::move(aPayload));
857862

858863
return Status::Success;

src/app/ReadHandler.h

+5
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ class ReadHandler : public Messaging::ExchangeDelegate
491491
/// @param aFlag Flag to clear
492492
void ClearStateFlag(ReadHandlerFlags aFlag);
493493

494+
void UseLargePayloadBuffer() { mUseLargePayloadBuffer = true; }
495+
bool ShouldUseLargePayloadBuffer() { return mUseLargePayloadBuffer; }
496+
494497
AttributePathExpandIterator mAttributePathExpandIterator = AttributePathExpandIterator(nullptr);
495498

496499
// The current generation of the reporting engine dirty set the last time we were notified that a path we're interested in was
@@ -572,6 +575,8 @@ class ReadHandler : public Messaging::ExchangeDelegate
572575

573576
// TODO (#27675): Merge all observers into one and that one will dispatch the callbacks to the right place.
574577
Observer * mObserver = nullptr;
578+
579+
bool mUseLargePayloadBuffer = false;
575580
};
576581
} // namespace app
577582
} // namespace chip

src/app/StatusResponse.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
namespace chip {
2828
namespace app {
29-
static constexpr size_t kMaxSecureSduLengthBytes = kMaxAppMessageLen + kMaxTagLen;
29+
static constexpr size_t kMaxSecureSduLengthBytes = kMaxAppMessageLen + kMaxTagLen;
30+
static constexpr size_t kMaxLargeSecureSduLengthBytes = kMaxLargeAppMessageLen + kMaxTagLen;
3031

3132
class StatusResponse
3233
{

src/app/reporting/Engine.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)
492492
CHIP_ERROR err = CHIP_NO_ERROR;
493493
chip::System::PacketBufferTLVWriter reportDataWriter;
494494
ReportDataMessage::Builder reportDataBuilder;
495-
chip::System::PacketBufferHandle bufHandle = System::PacketBufferHandle::New(chip::app::kMaxSecureSduLengthBytes);
495+
size_t maxSduSize = chip::app::kMaxSecureSduLengthBytes;
496+
chip::System::PacketBufferHandle bufHandle = nullptr;
496497
uint16_t reservedSize = 0;
497498
bool hasMoreChunks = false;
498499
bool needCloseReadHandler = false;
@@ -512,11 +513,18 @@ CHIP_ERROR Engine::BuildAndSendSingleReportData(ReadHandler * apReadHandler)
512513

513514
VerifyOrExit(apReadHandler != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);
514515
VerifyOrExit(apReadHandler->GetSession() != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
516+
517+
if (apReadHandler->ShouldUseLargePayloadBuffer())
518+
{
519+
maxSduSize = chip::app::kMaxLargeSecureSduLengthBytes;
520+
}
521+
522+
bufHandle = System::PacketBufferHandle::New(maxSduSize);
515523
VerifyOrExit(!bufHandle.IsNull(), err = CHIP_ERROR_NO_MEMORY);
516524

517-
if (bufHandle->AvailableDataLength() > kMaxSecureSduLengthBytes)
525+
if (bufHandle->AvailableDataLength() > maxSduSize)
518526
{
519-
reservedSize = static_cast<uint16_t>(bufHandle->AvailableDataLength() - kMaxSecureSduLengthBytes);
527+
reservedSize = static_cast<uint16_t>(bufHandle->AvailableDataLength() - maxSduSize);
520528
}
521529

522530
reportDataWriter.Init(std::move(bufHandle));

0 commit comments

Comments
 (0)