diff options
Diffstat (limited to 'Source/CMMCPConnection.m')
-rw-r--r-- | Source/CMMCPConnection.m | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index 64315ff6..abb61d82 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -67,6 +67,10 @@ static void forcePingTimeout(int signalNumber); connectionPort = 0; connectionSocket = nil; keepAliveTimer = nil; + connectionTimeout = [[[NSUserDefaults standardUserDefaults] objectForKey:@"connectionTimeout"] intValue]; + if (!connectionTimeout) connectionTimeout = 10; + keepAliveInterval = [[[NSUserDefaults standardUserDefaults] objectForKey:@"keepAliveInterval"] doubleValue]; + if (!keepAliveInterval) keepAliveInterval = 0; lastKeepAliveSuccess = nil; lastQueryExecutionTime = 0; if (![NSBundle loadNibNamed:@"ConnectionErrorDialog" owner:self]) { @@ -93,7 +97,6 @@ static void forcePingTimeout(int signalNumber); if (socket) connectionSocket = [[NSString alloc] initWithString:socket]; if (mConnection != NULL) { - unsigned int connectionTimeout = SP_CONNECTION_TIMEOUT; mysql_options(mConnection, MYSQL_OPT_CONNECT_TIMEOUT, (const void *)&connectionTimeout); } @@ -158,7 +161,6 @@ static void forcePingTimeout(int signalNumber); if (mConnection != NULL) { // Set a connection timeout for the new connection - unsigned int connectionTimeout = SP_CONNECTION_TIMEOUT; mysql_options(mConnection, MYSQL_OPT_CONNECT_TIMEOUT, (const void *)&connectionTimeout); // Attempt to reestablish the connection - using own method so everything gets set up as standard. @@ -542,7 +544,7 @@ static void forcePingTimeout(int signalNumber); sigemptyset(&timeoutAction.sa_mask); timeoutAction.sa_flags = 0; sigaction(SIGALRM, &timeoutAction, NULL); - alarm(SP_CONNECTION_TIMEOUT+1); + alarm(connectionTimeout+1); // Set up a "restore point", returning 0; if longjmp is used later with this reference, execution // jumps back to this point and returns a nonzero value, so this function evaluates to false when initially @@ -587,28 +589,11 @@ 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; @@ -617,10 +602,9 @@ static void forcePingTimeout(int signalNumber) lastKeepAliveSuccess = nil; } - interval = [self keepAliveInterval]; - if (interval) { + if (keepAliveInterval) { keepAliveTimer = [NSTimer - scheduledTimerWithTimeInterval:interval + scheduledTimerWithTimeInterval:keepAliveInterval target:self selector:@selector(keepAlive:) userInfo:nil @@ -652,7 +636,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 * [self keepAliveInterval]) return; + if (lastKeepAliveSuccess && [lastKeepAliveSuccess timeIntervalSinceNow] < -5 * keepAliveInterval) return; [NSThread detachNewThreadSelector:@selector(threadedKeepAlive) toTarget:self withObject:nil]; [self startKeepAliveTimerResettingState:NO]; |