From b7836aeac67c32b940ac38ee967e30a24ce8cf6f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 4 May 2020 19:51:08 -0400 Subject: address review comments --- ports/nrf/common-hal/_bleio/PacketBuffer.c | 4 ++++ shared-bindings/_bleio/PacketBuffer.c | 10 ++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/ports/nrf/common-hal/_bleio/PacketBuffer.c b/ports/nrf/common-hal/_bleio/PacketBuffer.c index 37f584664..a8773f961 100644 --- a/ports/nrf/common-hal/_bleio/PacketBuffer.c +++ b/ports/nrf/common-hal/_bleio/PacketBuffer.c @@ -267,6 +267,10 @@ mp_int_t common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self if (packet_length > len) { // Packet is longer than requested. Return negative of overrun value. ret = len - packet_length; + // Discard the packet if it's too large. Don't fill data. + while (packet_length--) { + (void) ringbuf_get(&self->ringbuf); + } } else { // Read as much as possible, but might be shorter than len. ringbuf_get_n(&self->ringbuf, data, packet_length); diff --git a/shared-bindings/_bleio/PacketBuffer.c b/shared-bindings/_bleio/PacketBuffer.c index 1520c8b5c..e087cf22d 100644 --- a/shared-bindings/_bleio/PacketBuffer.c +++ b/shared-bindings/_bleio/PacketBuffer.c @@ -190,16 +190,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_packet_buffer_deinit_obj, bleio_packet_bu //| .. attribute:: incoming_packet_length //| //| Maximum length in bytes of a packet we are reading. -//| If the packet is arriving from a remote service via notify or indicate, -//| the maximum length is `Connection.max_packet_length`. -//| Otherwise it is the ``max_length`` of the :py:class:`~_bleio.Characteristic`. //| STATIC mp_obj_t bleio_packet_buffer_get_incoming_packet_length(mp_obj_t self_in) { bleio_packet_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t size = common_hal_bleio_packet_buffer_get_incoming_packet_length(self); if (size < 0) { - mp_raise_ValueError(translate("No connection: size cannot be determined")); + mp_raise_ValueError(translate("No connection: length cannot be determined")); } return MP_OBJ_NEW_SMALL_INT(size); } @@ -215,16 +212,13 @@ const mp_obj_property_t bleio_packet_buffer_incoming_packet_length_obj = { //| .. attribute:: outgoing_packet_length //| //| Maximum length in bytes of a packet we are writing. -//| If the packet is being sent via notify or indicate, -//| the maximum length is `Connection.max_packet_length`. -//| Otherwise it is the ``max_length`` of the :py:class:`~_bleio.Characteristic`. //| STATIC mp_obj_t bleio_packet_buffer_get_outgoing_packet_length(mp_obj_t self_in) { bleio_packet_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t size = common_hal_bleio_packet_buffer_get_outgoing_packet_length(self); if (size < 0) { - mp_raise_ValueError(translate("No connection: size cannot be determined")); + mp_raise_ValueError(translate("No connection: length cannot be determined")); } return MP_OBJ_NEW_SMALL_INT(size); } -- cgit v1.2.3