Skip to content

Commit

Permalink
Handle output event of type TransferSession::OutputEventType::kIntern…
Browse files Browse the repository at this point in the history
…alError in the ProcessOutputEvents API.

- If the state machine generates this event, indicating that the session is in a bad state and cannot continue,
  terminate the BDX session.
  • Loading branch information
nivi-apple committed Jan 31, 2025
1 parent d4cee81 commit 6e57c4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/protocols/bdx/AsyncTransferFacilitator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ CHIP_ERROR AsyncTransferFacilitator::Init(System::Layer * layer, Messaging::Exch
*/
void AsyncTransferFacilitator::ProcessOutputEvents()
{

if (mProcessingOutputEvents)
{
ChipLogDetail(BDX,
Expand All @@ -63,6 +64,16 @@ void AsyncTransferFacilitator::ProcessOutputEvents()
mTransfer.GetNextAction(outEvent);
while (outEvent.EventType != TransferSession::OutputEventType::kNone)
{

// If the transfer session state machine generates an event of type TransferSession::OutputEventType::kInternalError,
// indicating that the session is in a bad state, we do not want to process any more events and terminate the session.
// In that case, set mDestroySelfAfterProcessingEvents to true and break from the loop so we can call DestroySelf() to clean up.
if (outEvent.EventType == TransferSession::OutputEventType::kInternalError)
{
mDestroySelfAfterProcessingEvents = true;
break;
}

if (outEvent.EventType == TransferSession::OutputEventType::kMsgToSend)
{
CHIP_ERROR err = SendMessage(outEvent.msgTypeData, outEvent.MsgData);
Expand Down Expand Up @@ -170,27 +181,20 @@ void AsyncResponder::NotifyEventHandled(const TransferSession::OutputEventType e
ChipLogDetail(BDX, "NotifyEventHandled : Event %s Error %" CHIP_ERROR_FORMAT,
TransferSession::OutputEvent::TypeToString(eventType), status.Format());

// If we are handling a status report, we should destroy ourselves and hence, terminate the transfer.
if (eventType == TransferSession::OutputEventType::kStatusReceived)
{
DestroySelf();
return;
}

// If this is the end of the transfer (whether a clean end, or some sort of error condition), ensure that
// we destroy ourselves after processing any output events that might have been generated by
// the transfer session to handle end-of-transfer (e.g. in some error conditions it might want to send
// out a status report).
if (eventType == TransferSession::OutputEventType::kAckEOFReceived ||
eventType == TransferSession::OutputEventType::kStatusReceived ||
eventType == TransferSession::OutputEventType::kInternalError ||
eventType == TransferSession::OutputEventType::kTransferTimeout)
{
mDestroySelfAfterProcessingEvents = true;
}

// If there was an error handling the output event, this should notify the transfer object to abort transfer so it can send a
// status report across the exchange when we call ProcessOutputEvents below.
if (status != CHIP_NO_ERROR)
else if (status != CHIP_NO_ERROR)
{
mTransfer.AbortTransfer(GetBdxStatusCodeFromChipError(status));
}
Expand Down
6 changes: 5 additions & 1 deletion src/protocols/bdx/AsyncTransferFacilitator.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ class AsyncTransferFacilitator : public Messaging::ExchangeDelegate
*/
virtual void DestroySelf() = 0;

// Calling ProcessOutputEvents can destroy this object before the call returns.
/**
* Calling ProcessOutputEvents can destroy this object before the call returns for certain cases
* where the state machine either receives a message indicating termination of the transfer session (StatusReport
* or BlockAckEOF) or generates an InternalError for various error scenarios including timeout.
*/
void ProcessOutputEvents();

// The transfer session corresponding to this AsyncTransferFacilitator object.
Expand Down

0 comments on commit 6e57c4e

Please sign in to comment.