aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks')
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.h2
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m34
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h2
3 files changed, 21 insertions, 17 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.h
index cff8d43b..ae3c8156 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.h
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.h
@@ -51,6 +51,6 @@ void _forceThreadExit(int signalNumber);
void _pingThreadCleanup(void *pingDetails);
// Cancellation
-- (void)_cancelKeepAlives;
+- (BOOL)_cancelKeepAlives;
@end
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m
index e43b4a2f..0c455242 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m
@@ -102,8 +102,7 @@
}
// Return as no further ping action required this cycle.
- keepAliveThread = nil;
- return;
+ goto end;
}
// Otherwise, perform a background ping.
@@ -113,6 +112,7 @@
} else {
keepAlivePingFailures++;
}
+end:
keepAliveThread = nil;
}
@@ -170,7 +170,7 @@
// If the ping timeout has been exceeded, or the ping thread has been
// cancelled, force a timeout; double-check that the thread is still active.
- if (([keepAliveThread isCancelled] || pingElapsedTime > pingTimeout)
+ if (([[NSThread currentThread] isCancelled] || pingElapsedTime > pingTimeout)
&& keepAlivePingThreadActive
&& !threadCancelled)
{
@@ -254,24 +254,28 @@ void _pingThreadCleanup(void *pingDetails)
/**
* If a keepalive thread is active, cancel it, and wait a short time for it
* to exit.
+ *
+ * @return YES, if the thread exited within 10 seconds after canceling it
*/
-- (void)_cancelKeepAlives
+- (BOOL)_cancelKeepAlives
{
// If no keepalive thread is active, return
- if (!keepAliveThread) {
- return;
- }
+ if (keepAliveThread) {
- // Mark the thread as cancelled
- [keepAliveThread cancel];
+ // Mark the thread as cancelled
+ [keepAliveThread cancel];
- // Wait inside a time limit of ten seconds for it to exit
- uint64_t threadCancelStartTime_t = mach_absolute_time();
- do {
- usleep(100000);
- if (_elapsedSecondsSinceAbsoluteTime(threadCancelStartTime_t) > 10) break;
- } while (keepAliveThread);
+ // Wait inside a time limit of ten seconds for it to exit
+ uint64_t threadCancelStartTime_t = mach_absolute_time();
+ do {
+ usleep(100000);
+ if (_elapsedSecondsSinceAbsoluteTime(threadCancelStartTime_t) > 10) return NO;
+ } while (keepAliveThread);
+
+ }
+
+ return YES;
}
@end
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h
index c65ec2fb..9fae3f98 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h
@@ -85,7 +85,7 @@
CGFloat keepAliveInterval;
uint64_t lastKeepAliveTime;
NSUInteger keepAlivePingFailures;
- NSThread *keepAliveThread;
+ volatile NSThread *keepAliveThread;
pthread_t keepAlivePingThread_t;
BOOL keepAlivePingThreadActive;
BOOL keepAliveLastPingSuccess;