aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m')
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m60
1 files changed, 31 insertions, 29 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
index ce980af8..e8692895 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
@@ -336,6 +336,8 @@ const char *SPMySQLSSLPermissibleCiphers = "DHE-RSA-AES256-SHA:AES256-SHA:DHE-RS
*
* WARNING: This method may return NO if the current thread is cancelled!
* You MUST check the isCancelled flag before using the result!
+ *
+ * NOTE: In general -checkConnectionIfNecessary should be used instead!
*/
- (BOOL)checkConnection
{
@@ -375,6 +377,35 @@ const char *SPMySQLSSLPermissibleCiphers = "DHE-RSA-AES256-SHA:AES256-SHA:DHE-RS
}
/**
+ * If thirty seconds have passed since the last time the connection was
+ * used, check the connection.
+ * This minimises the impact of continuous additional connection checks -
+ * each of which requires a round trip to the server - but handles most
+ * network issues.
+ * Returns whether the connection is considered still valid.
+ *
+ * WARNING: This method may return NO if the current thread is cancelled!
+ * You MUST check the isCancelled flag before using the result!
+ */
+- (BOOL)checkConnectionIfNecessary
+{
+
+ // If the connection has been dropped in the background, trigger a
+ // reconnect and return the success state here
+ if (state == SPMySQLConnectionLostInBackground) {
+ return [self _reconnectAllowingRetries:YES];
+ }
+
+ // If the connection was recently used, return success
+ if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < 30) {
+ return YES;
+ }
+
+ // Otherwise check the connection
+ return [self checkConnection];
+}
+
+/**
* Retrieve the time elapsed since the connection was established, in seconds.
* This time is retrieved in a monotonically increasing fashion and is high
* precision; it is used internally for query timing, and is reset on reconnections.
@@ -1043,35 +1074,6 @@ static uint64_t _elapsedMicroSecondsSinceAbsoluteTime(uint64_t comparisonTime)
}
/**
- * If thirty seconds have passed since the last time the connection was
- * used, check the connection.
- * This minimises the impact of continuous additional connection checks -
- * each of which requires a round trip to the server - but handles most
- * network issues.
- * Returns whether the connection is considered still valid.
- *
- * WARNING: This method may return NO if the current thread is cancelled!
- * You MUST check the isCancelled flag before using the result!
- */
-- (BOOL)_checkConnectionIfNecessary
-{
-
- // If the connection has been dropped in the background, trigger a
- // reconnect and return the success state here
- if (state == SPMySQLConnectionLostInBackground) {
- return [self _reconnectAllowingRetries:YES];
- }
-
- // If the connection was recently used, return success
- if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < 30) {
- return YES;
- }
-
- // Otherwise check the connection
- return [self checkConnection];
-}
-
-/**
* Ensure that the thread this method is called on has been registered for
* use with MySQL. MySQL requires thread-specific variables for safe
* execution.