Skip to content

Commit

Permalink
[coap] have AbortTransaction() call the associated response handler (o…
Browse files Browse the repository at this point in the history
…penthread#2473)

Calling the associated response handler simplifies the client's handling of
CoAP transactions.

This commit also fixes a bug in aborting multiple pending transactions.
  • Loading branch information
jwhui authored Jan 15, 2018
1 parent 8363770 commit 0b59c2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/coap/coap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,17 @@ otError CoapBase::AbortTransaction(otCoapResponseHandler aHandler, void *aContex
{
otError error = OT_ERROR_NOT_FOUND;
Message *message;
Message *nextMessage;
CoapMetadata coapMetadata;

for (message = mPendingRequests.GetHead(); message != NULL; message = message->GetNext())
for (message = mPendingRequests.GetHead(); message != NULL; message = nextMessage)
{
nextMessage = message->GetNext();
coapMetadata.ReadFrom(*message);

if (coapMetadata.mResponseHandler == aHandler && coapMetadata.mResponseContext == aContext)
{
DequeueMessage(*message);
FinalizeCoapTransaction(*message, coapMetadata, NULL, NULL, NULL, OT_ERROR_ABORT);
error = OT_ERROR_NONE;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/coap/coap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ class CoapBase: public InstanceLocator
/**
* This method aborts CoAP transactions associated with given handler and context.
*
* The associated response handler will be called with OT_ERROR_ABORT.
*
* @param[in] aHandler A function pointer that should be called when the transaction ends.
* @param[in] aContext A pointer to arbitrary context information.
*
Expand Down

0 comments on commit 0b59c2f

Please sign in to comment.