Bugfix: Multiple packets in buffer handling was broken
This commit is contained in:
parent
636840641e
commit
40faa2e8cf
1 changed files with 6 additions and 6 deletions
12
src/mqtt.c
12
src/mqtt.c
|
@ -107,16 +107,18 @@ static inline void parse_packet(MQTTHandle *handle, MQTTPacket *packet) {
|
||||||
break;
|
break;
|
||||||
case MQTT_QOS_1:
|
case MQTT_QOS_1:
|
||||||
if (send_puback_packet(handle, payload->packet_id)) {
|
if (send_puback_packet(handle, payload->packet_id)) {
|
||||||
DEBUG_LOG("Dispatching subscription...");
|
|
||||||
dispatch_subscription(handle, payload);
|
dispatch_subscription(handle, payload);
|
||||||
} else {
|
|
||||||
DEBUG_LOG("Error sending PubAck");
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MQTT_QOS_2:
|
case MQTT_QOS_2:
|
||||||
DEBUG_LOG("Sending PubRec packet");
|
|
||||||
send_pubrec_packet(handle, payload->packet_id, dispatch_subscription_direct, payload);
|
send_pubrec_packet(handle, payload->packet_id, dispatch_subscription_direct, payload);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
DEBUG_LOG("Invalid QoS! (packet_id: %d)", payload->packet_id);
|
||||||
|
(void)platform_destroy_timer(handle, handle->keepalive_timer);
|
||||||
|
handle->keepalive_timer = -1;
|
||||||
|
(void)platform_disconnect(handle);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -184,14 +186,12 @@ PlatformTaskFunc(_reader) {
|
||||||
free_MQTTPacket(packet);
|
free_MQTTPacket(packet);
|
||||||
|
|
||||||
if (!buffer_eof(buffer)) {
|
if (!buffer_eof(buffer)) {
|
||||||
buffer->position = buffer->len;
|
|
||||||
buffer->len = max_receive_buffer_size;
|
buffer->len = max_receive_buffer_size;
|
||||||
|
|
||||||
// Not complete recv buffer was consumed, so we have more than one packet in there
|
// Not complete recv buffer was consumed, so we have more than one packet in there
|
||||||
size_t remaining = max_receive_buffer_size - buffer->position;
|
size_t remaining = max_receive_buffer_size - buffer->position;
|
||||||
memmove(buffer->data, buffer->data + buffer->position, remaining);
|
memmove(buffer->data, buffer->data + buffer->position, remaining);
|
||||||
buffer->position = 0;
|
buffer->position = 0;
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
// buffer consumed completely, read another chunk
|
// buffer consumed completely, read another chunk
|
||||||
buffer->position = 0;
|
buffer->position = 0;
|
||||||
|
|
Loading…
Reference in a new issue