Skip to content

Commit

Permalink
allow connect on low memory
Browse files Browse the repository at this point in the history
  • Loading branch information
bertmelis committed Aug 31, 2023
1 parent 2ab5ca4 commit 2b8fd27
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Packets/Packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Packet::Packet(espMqttClientTypes::Error& error,
(password ? 2 + strlen(password) : 0);

// allocate memory
if (!_allocate(remainingLength)) {
if (!_allocate(remainingLength, false)) {
error = espMqttClientTypes::Error::OUT_OF_MEMORY;
return;
}
Expand Down Expand Up @@ -300,8 +300,8 @@ Packet::Packet(espMqttClientTypes::Error& error, MQTTPacketType type)
}


bool Packet::_allocate(size_t remainingLength) {
if (EMC_GET_FREE_MEMORY() < EMC_MIN_FREE_MEMORY) {
bool Packet::_allocate(size_t remainingLength, bool check) {
if (check && EMC_GET_FREE_MEMORY() < EMC_MIN_FREE_MEMORY) {
emc_log_w("Packet buffer not allocated: low memory");
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Packets/Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Packet {

private:
// pass remainingLength = total size - header - remainingLengthLength!
bool _allocate(size_t remainingLength);
bool _allocate(size_t remainingLength, bool check = true);

// fills header and returns index of next available byte in buffer
size_t _fillPublishHeader(uint16_t packetId,
Expand Down

0 comments on commit 2b8fd27

Please sign in to comment.