Skip to content

Commit b7836ae

Browse files
committed
address review comments
1 parent bae7a5e commit b7836ae

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

ports/nrf/common-hal/_bleio/PacketBuffer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ mp_int_t common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self
267267
if (packet_length > len) {
268268
// Packet is longer than requested. Return negative of overrun value.
269269
ret = len - packet_length;
270+
// Discard the packet if it's too large. Don't fill data.
271+
while (packet_length--) {
272+
(void) ringbuf_get(&self->ringbuf);
273+
}
270274
} else {
271275
// Read as much as possible, but might be shorter than len.
272276
ringbuf_get_n(&self->ringbuf, data, packet_length);

shared-bindings/_bleio/PacketBuffer.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_packet_buffer_deinit_obj, bleio_packet_bu
190190
//| .. attribute:: incoming_packet_length
191191
//|
192192
//| Maximum length in bytes of a packet we are reading.
193-
//| If the packet is arriving from a remote service via notify or indicate,
194-
//| the maximum length is `Connection.max_packet_length`.
195-
//| Otherwise it is the ``max_length`` of the :py:class:`~_bleio.Characteristic`.
196193
//|
197194
STATIC mp_obj_t bleio_packet_buffer_get_incoming_packet_length(mp_obj_t self_in) {
198195
bleio_packet_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);
199196

200197
mp_int_t size = common_hal_bleio_packet_buffer_get_incoming_packet_length(self);
201198
if (size < 0) {
202-
mp_raise_ValueError(translate("No connection: size cannot be determined"));
199+
mp_raise_ValueError(translate("No connection: length cannot be determined"));
203200
}
204201
return MP_OBJ_NEW_SMALL_INT(size);
205202
}
@@ -215,16 +212,13 @@ const mp_obj_property_t bleio_packet_buffer_incoming_packet_length_obj = {
215212
//| .. attribute:: outgoing_packet_length
216213
//|
217214
//| Maximum length in bytes of a packet we are writing.
218-
//| If the packet is being sent via notify or indicate,
219-
//| the maximum length is `Connection.max_packet_length`.
220-
//| Otherwise it is the ``max_length`` of the :py:class:`~_bleio.Characteristic`.
221215
//|
222216
STATIC mp_obj_t bleio_packet_buffer_get_outgoing_packet_length(mp_obj_t self_in) {
223217
bleio_packet_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);
224218

225219
mp_int_t size = common_hal_bleio_packet_buffer_get_outgoing_packet_length(self);
226220
if (size < 0) {
227-
mp_raise_ValueError(translate("No connection: size cannot be determined"));
221+
mp_raise_ValueError(translate("No connection: length cannot be determined"));
228222
}
229223
return MP_OBJ_NEW_SMALL_INT(size);
230224
}

0 commit comments

Comments
 (0)