diff options
author | rowanbeentje <rowan@beent.je> | 2009-03-28 01:48:37 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-03-28 01:48:37 +0000 |
commit | 808a76c28f2346befc38a7b6e744987b2bedace1 (patch) | |
tree | 49fdbed7febdf85bf6cc4dad76a89e2f87a80169 /Source/CMMCPConnection.m | |
parent | 905a44014caa805f2b2621bedef3a76da259c8b1 (diff) | |
download | sequelpro-808a76c28f2346befc38a7b6e744987b2bedace1.tar.gz sequelpro-808a76c28f2346befc38a7b6e744987b2bedace1.tar.bz2 sequelpro-808a76c28f2346befc38a7b6e744987b2bedace1.zip |
- Add a preference (currently with no UI) for connection timeout
- Improve connection error messages slightly.
- Avoid reading prefs for every keepalive check - now sets connection timeout and keepalive interval on connection setup
- Fix and extend connection checks to avoid showing extra errors when the connection has been closed
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]; |