[coap] have AbortTransaction() call the associated response handler (#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.
This commit is contained in:
Jonathan Hui
2018-01-15 19:37:03 +00:00
committed by GitHub
parent 836377093e
commit 0b59c2fcd0
2 changed files with 6 additions and 2 deletions
+4 -2
View File
@@ -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;
}
}
+2
View File
@@ -610,6 +610,8 @@ public:
/**
* 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.
*