aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-03-22 00:32:47 +0000
committerrowanbeentje <rowan@beent.je>2010-03-22 00:32:47 +0000
commit1c037fd0f3014833dd3c47d5c1b30d0e525536db (patch)
tree61fd80166bf16cc8461fa2b75bbb10f5a9239c80
parentb5cabd449156acaf18815759ee4cc5383e8fa4f6 (diff)
downloadsequelpro-1c037fd0f3014833dd3c47d5c1b30d0e525536db.tar.gz
sequelpro-1c037fd0f3014833dd3c47d5c1b30d0e525536db.tar.bz2
sequelpro-1c037fd0f3014833dd3c47d5c1b30d0e525536db.zip
- Tweak keepalive process, ensuring keepalives have a minimum time separation and fixing thread compatibility (not mentioned in docs but it seems NSTimers from terminated threads also terminate!)
-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