summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2020-05-01 09:56:55 -0400
committerJoel Fischer <joeljfischer@gmail.com>2020-05-01 09:56:55 -0400
commit4b0954298b7a38e4fe52dcb0d84c8276774d083c (patch)
tree560c03249e7319ac03944de330cfa2811db5fb2b
parenta1519df2532bbd20981ecfb6464fb95c4c2e2ed1 (diff)
downloadsdl_ios-4b0954298b7a38e4fe52dcb0d84c8276774d083c.tar.gz
Fix TCP transport code no longer running on the correct thread
-rw-r--r--SmartDeviceLink/SDLTCPTransport.m2
-rw-r--r--SmartDeviceLink/SDLTimer.h1
-rw-r--r--SmartDeviceLink/SDLTimer.m8
3 files changed, 8 insertions, 3 deletions
diff --git a/SmartDeviceLink/SDLTCPTransport.m b/SmartDeviceLink/SDLTCPTransport.m
index 356d298f0..0dc347f8a 100644
--- a/SmartDeviceLink/SDLTCPTransport.m
+++ b/SmartDeviceLink/SDLTCPTransport.m
@@ -132,7 +132,7 @@ NSTimeInterval ConnectionTimeoutSecs = 30.0;
self.connectionTimer.elapsedBlock = ^{
[weakSelf sdl_onConnectionTimedOut];
};
- [self.connectionTimer start];
+ [self.connectionTimer startOnRunLoop:[NSRunLoop currentRunLoop]];
// these will initiate a connection to remote server
SDLLogD(@"Connecting to %@:%@ ...", self.hostName, self.portNumber);
diff --git a/SmartDeviceLink/SDLTimer.h b/SmartDeviceLink/SDLTimer.h
index f7c3cb46b..cd414bdcf 100644
--- a/SmartDeviceLink/SDLTimer.h
+++ b/SmartDeviceLink/SDLTimer.h
@@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithDuration:(NSTimeInterval)duration;
- (instancetype)initWithDuration:(NSTimeInterval)duration repeat:(BOOL)repeat;
- (void)start;
+- (void)startOnRunLoop:(NSRunLoop *)runLoop;
- (void)cancel;
@end
diff --git a/SmartDeviceLink/SDLTimer.m b/SmartDeviceLink/SDLTimer.m
index c9a162bd7..dd848c2f0 100644
--- a/SmartDeviceLink/SDLTimer.m
+++ b/SmartDeviceLink/SDLTimer.m
@@ -74,12 +74,16 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)start {
+ [self startOnRunLoop:[NSRunLoop mainRunLoop]];
+}
+
+- (void)startOnRunLoop:(NSRunLoop *)runLoop {
if (self.duration > 0) {
[self stopAndDestroyTimer];
-
+
SDLTimerTarget *timerTarget = [[SDLTimerTarget alloc] initWithDelegate:self];
self.timer = [NSTimer timerWithTimeInterval:self.duration target:timerTarget selector:@selector(timerElapsed) userInfo:nil repeats:_repeat];
- [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
+ [runLoop addTimer:self.timer forMode:NSRunLoopCommonModes];
self.timerRunning = YES;
}
}