From e185e73e733edc9357e3642a4bb1fc9b9f2c0748 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Wed, 3 Nov 2010 23:55:22 +0000 Subject: - Improve query disconnection/reconnection while pings or queries are still active or cleaning up --- Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'Frameworks') diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index 48509969..653f9b2f 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -502,9 +502,20 @@ static BOOL sTruncateLongFieldInLogs = YES; if (mConnected) { [self cancelCurrentQuery]; mConnected = NO; - - // Small pause for cleanup. - usleep(100000); + + // Allow any pings or query cleanups to complete - within a time limit. + uint64_t startTime_t, currentTime_t; + Nanoseconds elapsedNanoseconds; + startTime_t = mach_absolute_time(); + do { + usleep(100000); + + currentTime_t = mach_absolute_time() - startTime_t ; + elapsedNanoseconds = AbsoluteToNanoseconds(*(AbsoluteTime *)&(currentTime_t)); + if (((double)UnsignedWideToUInt64(elapsedNanoseconds)) * 1e-9 > 10) break; + } while (![self tryLockConnection]); + [self unlockConnection]; + if (mConnection->net.vio && mConnection->net.buff) mysql_close(mConnection); mConnection = NULL; } @@ -544,6 +555,20 @@ static BOOL sTruncateLongFieldInLogs = YES; // Close the connection if it exists. if (mConnected) { + + // Allow any pings or query cleanups to complete - within a time limit. + uint64_t startTime_t, currentTime_t; + Nanoseconds elapsedNanoseconds; + startTime_t = mach_absolute_time(); + do { + usleep(100000); + + currentTime_t = mach_absolute_time() - startTime_t ; + elapsedNanoseconds = AbsoluteToNanoseconds(*(AbsoluteTime *)&(currentTime_t)); + if (((double)UnsignedWideToUInt64(elapsedNanoseconds)) * 1e-9 > 10) break; + } while (![self tryLockConnection]); + [self unlockConnection]; + if (mConnection->net.vio && mConnection->net.buff) mysql_close(mConnection); mConnection = NULL; } -- cgit v1.2.3