diff options
Diffstat (limited to 'Frameworks')
-rw-r--r-- | Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m index d1de87a1..09988dbe 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m @@ -87,43 +87,45 @@ typedef struct { */ - (void)_threadedKeepAlive { - @synchronized(self) { - if(keepAliveThread) { - NSLog(@"warning: overwriting existing keepAliveThread: %@, results may be unpredictable!",keepAliveThread); + @autoreleasepool { + @synchronized(self) { + if(keepAliveThread) { + NSLog(@"warning: overwriting existing keepAliveThread: %@, results may be unpredictable!",keepAliveThread); + } + keepAliveThread = [NSThread currentThread]; } - keepAliveThread = [NSThread currentThread]; - } - - [keepAliveThread setName:[NSString stringWithFormat:@"SPMySQL connection keepalive monitor thread (id=%p)", self]]; - // If the maximum number of ping failures has been reached, determine whether to reconnect. - if (keepAliveLastPingBlocked || keepAlivePingFailures >= 3) { + [keepAliveThread setName:[NSString stringWithFormat:@"SPMySQL connection keepalive monitor thread (id=%p)", self]]; - // If the connection has been used within the last fifteen minutes, - // attempt a single reconnection in the background - if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < 60 * 15) { - [self _reconnectAfterBackgroundConnectionLoss]; - } - // Otherwise set the state to connection lost for automatic reconnect on - // next use. - else { - state = SPMySQLConnectionLostInBackground; - } + // If the maximum number of ping failures has been reached, determine whether to reconnect. + if (keepAliveLastPingBlocked || keepAlivePingFailures >= 3) { - // Return as no further ping action required this cycle. - goto end_cleanup; - } + // If the connection has been used within the last fifteen minutes, + // attempt a single reconnection in the background + if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < 60 * 15) { + [self _reconnectAfterBackgroundConnectionLoss]; + } + // Otherwise set the state to connection lost for automatic reconnect on + // next use. + else { + state = SPMySQLConnectionLostInBackground; + } - // Otherwise, perform a background ping. - BOOL pingResult = [self _pingConnectionUsingLoopDelay:10000]; - if (pingResult) { - keepAlivePingFailures = 0; - } else { - keepAlivePingFailures++; - } + // Return as no further ping action required this cycle. + goto end_cleanup; + } + + // Otherwise, perform a background ping. + BOOL pingResult = [self _pingConnectionUsingLoopDelay:10000]; + if (pingResult) { + keepAlivePingFailures = 0; + } else { + keepAlivePingFailures++; + } end_cleanup: - @synchronized(self) { - keepAliveThread = nil; + @synchronized(self) { + keepAliveThread = nil; + } } } |