From d4b8b5fcf2ea8962011a848e48fdfe3324a5453d Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Mon, 27 Jan 2020 12:55:49 -0800 Subject: [PATCH] drivers: modem: socket: allow partial packet reads Let's allow protocols to request portions of the current packet. This is seen in the MQTT library when parsing headers for the type and variable length of the packet. This fixes basic parsing done in the MQTT library and probably others. Signed-off-by: Michael Scott --- drivers/modem/modem_socket.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/modem/modem_socket.c b/drivers/modem/modem_socket.c index aa264023317..baff5b50b0f 100644 --- a/drivers/modem/modem_socket.c +++ b/drivers/modem/modem_socket.c @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2019 Foundries.io + * Copyright (c) 2019-2020 Foundries.io * * SPDX-License-Identifier: Apache-2.0 */ @@ -82,6 +82,12 @@ int modem_socket_packet_size_update(struct modem_socket_config *cfg, if (new_total < old_total) { /* remove packets that are not included in new_size */ while (old_total > new_total && sock->packet_count > 0) { + /* handle partial read */ + if (old_total - new_total < sock->packet_sizes[0]) { + sock->packet_sizes[0] -= old_total - new_total; + break; + } + old_total -= sock->packet_sizes[0]; modem_socket_packet_drop_first(sock); }