forked from h2zero/esp-nimble-cpp
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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user