diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-12-12 20:24:35 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-12-12 20:51:29 +0300 |
commit | fdf0ea88acd3829766a7aec8ef7418dc535c2850 (patch) | |
tree | e842a3221bc26fe716ed79009f0d635c0a27c78c | |
parent | 141a8e702c0d145de85abc7fd1f9d11363fa24a7 (diff) | |
download | libmicrohttpd-fdf0ea88acd3829766a7aec8ef7418dc535c2850.tar.gz libmicrohttpd-fdf0ea88acd3829766a7aec8ef7418dc535c2850.zip |
test_https_time_out: use better sleep function
-rw-r--r-- | src/testcurl/https/test_https_time_out.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/testcurl/https/test_https_time_out.c b/src/testcurl/https/test_https_time_out.c index a6d1b3bb..88877b60 100644 --- a/src/testcurl/https/test_https_time_out.c +++ b/src/testcurl/https/test_https_time_out.c | |||
@@ -36,6 +36,13 @@ | |||
36 | #ifdef HAVE_SIGNAL_H | 36 | #ifdef HAVE_SIGNAL_H |
37 | #include <signal.h> | 37 | #include <signal.h> |
38 | #endif /* HAVE_SIGNAL_H */ | 38 | #endif /* HAVE_SIGNAL_H */ |
39 | #ifdef HAVE_UNISTD_H | ||
40 | #include <unistd.h> | ||
41 | #endif /* HAVE_UNISTD_H */ | ||
42 | #ifdef HAVE_TIME_H | ||
43 | #include <time.h> | ||
44 | #endif /* HAVE_TIME_H */ | ||
45 | |||
39 | #include "mhd_sockets.h" /* only macros used */ | 46 | #include "mhd_sockets.h" /* only macros used */ |
40 | 47 | ||
41 | 48 | ||
@@ -54,6 +61,45 @@ static const int TIME_OUT = 2; | |||
54 | static unsigned int num_connects = 0; | 61 | static unsigned int num_connects = 0; |
55 | static unsigned int num_disconnects = 0; | 62 | static unsigned int num_disconnects = 0; |
56 | 63 | ||
64 | |||
65 | /** | ||
66 | * Pause execution for specified number of milliseconds. | ||
67 | * @param ms the number of milliseconds to sleep | ||
68 | */ | ||
69 | void | ||
70 | _MHD_sleep (uint32_t ms) | ||
71 | { | ||
72 | #if defined(_WIN32) | ||
73 | Sleep (ms); | ||
74 | #elif defined(HAVE_NANOSLEEP) | ||
75 | struct timespec slp = {ms / 1000, (ms % 1000) * 1000000}; | ||
76 | struct timespec rmn; | ||
77 | int num_retries = 0; | ||
78 | while (0 != nanosleep (&slp, &rmn)) | ||
79 | { | ||
80 | if (num_retries++ > 8) | ||
81 | break; | ||
82 | slp = rmn; | ||
83 | } | ||
84 | #elif defined(HAVE_USLEEP) | ||
85 | uint64_t us = ms * 1000; | ||
86 | do | ||
87 | { | ||
88 | uint64_t this_sleep; | ||
89 | if (999999 < us) | ||
90 | this_sleep = 999999; | ||
91 | else | ||
92 | this_sleep = us; | ||
93 | /* Ignore return value as it could be void */ | ||
94 | usleep (this_sleep); | ||
95 | us -= this_sleep; | ||
96 | } while (us > 0); | ||
97 | #else | ||
98 | sleep ((ms + 999) / 1000); | ||
99 | #endif | ||
100 | } | ||
101 | |||
102 | |||
57 | void | 103 | void |
58 | socket_cb (void *cls, | 104 | socket_cb (void *cls, |
59 | struct MHD_Connection *c, | 105 | struct MHD_Connection *c, |
@@ -119,7 +165,7 @@ test_tls_session_time_out (gnutls_session_t session, int port) | |||
119 | return 2; | 165 | return 2; |
120 | } | 166 | } |
121 | 167 | ||
122 | (void) sleep (TIME_OUT + 2); | 168 | _MHD_sleep (TIME_OUT * 1000 + 1200); |
123 | 169 | ||
124 | /* check that server has closed the connection */ | 170 | /* check that server has closed the connection */ |
125 | if (1 == num_disconnects) | 171 | if (1 == num_disconnects) |