@@ -336,6 +336,8 @@ - (BOOL)isConnectedViaSSL
336
336
*
337
337
* WARNING: This method may return NO if the current thread is cancelled!
338
338
* You MUST check the isCancelled flag before using the result!
339
+ *
340
+ * NOTE: In general -checkConnectionIfNecessary should be used instead!
339
341
*/
340
342
- (BOOL )checkConnection
341
343
{
@@ -374,6 +376,35 @@ - (BOOL)checkConnection
374
376
return connectionVerified;
375
377
}
376
378
379
+ /* *
380
+ * If thirty seconds have passed since the last time the connection was
381
+ * used, check the connection.
382
+ * This minimises the impact of continuous additional connection checks -
383
+ * each of which requires a round trip to the server - but handles most
384
+ * network issues.
385
+ * Returns whether the connection is considered still valid.
386
+ *
387
+ * WARNING: This method may return NO if the current thread is cancelled!
388
+ * You MUST check the isCancelled flag before using the result!
389
+ */
390
+ - (BOOL )checkConnectionIfNecessary
391
+ {
392
+
393
+ // If the connection has been dropped in the background, trigger a
394
+ // reconnect and return the success state here
395
+ if (state == SPMySQLConnectionLostInBackground) {
396
+ return [self _reconnectAllowingRetries: YES ];
397
+ }
398
+
399
+ // If the connection was recently used, return success
400
+ if (_elapsedSecondsSinceAbsoluteTime (lastConnectionUsedTime) < 30 ) {
401
+ return YES ;
402
+ }
403
+
404
+ // Otherwise check the connection
405
+ return [self checkConnection ];
406
+ }
407
+
377
408
/* *
378
409
* Retrieve the time elapsed since the connection was established, in seconds.
379
410
* This time is retrieved in a monotonically increasing fashion and is high
@@ -1042,35 +1073,6 @@ - (void)_restoreConnectionVariables
1042
1073
[self setEncodingUsesLatin1Transport: encodingUsesLatin1Transport];
1043
1074
}
1044
1075
1045
- /* *
1046
- * If thirty seconds have passed since the last time the connection was
1047
- * used, check the connection.
1048
- * This minimises the impact of continuous additional connection checks -
1049
- * each of which requires a round trip to the server - but handles most
1050
- * network issues.
1051
- * Returns whether the connection is considered still valid.
1052
- *
1053
- * WARNING: This method may return NO if the current thread is cancelled!
1054
- * You MUST check the isCancelled flag before using the result!
1055
- */
1056
- - (BOOL )_checkConnectionIfNecessary
1057
- {
1058
-
1059
- // If the connection has been dropped in the background, trigger a
1060
- // reconnect and return the success state here
1061
- if (state == SPMySQLConnectionLostInBackground) {
1062
- return [self _reconnectAllowingRetries: YES ];
1063
- }
1064
-
1065
- // If the connection was recently used, return success
1066
- if (_elapsedSecondsSinceAbsoluteTime (lastConnectionUsedTime) < 30 ) {
1067
- return YES ;
1068
- }
1069
-
1070
- // Otherwise check the connection
1071
- return [self checkConnection ];
1072
- }
1073
-
1074
1076
/* *
1075
1077
* Ensure that the thread this method is called on has been registered for
1076
1078
* use with MySQL. MySQL requires thread-specific variables for safe
0 commit comments