blob: 42b1b24c34de55287ebf18b770b2f324df93f460 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
Upstream-status: merged with commit ccec6c2f6770484278b25c3335d4bd8882bc4c87
diff --git a/configure.ac b/configure.ac
index b54d5b49..584b0179 100644
--- a/configure.ac
+++ b/configure.ac
@@ -83,6 +83,7 @@ case "${host_os}" in
;;
linux*)
SYS=linux
+ CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200809L"
;;
darwin*)
SYS=darwin
diff --git a/src/compat/msvc/unistd.h b/src/compat/msvc/unistd.h
index d43d4796..abcc1c61 100644
--- a/src/compat/msvc/unistd.h
+++ b/src/compat/msvc/unistd.h
@@ -50,4 +50,6 @@
typedef int mode_t;
#include <BaseTsd.h>
+#define nanosleep(x) Sleep((x) / 1000000)
+
#endif
diff --git a/tools/dhtcnode.c b/tools/dhtcnode.c
index cdb04714..f78a7f7f 100644
--- a/tools/dhtcnode.c
+++ b/tools/dhtcnode.c
@@ -24,12 +24,17 @@
#include <stdlib.h>
#include <stdatomic.h>
#include <inttypes.h>
+#include <time.h>
#include <getopt.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <arpa/inet.h>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
struct op_context {
dht_runner* runner;
atomic_bool stop;
@@ -287,7 +292,12 @@ int main(int argc, char **argv)
// Wait until shutdown callback is called
while (!atomic_load(&ctx.stop)) {
- usleep(10000);
+#ifdef _WIN32
+ Sleep(10); // 10ms
+#else
+ struct timespec ts = {0, 10000000}; // 10ms
+ nanosleep(&ts, NULL);
+#endif
}
dht_runner_delete(runner);
return EXIT_SUCCESS;
|