|
48 | 48 | #endif |
49 | 49 | #endif |
50 | 50 |
|
51 | | -#ifdef __unix__ |
| 51 | +#if defined(__unix__) && !defined(__APPLE__) |
| 52 | +#include <sys/sysinfo.h> |
| 53 | +#endif |
| 54 | + |
| 55 | +#if defined(__unix__) || defined(__APPLE__) |
52 | 56 | #include <arpa/inet.h> |
53 | 57 | #include <netdb.h> |
54 | 58 | #include <netinet/in.h> |
55 | 59 | #include <sys/ioctl.h> |
56 | 60 | #include <sys/socket.h> |
57 | | -#include <sys/sysinfo.h> |
58 | 61 | #include <sys/types.h> |
59 | 62 | #endif |
| 63 | + |
| 64 | +#if defined(__APPLE__) |
| 65 | +#include <mach/mach_time.h> |
| 66 | +#include <netinet/tcp.h> |
| 67 | +#ifndef SOCK_CLOEXEC |
| 68 | +#define SOCK_CLOEXEC 0 |
| 69 | +#endif |
| 70 | +#ifndef SOCK_NONBLOCK |
| 71 | +#include <fcntl.h> |
| 72 | +#define SOCK_NONBLOCK O_NONBLOCK |
| 73 | +#endif |
| 74 | +#ifndef MSG_NOSIGNAL |
| 75 | +#define MSG_NOSIGNAL 0 |
| 76 | +#endif |
| 77 | +uint32_t TickCount() { |
| 78 | + uint64_t mat = mach_absolute_time(); |
| 79 | + uint32_t mul = 0x80d9594e; |
| 80 | + return ((((0xffffffff & mat) * mul) >> 32) + (mat >> 32) * mul) >> 23; |
| 81 | +} |
| 82 | +#endif |
| 83 | + |
60 | 84 | //////////////////////////////////////////////////////////////////////////////// |
61 | 85 | int libsam3a_debug = 0; |
62 | 86 |
|
63 | 87 | #define DEFAULT_TCP_PORT (7656) |
64 | 88 | #define DEFAULT_UDP_PORT (7655) |
65 | 89 |
|
66 | 90 | //////////////////////////////////////////////////////////////////////////////// |
67 | | -uint64_t sam3atimeval2ms(const struct timeval *tv) { |
| 91 | +extern uint64_t sam3atimeval2ms(const struct timeval *tv) { |
68 | 92 | return ((uint64_t)tv->tv_sec) * 1000 + ((uint64_t)tv->tv_usec) / 1000; |
69 | 93 | } |
70 | 94 |
|
71 | | -void sam3ams2timeval(struct timeval *tv, uint64_t ms) { |
| 95 | +extern void sam3ams2timeval(struct timeval *tv, uint64_t ms) { |
72 | 96 | tv->tv_sec = ms / 1000; |
73 | 97 | tv->tv_usec = (ms % 1000) * 1000; |
74 | 98 | } |
@@ -665,13 +689,18 @@ static uint32_t genSeed(void) { |
665 | 689 | volatile uint32_t seed = 1; |
666 | 690 | uint32_t res; |
667 | 691 | #ifndef WIN32 |
668 | | - struct sysinfo sy; |
669 | | - pid_t pid = getpid(); |
670 | | - // |
671 | | - sysinfo(&sy); |
672 | | - res = hashint((uint32_t)pid) ^ hashint((uint32_t)time(NULL)) ^ |
673 | | - hashint((uint32_t)sy.sharedram) ^ hashint((uint32_t)sy.bufferram) ^ |
674 | | - hashint((uint32_t)sy.uptime); |
| 692 | + #ifndef __APPLE__ |
| 693 | + struct sysinfo sy; |
| 694 | + pid_t pid = getpid(); |
| 695 | + // |
| 696 | + sysinfo(&sy); |
| 697 | + res = hashint((uint32_t)pid) ^ hashint((uint32_t)time(NULL)) ^ |
| 698 | + hashint((uint32_t)sy.sharedram) ^ hashint((uint32_t)sy.bufferram) ^ |
| 699 | + hashint((uint32_t)sy.uptime); |
| 700 | + #else |
| 701 | + res = hashint((uint32_t)getpid()) ^ |
| 702 | + hashint((uint32_t)TickCount()); |
| 703 | + #endif |
675 | 704 | #else |
676 | 705 | res = hashint((uint32_t)GetCurrentProcessId()) ^ |
677 | 706 | hashint((uint32_t)GetTickCount()); |
|
0 commit comments