mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Fixes a potential crash when shutting down a BleMedium.
PiperOrigin-RevId: 792365629
This commit is contained in:
committed by
Copybara-Service
parent
0847245618
commit
e95b44cf61
@@ -238,6 +238,11 @@ typedef void (^GNCGATTConnectionCompletionHandler)(GNCBLEGATTClient *_Nullable c
|
||||
peripheral:(id<GNCPeripheral>)remotePeripheral
|
||||
completionHandler:(nullable GNCOpenL2CAPStreamCompletionHandler)completionHandler;
|
||||
|
||||
/**
|
||||
* Stops all BLE operations.
|
||||
*/
|
||||
- (void)stop;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -34,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
static char *const kBLEMediumQueueLabel = "com.nearby.GNCBLEMedium";
|
||||
// TODO: b/762454867 - Make this a flag.
|
||||
static const NSTimeInterval kPeripheralConnectTimeout = 10.0; // 10 seconds timeout
|
||||
static const NSTimeInterval kStopTimeout = 5.0;
|
||||
|
||||
static NSError *AlreadyScanningError() {
|
||||
return [NSError errorWithDomain:GNCBLEErrorDomain code:GNCBLEErrorAlreadyScanning userInfo:nil];
|
||||
@@ -122,8 +123,17 @@ static GNCBLEL2CAPServer *_Nonnull CreateL2CapServer(
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self cancelConnectionTimeout];
|
||||
- (void)stop {
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
dispatch_async(_queue, ^{
|
||||
[self cancelConnectionTimeout];
|
||||
dispatch_semaphore_signal(semaphore);
|
||||
});
|
||||
dispatch_time_t timeout =
|
||||
dispatch_time(DISPATCH_TIME_NOW, kStopTimeout * NSEC_PER_SEC); // 5 seconds timeout
|
||||
if (dispatch_semaphore_wait(semaphore, timeout) != 0) {
|
||||
GNCLoggerError(@"GNCBLEMedium stop timeout.");
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)supportsExtendedAdvertisements {
|
||||
|
||||
Reference in New Issue
Block a user