Browse Source

Hopefully this is the last fix needed for pre-iOS 10

Matt Coburn 5 years ago
parent
commit
373ade60e6
1 changed files with 23 additions and 13 deletions
  1. 23 13
      Source/Native/enet.h

+ 23 - 13
Source/Native/enet.h

@@ -1190,20 +1190,25 @@ int clock_gettime(int X, struct timespec* tv) {
 }
 }
 #elif __APPLE__ && (__MAC_OS_X_VERSION_MIN_REQUIRED < 101200 || __IPHONE_OS_VERSION_MIN_REQUIRED < 100000) && !defined(CLOCK_MONOTONIC)
 #elif __APPLE__ && (__MAC_OS_X_VERSION_MIN_REQUIRED < 101200 || __IPHONE_OS_VERSION_MIN_REQUIRED < 100000) && !defined(CLOCK_MONOTONIC)
 #define CLOCK_MONOTONIC 0
 #define CLOCK_MONOTONIC 0
+#endif
 
 
-int clock_gettime(int X, struct timespec* ts) {
-	clock_serv_t cclock;
-	mach_timespec_t mts;
+// Fix for pre-macOS 10.12 or pre-iOS 10.0 devices.
+#if __APPLE__ && (__MAC_OS_X_VERSION_MIN_REQUIRED < 101200 || __IPHONE_OS_VERSION_MIN_REQUIRED < 100000)
 
 
-	host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
-	clock_get_time(cclock, &mts);
-	mach_port_deallocate(mach_task_self(), cclock);
+int preiOS10_clock_get_time(int X, struct timespec* ts) {
+    clock_serv_t cclock;
+    mach_timespec_t mts;
 
 
-	ts->tv_sec = mts.tv_sec;
-	ts->tv_nsec = mts.tv_nsec;
+    host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
+    clock_get_time(cclock, &mts);
+    mach_port_deallocate(mach_task_self(), cclock);
 
 
-	return 0;
+    ts->tv_sec = mts.tv_sec;
+    ts->tv_nsec = mts.tv_nsec;
+
+    return 0;
 }
 }
+
 #endif
 #endif
 
 
 uint32_t enet_time_get(void) {
 uint32_t enet_time_get(void) {
@@ -1212,11 +1217,16 @@ uint32_t enet_time_get(void) {
 	struct timespec ts;
 	struct timespec ts;
 
 
 	// [Replay from a past commit... >>]
 	// [Replay from a past commit... >>]
-	// c6: what the [redacted] fuck is clock_monotonic_raw??????
-	// c6: just use clock monotonic
-	// Coburn: sir yes sir	
+	// c6: what the [redacted] fuck is clock_monotonic_raw?????? just use clock monotonic
+	// Coburn: sir yes sir
+    // [End replay]
+    // attempt 2 at fixing a pre-iOS 10 bug (ugh!)
+#if __APPLE__ && (__MAC_OS_X_VERSION_MIN_REQUIRED < 101200 || __IPHONE_OS_VERSION_MIN_REQUIRED < 100000)
+    preiOS10_clock_get_time(CLOCK_MONOTONIC, &ts);
+#else
 	clock_gettime(CLOCK_MONOTONIC, &ts);
 	clock_gettime(CLOCK_MONOTONIC, &ts);
-	// [End replay]
+#endif
+
 	
 	
 	static const uint64_t ns_in_s = 1000 * 1000 * 1000;
 	static const uint64_t ns_in_s = 1000 * 1000 * 1000;
 	static const uint64_t ns_in_ms = 1000 * 1000;
 	static const uint64_t ns_in_ms = 1000 * 1000;