diff options
author | Michael Kinney <michaelakinney@comcast.net> | 2021-02-12 16:40:03 -0500 |
---|---|---|
committer | Michael Kinney <michaelakinney@comcast.net> | 2021-02-12 16:40:03 -0500 |
commit | aef11aca68bbf90e4d4f443f75f31a575ccce828 (patch) | |
tree | c690f9e2447138a71c8f9c9d6a0af03c0ffc9208 | |
parent | 255fbdff1122ac3cd2a0ea72fbb71b48b29e9ea8 (diff) | |
download | sdl_ios-aef11aca68bbf90e4d4f443f75f31a575ccce828.tar.gz |
ensure easession is always closed on easessions thread
-rw-r--r-- | SmartDeviceLink/private/SDLIAPSession.m | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/SmartDeviceLink/private/SDLIAPSession.m b/SmartDeviceLink/private/SDLIAPSession.m index 0a421a448..1e0827086 100644 --- a/SmartDeviceLink/private/SDLIAPSession.m +++ b/SmartDeviceLink/private/SDLIAPSession.m @@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) BOOL inputStreamOpen; @property (nonatomic) BOOL outputStreamOpen; @property (nonatomic) BOOL runTheLoop; +@property (nonatomic, weak) NSThread *sessionThread; @end @@ -64,6 +65,7 @@ NS_ASSUME_NONNULL_BEGIN - (void) startSession { dispatch_async(self.iapSessionQueue, ^{ self.eaSession = [[EASession alloc] initWithAccessory:self.accessory forProtocol:self.protocolString]; + self.sessionThread = NSThread.currentThread; SDLLogD(@"Created EASession with %@ Protocol and EASession is %@", self.protocolString, self.eaSession); if (self.eaSession != nil) { [self openStreams]; @@ -113,12 +115,20 @@ NS_ASSUME_NONNULL_BEGIN } - (void) closeSession { - [self stopStreamRunLoop]; + bool waitUntilDone = NO; + if (NSThread.currentThread == self.sessionThread) { + waitUntilDone = YES; + } + [self performSelector:@selector(peformCloseSession) onThread:self.sessionThread withObject:nil waitUntilDone:waitUntilDone]; +} + +- (void) peformCloseSession { SDLLogD(@"Closing EASession streams"); if (self.eaSession != nil) { [self close: self.eaSession.inputStream]; [self close: self.eaSession.outputStream]; self.eaSession = nil; + [self stopStreamRunLoop]; } else { SDLLogD(@"Failed to close streams because EASession is already nil"); } |