[esp32_ble] Fix max_connections architecture (shared client+server limit) (#11006)
This commit is contained in:
1 parent
a3622d878d
commit
e8854e0659
8 files changed
+173
-79
No files matched your search
@@ -185,9 +185,38 @@ void BLEServer::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t ga
|
||||
}
|
||||
}
|
||||
|
||||
int8_t BLEServer::find_client_index_(uint16_t conn_id) const {
|
||||
for (uint8_t i = 0; i < this->client_count_; i++) {
|
||||
if (this->clients_[i] == conn_id)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void BLEServer::add_client_(uint16_t conn_id) {
|
||||
// Check if already in list
|
||||
if (this->find_client_index_(conn_id) >= 0)
|
||||
return;
|
||||
// Add if there's space
|
||||
if (this->client_count_ < USE_ESP32_BLE_MAX_CONNECTIONS) {
|
||||
this->clients_[this->client_count_++] = conn_id;
|
||||
} else {
|
||||
// This should never happen since max clients is known at compile time
|
||||
ESP_LOGE(TAG, "Client array full");
|
||||
}
|
||||
}
|
||||
|
||||
void BLEServer::remove_client_(uint16_t conn_id) {
|
||||
int8_t index = this->find_client_index_(conn_id);
|
||||
if (index >= 0) {
|
||||
// Replace with last element and decrement count (client order not preserved)
|
||||
this->clients_[index] = this->clients_[--this->client_count_];
|
||||
}
|
||||
}
|
||||
|
||||
void BLEServer::ble_before_disabled_event_handler() {
|
||||
// Delete all clients
|
||||
this->clients_.clear();
|
||||
this->client_count_ = 0;
|
||||
// Delete all services
|
||||
for (auto &entry : this->services_) {
|
||||
entry.service->do_delete();
|
||||
|
||||
Reference in new issue
Block a user