Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ble endpoint pool FULL on macOS controller #7806

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/platform/Darwin/BleConnectionDelegateImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ @interface BleConnection : NSObject <CBCentralManagerDelegate, CBPeripheralDeleg
@property (strong, nonatomic) CBPeripheral * peripheral;
@property (strong, nonatomic) CBUUID * shortServiceUUID;
@property (nonatomic, readonly, nullable) dispatch_source_t timer;
@property (unsafe_unretained, nonatomic) bool found;
@property (unsafe_unretained, nonatomic) uint16_t deviceDiscriminator;
@property (unsafe_unretained, nonatomic) void * appState;
@property (unsafe_unretained, nonatomic) BleConnectionDelegate::OnConnectionCompleteFunct onConnectionComplete;
Expand Down Expand Up @@ -103,6 +104,7 @@ - (id)initWithDiscriminator:(uint16_t)deviceDiscriminator
_chipWorkQueue = chip::DeviceLayer::PlatformMgrImpl().GetWorkQueue();
_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, _workQueue);
_centralManager = [CBCentralManager alloc];
_found = false;

dispatch_source_set_event_handler(_timer, ^{
[self stop];
Expand Down Expand Up @@ -206,17 +208,15 @@ - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)err
ChipLogError(Ble, "BLE:Error finding Chip Service in the device: [%s]", [error.localizedDescription UTF8String]);
}

bool found;

for (CBService * service in peripheral.services) {
if ([service.UUID.data isEqualToData:_shortServiceUUID.data]) {
found = true;
if ([service.UUID.data isEqualToData:_shortServiceUUID.data] && !self.found) {
[peripheral discoverCharacteristics:nil forService:service];
self.found = true;
break;
}
}

if (!found || error != nil) {
if (!self.found || error != nil) {
ChipLogError(Ble, "Service not found on the device.");
_onConnectionError(_appState, BLE_ERROR_INCORRECT_STATE);
}
Expand Down