diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMMCPConnection.h | 1 | ||||
-rw-r--r-- | Source/CMMCPConnection.m | 42 |
2 files changed, 33 insertions, 10 deletions
diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h index 584b8056..e6479eb1 100644 --- a/Source/CMMCPConnection.h +++ b/Source/CMMCPConnection.h @@ -71,6 +71,7 @@ - (void) setDelegate:(id)object; - (NSTimeZone *) timeZone; - (BOOL) pingConnection; +- (double) keepAliveInterval; - (void) startKeepAliveTimerResettingState:(BOOL)resetState; - (void) stopKeepAliveTimer; - (void) keepAlive:(NSTimer *)theTimer; diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index 14cd6ba7..109ab280 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -68,7 +68,9 @@ static void forcePingTimeout(int signalNumber); connectionSocket = nil; keepAliveTimer = nil; lastKeepAliveSuccess = nil; - [NSBundle loadNibNamed:@"ConnectionErrorDialog" owner:self]; + if (![NSBundle loadNibNamed:@"ConnectionErrorDialog" owner:self]) { + NSLog(@"Connection error dialog could not be loaded; connection failure handling will not function correctly."); + } } @@ -567,11 +569,28 @@ static void forcePingTimeout(int signalNumber) longjmp(pingTimeoutJumpLocation, 1); } + +/* + * Returns the keepalive interval, or 0 if keepalive should be disabled. + * Sequel Pro draws this from the preferences with a default of 60 secs. + */ +- (double) keepAliveInterval +{ + double interval; + + interval = [[[NSUserDefaults standardUserDefaults] objectForKey:@"keepAliveInterval"] doubleValue]; + if (!interval) interval = 0; + + return interval; +} + /* * Restarts a keepalive to fire in the future. */ - (void) startKeepAliveTimerResettingState:(BOOL)resetState { + double interval; + if (keepAliveTimer) [self stopKeepAliveTimer]; if (!mConnected) return; @@ -579,14 +598,17 @@ static void forcePingTimeout(int signalNumber) [lastKeepAliveSuccess release]; lastKeepAliveSuccess = nil; } - - keepAliveTimer = [NSTimer - scheduledTimerWithTimeInterval:[[[NSUserDefaults standardUserDefaults] objectForKey:@"keepAliveInterval"] doubleValue] - target:self - selector:@selector(keepAlive:) - userInfo:nil - repeats:NO]; - [keepAliveTimer retain]; + + interval = [self keepAliveInterval]; + if (interval) { + keepAliveTimer = [NSTimer + scheduledTimerWithTimeInterval:interval + target:self + selector:@selector(keepAlive:) + userInfo:nil + repeats:NO]; + [keepAliveTimer retain]; + } } /* @@ -612,7 +634,7 @@ static void forcePingTimeout(int signalNumber) // cut but mysql doesn't pick up on the fact - see comment for pingConnection above. The same // forced-timeout approach cannot be used here on a background thread. // When the connection is disconnected in code, these 5 "hanging" threads are automatically cleaned. - if (lastKeepAliveSuccess && [lastKeepAliveSuccess timeIntervalSinceNow] < -5 * [[[NSUserDefaults standardUserDefaults] objectForKey:@"keepAliveInterval"] doubleValue]) return; + if (lastKeepAliveSuccess && [lastKeepAliveSuccess timeIntervalSinceNow] < -5 * [self keepAliveInterval]) return; [NSThread detachNewThreadSelector:@selector(threadedKeepAlive) toTarget:self withObject:nil]; [self startKeepAliveTimerResettingState:NO]; |