mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-24 14:10:55 +01:00
Correct client connection status signalling.
* NimBLEClient::disconnect() was setting the connected flag to false before the disconnection occured. * NimBLEDevice::deleteClient() was not waiting for disconnection if it was already in progress. * Client gap event handler was releasing the connection event semaphore when it should not.
This commit is contained in:
parent
143631d327
commit
44f16e6ee2
2 changed files with 12 additions and 9 deletions
|
@ -242,15 +242,11 @@ int NimBLEClient::disconnect(uint8_t reason) {
|
|||
NIMBLE_LOGD(LOG_TAG, ">> disconnect()");
|
||||
int rc = 0;
|
||||
if(m_isConnected){
|
||||
m_isConnected = false; // flag the disconnect now so no calls are performed after
|
||||
rc = ble_gap_terminate(m_conn_id, reason);
|
||||
if(rc != 0){
|
||||
NIMBLE_LOGE(LOG_TAG, "ble_gap_terminate failed: rc=%d %s", rc,
|
||||
NimBLEUtils::returnCodeToString(rc));
|
||||
}
|
||||
// Sometimes a disconnect event is not sent so we need to make sure
|
||||
// the device can be found again.
|
||||
NimBLEDevice::removeIgnored(m_peerAddress);
|
||||
}
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< disconnect()");
|
||||
|
@ -711,8 +707,10 @@ uint16_t NimBLEClient::getMTU() {
|
|||
NIMBLE_LOGE(LOG_TAG, "Error: Connection failed; status=%d %s",
|
||||
event->connect.status,
|
||||
NimBLEUtils::returnCodeToString(event->connect.status));
|
||||
|
||||
client->m_isConnected = false;
|
||||
client->m_semaphoreOpenEvt.give(event->connect.status);
|
||||
}
|
||||
client->m_semaphoreOpenEvt.give(event->connect.status);
|
||||
return 0;
|
||||
} // BLE_GAP_EVENT_CONNECT
|
||||
|
||||
|
|
|
@ -152,21 +152,26 @@ void NimBLEDevice::stopAdvertising() {
|
|||
return false;
|
||||
}
|
||||
|
||||
int rc =0;
|
||||
|
||||
if(pClient->m_isConnected) {
|
||||
if (pClient->disconnect() != 0) {
|
||||
rc = pClient->disconnect();
|
||||
if (rc != 0 && rc != BLE_HS_EALREADY && rc != BLE_HS_ENOTCONN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while(pClient->m_isConnected) {
|
||||
vTaskDelay(1);
|
||||
vTaskDelay(10);
|
||||
}
|
||||
}
|
||||
|
||||
if(pClient->m_waitingToConnect) {
|
||||
if(ble_gap_conn_cancel() != 0){
|
||||
rc = ble_gap_conn_cancel();
|
||||
if (rc != 0 && rc != BLE_HS_EALREADY) {
|
||||
return false;
|
||||
}
|
||||
while(pClient->m_waitingToConnect) {
|
||||
vTaskDelay(1);
|
||||
vTaskDelay(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue