mirror of
https://github.com/espressif/openthread.git
synced 2026-08-17 16:09:51 +00:00
[coap] reduce stack occupation (#3385)
In #3210, CoAP header is increased from 128 to 512. Multiple local CoAP header variables are declared in nested calls during CoAP process, easily causing limited stack space overflow. This commit tries to reuse existing local header variable to reduce stack usage.
This commit is contained in:
+3
-21
@@ -171,7 +171,7 @@ otError Coap::SendMessage(Message & aMessage,
|
||||
if ((header.GetType() == OT_COAP_TYPE_ACKNOWLEDGMENT || header.GetType() == OT_COAP_TYPE_RESET) &&
|
||||
header.GetCode() != OT_COAP_CODE_EMPTY)
|
||||
{
|
||||
mResponsesQueue.EnqueueResponse(aMessage, aMessageInfo);
|
||||
mResponsesQueue.EnqueueResponse(header, aMessage, aMessageInfo);
|
||||
}
|
||||
|
||||
// Set Message Id if it was not already set.
|
||||
@@ -809,32 +809,14 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError ResponsesQueue::GetMatchedResponseCopy(const Message & aRequest,
|
||||
const Ip6::MessageInfo &aMessageInfo,
|
||||
Message ** aResponse)
|
||||
void ResponsesQueue::EnqueueResponse(const Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
Header header;
|
||||
|
||||
SuccessOrExit(error = header.FromMessage(aRequest, 0));
|
||||
|
||||
error = GetMatchedResponseCopy(header, aMessageInfo, aResponse);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void ResponsesQueue::EnqueueResponse(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
Header header;
|
||||
Message * copy;
|
||||
EnqueuedResponseHeader enqueuedResponseHeader(aMessageInfo);
|
||||
uint16_t messageCount;
|
||||
uint16_t bufferCount;
|
||||
|
||||
SuccessOrExit(header.FromMessage(aMessage, 0));
|
||||
|
||||
switch (GetMatchedResponseCopy(aMessage, aMessageInfo, ©))
|
||||
switch (GetMatchedResponseCopy(aHeader, aMessageInfo, ©))
|
||||
{
|
||||
case OT_ERROR_NOT_FOUND:
|
||||
break;
|
||||
|
||||
+2
-16
@@ -363,11 +363,12 @@ public:
|
||||
* response is not added.
|
||||
* The CoAP response is copied before it is added to the cache.
|
||||
*
|
||||
* @param[in] aHeader A reference to a CoAP header.
|
||||
* @param[in] aMessage The CoAP response to add to the cache.
|
||||
* @param[in] aMessageInfo The message info corresponding to @p aMessage.
|
||||
*
|
||||
*/
|
||||
void EnqueueResponse(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
void EnqueueResponse(const Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
/**
|
||||
* Remove the oldest response from the cache.
|
||||
@@ -395,21 +396,6 @@ public:
|
||||
*/
|
||||
otError GetMatchedResponseCopy(const Header &aHeader, const Ip6::MessageInfo &aMessageInfo, Message **aResponse);
|
||||
|
||||
/**
|
||||
* Get a copy of CoAP response from the cache that matches given Message ID and source endpoint.
|
||||
*
|
||||
* @param[in] aRequest The CoAP message containing Message ID.
|
||||
* @param[in] aMessageInfo The message info containing source endpoint address and port.
|
||||
* @param[out] aResponse A pointer to a copy of a cached CoAP response matching given arguments.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Matching response found and successfully created a copy.
|
||||
* @retval OT_ERROR_NO_BUFS Matching response found but there is not sufficient buffer to create a copy.
|
||||
* @retval OT_ERROR_NOT_FOUND Matching response not found.
|
||||
* @retval OT_ERROR_PARSE Could not parse CoAP header in the request message.
|
||||
*
|
||||
*/
|
||||
otError GetMatchedResponseCopy(const Message &aRequest, const Ip6::MessageInfo &aMessageInfo, Message **aResponse);
|
||||
|
||||
/**
|
||||
* Get a reference to the cached CoAP responses queue.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user