@@ -106,13 +106,16 @@ STATIC uint32_t queue_next_write(bleio_packet_buffer_obj_t *self) {
106
106
107
107
STATIC bool packet_buffer_on_ble_client_evt (ble_evt_t * ble_evt , void * param ) {
108
108
const uint16_t evt_id = ble_evt -> header .evt_id ;
109
+ bleio_packet_buffer_obj_t * self = (bleio_packet_buffer_obj_t * )param ;
110
+ if (evt_id == BLE_GAP_EVT_DISCONNECTED && self -> conn_handle == ble_evt -> evt .gap_evt .conn_handle ) {
111
+ self -> conn_handle = BLE_CONN_HANDLE_INVALID ;
112
+ }
109
113
// Check if this is a GATTC event so we can make sure the conn_handle is valid.
110
114
if (evt_id < BLE_GATTC_EVT_BASE || evt_id > BLE_GATTC_EVT_LAST ) {
111
115
return false;
112
116
}
113
117
114
118
uint16_t conn_handle = ble_evt -> evt .gattc_evt .conn_handle ;
115
- bleio_packet_buffer_obj_t * self = (bleio_packet_buffer_obj_t * )param ;
116
119
if (conn_handle != self -> conn_handle ) {
117
120
return false;
118
121
}
@@ -298,11 +301,14 @@ mp_int_t common_hal_bleio_packet_buffer_write(bleio_packet_buffer_obj_t *self, u
298
301
if (len + self -> pending_size > outgoing_packet_length ) {
299
302
// No room to append len bytes to packet. Wait until we get a free buffer,
300
303
// and keep checking that we haven't been disconnected.
301
- while (self -> pending_size != 0 && self -> conn_handle != BLE_CONN_HANDLE_INVALID ) {
304
+ while (self -> pending_size != 0 &&
305
+ self -> conn_handle != BLE_CONN_HANDLE_INVALID &&
306
+ !mp_hal_is_interrupted ()) {
302
307
RUN_BACKGROUND_TASKS ;
303
308
}
304
309
}
305
- if (self -> conn_handle == BLE_CONN_HANDLE_INVALID ) {
310
+ if (self -> conn_handle == BLE_CONN_HANDLE_INVALID ||
311
+ mp_hal_is_interrupted ()) {
306
312
return -1 ;
307
313
}
308
314
0 commit comments