summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kinney <michaelakinney@comcast.net>2021-02-12 16:40:03 -0500
committerMichael Kinney <michaelakinney@comcast.net>2021-02-12 16:40:03 -0500
commitaef11aca68bbf90e4d4f443f75f31a575ccce828 (patch)
treec690f9e2447138a71c8f9c9d6a0af03c0ffc9208
parent255fbdff1122ac3cd2a0ea72fbb71b48b29e9ea8 (diff)
downloadsdl_ios-aef11aca68bbf90e4d4f443f75f31a575ccce828.tar.gz
ensure easession is always closed on easessions thread
-rw-r--r--SmartDeviceLink/private/SDLIAPSession.m12
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");
}