Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeuz committed Sep 18, 2024
1 parent b765b06 commit c2cd5aa
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion communication/src/coap_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,25 @@
#include "coap_message_decoder.h"
#include "str_util.h"
#include "logging.h"
#include "scope_guard.h"
#include "check.h"

namespace particle::protocol {

int sendEmptyAckOrRst(MessageChannel& channel, Message& msg, CoapType type) {
auto msgLen = msg.length();
auto msgCapacity = msg.capacity();
Message resp;
auto err = channel.response(msg, resp, msg.capacity() - msg.length());
auto err = channel.response(msg, resp, msgCapacity - msgLen);
if (err != ProtocolError::NO_ERROR) {
return toSystemError(err);
}
SCOPE_GUARD({
// BufferMessageChannel::response() alters the capacity of the original message. Restore it
// so that the calling code could still use the extra space available in the message
msg.set_buffer(msg.buf(), msgCapacity);
msg.set_length(msgLen);
});
CoapMessageEncoder e((char*)resp.buf(), resp.capacity());
e.type(type);
e.code(CoapCode::EMPTY);
Expand Down

0 comments on commit c2cd5aa

Please sign in to comment.