aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/MCPKit/MCPFoundationKit
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks/MCPKit/MCPFoundationKit')
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m14
1 files changed, 12 insertions, 2 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
index 6b6ccc22..1a4786ec 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
@@ -660,12 +660,22 @@ void pingConnectionTask(void *ptr)
*/
- (void)startKeepAliveTimer
{
+
+ // Ensure keepalives are started on the main thread, as otherwise thread termination kills the timer
+ if (![NSThread isMainThread]) {
+ [self performSelectorOnMainThread:@selector(startKeepAliveTimer) withObject:nil waitUntilDone:NO];
+ return;
+ }
+
if (keepAliveTimer) [self stopKeepAliveTimer];
if (!mConnected) return;
- if (useKeepAlive && keepAliveInterval) {
+ double interval = keepAliveInterval;
+ if (interval <= 1) interval = 1.0;
+
+ if (useKeepAlive) {
keepAliveTimer = [NSTimer
- scheduledTimerWithTimeInterval:keepAliveInterval
+ scheduledTimerWithTimeInterval:interval
target:self
selector:@selector(keepAlive:)
userInfo:nil