Skip to content

Commit 25206a8

Browse files
authored
Merge pull request #6513 from dhalbert/7.3.x-6495-backport-ble-disconnect-check
Test for a BLE disconnect while reading
2 parents d8badb5 + e8023f3 commit 25206a8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,12 @@ STATIC bool _on_gattc_read_rsp_evt(ble_evt_t *ble_evt, void *param) {
185185
}
186186
break;
187187
}
188-
188+
case BLE_GAP_EVT_DISCONNECTED: {
189+
read->conn_handle = BLE_CONN_HANDLE_INVALID;
190+
read->done = true;
191+
return false;
192+
break;
193+
}
189194
default:
190195
// For debugging.
191196
// mp_printf(&mp_plat_print, "Unhandled characteristic event: 0x%04x\n", ble_evt->header.evt_id);
@@ -219,6 +224,8 @@ size_t common_hal_bleio_gattc_read(uint16_t handle, uint16_t conn_handle, uint8_
219224
while (!read_info.done) {
220225
RUN_BACKGROUND_TASKS;
221226
}
227+
// Test if we were disconnected while reading
228+
common_hal_bleio_check_connected(read_info.conn_handle);
222229

223230
ble_drv_remove_event_handler(_on_gattc_read_rsp_evt, &read_info);
224231
check_gatt_status(read_info.status);

0 commit comments

Comments
 (0)