enet_iosFixes.h 770 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef ENET_IOSFIXES_H
  2. #define ENET_IOSFIXES_H
  3. // Standard things.
  4. #include <stdlib.h>
  5. #include <stdbool.h>
  6. #include <stdint.h>
  7. #include <time.h>
  8. // Apple-related things.
  9. #include <mach/clock.h>
  10. #include <mach/mach.h>
  11. #include <Availability.h>
  12. // Fix for a pre iOS 10 bug where clock_get_time is a stub.
  13. // iOS 9.3.x is known to be affected on iPad Gen 2, iPhone 4S, etc.
  14. // clock_get_time became present post iOS 10.
  15. int preiOS10_clock_get_time(int X, struct timespec* ts) {
  16. clock_serv_t cclock;
  17. mach_timespec_t mts;
  18. host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
  19. clock_get_time(cclock, &mts);
  20. mach_port_deallocate(mach_task_self(), cclock);
  21. ts->tv_sec = mts.tv_sec;
  22. ts->tv_nsec = mts.tv_nsec;
  23. return 0;
  24. }
  25. #endif