[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 03/03: test_https_time_out: use better sleep function
From: |
gnunet |
Subject: |
[libmicrohttpd] 03/03: test_https_time_out: use better sleep function |
Date: |
Sun, 12 Dec 2021 18:52:49 +0100 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit fdf0ea88acd3829766a7aec8ef7418dc535c2850
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Sun Dec 12 20:24:35 2021 +0300
test_https_time_out: use better sleep function
---
src/testcurl/https/test_https_time_out.c | 48 +++++++++++++++++++++++++++++++-
1 file changed, 47 insertions(+), 1 deletion(-)
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 @@
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif /* HAVE_SIGNAL_H */
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif /* HAVE_TIME_H */
+
#include "mhd_sockets.h" /* only macros used */
@@ -54,6 +61,45 @@ static const int TIME_OUT = 2;
static unsigned int num_connects = 0;
static unsigned int num_disconnects = 0;
+
+/**
+ * Pause execution for specified number of milliseconds.
+ * @param ms the number of milliseconds to sleep
+ */
+void
+_MHD_sleep (uint32_t ms)
+{
+#if defined(_WIN32)
+ Sleep (ms);
+#elif defined(HAVE_NANOSLEEP)
+ struct timespec slp = {ms / 1000, (ms % 1000) * 1000000};
+ struct timespec rmn;
+ int num_retries = 0;
+ while (0 != nanosleep (&slp, &rmn))
+ {
+ if (num_retries++ > 8)
+ break;
+ slp = rmn;
+ }
+#elif defined(HAVE_USLEEP)
+ uint64_t us = ms * 1000;
+ do
+ {
+ uint64_t this_sleep;
+ if (999999 < us)
+ this_sleep = 999999;
+ else
+ this_sleep = us;
+ /* Ignore return value as it could be void */
+ usleep (this_sleep);
+ us -= this_sleep;
+ } while (us > 0);
+#else
+ sleep ((ms + 999) / 1000);
+#endif
+}
+
+
void
socket_cb (void *cls,
struct MHD_Connection *c,
@@ -119,7 +165,7 @@ test_tls_session_time_out (gnutls_session_t session, int
port)
return 2;
}
- (void) sleep (TIME_OUT + 2);
+ _MHD_sleep (TIME_OUT * 1000 + 1200);
/* check that server has closed the connection */
if (1 == num_disconnects)
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.