Fix endless loop when calling scan start from scan end callback.

When attempting to connect and the scanner is running `NimBLEScan::stop` is called to stop it
which then calls the `onScanEnded` callback. If the app then starts the scan again in this
callback an endless loop will be created.

This change prevents the endless loop by setting a flag in `NimBLEDevice` that is checked before
starting a scan while a client is trying to connect.

* Adds `NimBLEDevice::setConnectionInProgress` and `NimBLEDevice::isConnectionInProgress` functions.
This commit is contained in:
h2zero
2024-11-10 10:36:51 -07:00
committed by h2zero
parent 7d0636bc91
commit 724e1a7083
4 changed files with 37 additions and 2 deletions
+5
View File
@@ -292,6 +292,11 @@ bool NimBLEScan::isScanning() {
bool NimBLEScan::start(uint32_t duration, bool is_continue) {
NIMBLE_LOGD(LOG_TAG, ">> start: duration=%" PRIu32, duration);
if (NimBLEDevice::isConnectionInProgress()) {
NIMBLE_LOGE(LOG_TAG, "Connection in progress, cannot start scan");
return false;
}
// Save the duration in the case that the host is reset so we can reuse it.
m_duration = duration;