Skip to content

Commit

Permalink
Fix Ble endpoint pool FULL on macOS controller (project-chip#7806)
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton36 authored Jul 1, 2021
1 parent baddb92 commit a917264
Showing 1 changed file with 5 additions and 5 deletions.
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, CHIP_ERROR_INCORRECT_STATE);
}
Expand Down

0 comments on commit a917264

Please sign in to comment.