aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/MCPKit/MCPFoundationKit
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-03-11 01:15:00 +0000
committerrowanbeentje <rowan@beent.je>2010-03-11 01:15:00 +0000
commitcc016857a5602f1defa6972ab8254e105ae1f4ba (patch)
treeb6c5fffa6648ed7ad31ac9a5585bd64578038ed0 /Frameworks/MCPKit/MCPFoundationKit
parente92951358fd80fb42f33fe4ce0e33a39939a9bf3 (diff)
downloadsequelpro-cc016857a5602f1defa6972ab8254e105ae1f4ba.tar.gz
sequelpro-cc016857a5602f1defa6972ab8254e105ae1f4ba.tar.bz2
sequelpro-cc016857a5602f1defa6972ab8254e105ae1f4ba.zip
- Use a modified connection timeout for the keepalive ping timeout, topping out at 30 seconds to prevent sleeping threads
- Improve keepalive timer interaction
Diffstat (limited to 'Frameworks/MCPKit/MCPFoundationKit')
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m18
1 files changed, 13 insertions, 5 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
index a1feb05b..2f2a8858 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
@@ -402,6 +402,8 @@ static BOOL sTruncateLongFieldInLogs = YES;
*/
- (void)disconnect
{
+ [self stopKeepAliveTimer];
+
if (mConnected) {
mysql_close(mConnection);
mConnection = NULL;
@@ -415,9 +417,7 @@ static BOOL sTruncateLongFieldInLogs = YES;
if (serverVersionString) [serverVersionString release], serverVersionString = nil;
if (theDbStructure) [theDbStructure release], theDbStructure = nil;
- if (uniqueDbIdentifier) [uniqueDbIdentifier release], uniqueDbIdentifier = nil;
-
- [self stopKeepAliveTimer];
+ if (uniqueDbIdentifier) [uniqueDbIdentifier release], uniqueDbIdentifier = nil;
if (pingThread != NULL) pthread_cancel(pingThread), pingThread = NULL;
}
@@ -448,6 +448,7 @@ static BOOL sTruncateLongFieldInLogs = YES;
}
// Close the connection if it exists.
+ [self stopKeepAliveTimer];
if (mConnected) {
mysql_close(mConnection);
mConnection = NULL;
@@ -693,6 +694,10 @@ void pingConnectionTask(void *ptr)
{
if (!mConnected || keepAliveThread != NULL) return;
+ // Use a ping timeout between zero and thirty seconds
+ NSInteger pingTimeout = 30;
+ if (connectionTimeout > 0 && connectionTimeout < pingTimeout) pingTimeout = connectionTimeout;
+
// Attempt to get a query lock, but release it to ensure the connection isn't locked
// by a background ping.
if (![queryLock tryLock]) return;
@@ -701,9 +706,9 @@ void pingConnectionTask(void *ptr)
// Create a pthread for the actual keepalive
pthread_create(&keepAliveThread, NULL, (void *)&performThreadedKeepAlive, (void *)mConnection);
- // Give the connection time to respond, but force a timeout after the connection timeout
+ // Give the connection time to respond, but force a timeout after the ping timeout
// if the thread hasn't already closed itself.
- sleep(connectionTimeout);
+ sleep(pingTimeout);
pthread_cancel(keepAliveThread);
keepAliveThread = NULL;
}
@@ -726,6 +731,9 @@ void performThreadedKeepAlive(void *ptr)
connectionStartTime = mach_absolute_time();
[self fetchMaxAllowedPacket];
+ [self stopKeepAliveTimer];
+ [self startKeepAliveTimer];
+
if (delegate && [delegate respondsToSelector:@selector(onReconnectShouldUseEncoding:)]) {
[self queryString:[NSString stringWithFormat:@"/*!40101 SET NAMES '%@' */", [NSString stringWithString:[delegate onReconnectShouldUseEncoding:self]]]];
if (delegate && [delegate respondsToSelector:@selector(connectionEncodingViaLatin1:)]) {