From 4e309f66ef57cb3f925dda2216ce40727af30d47 Mon Sep 17 00:00:00 2001 From: Marco Nilsson Date: Fri, 13 Mar 2026 09:49:00 +0100 Subject: [PATCH] Do a message queue gc after receiving messages. Clean out messages that were waiting for ACK and clear the client error in case it was MQTT_ERROR_SEND_BUFFER_IS_FULL and the TX queue now has room again. --- src/mqtt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mqtt.c b/src/mqtt.c index d914c1a..afba6fe 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -890,6 +890,11 @@ ssize_t __mqtt_recv(struct mqtt_client *client) client->recv_buffer.curr -= consumed; client->recv_buffer.curr_sz += (unsigned long)consumed; } + + /* Free up space by removing processed messages */ + mqtt_mq_clean(&client->mq); + if(client->error == MQTT_ERROR_SEND_BUFFER_IS_FULL && client->mq.curr_sz > 0) + client->error = MQTT_OK; } /* In case there was some error handling the (well formed) message, we end up here */