gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] 02/02: test_timeout: avoid busy-waiting


From: gnunet
Subject: [libmicrohttpd] 02/02: test_timeout: avoid busy-waiting
Date: Sun, 12 Dec 2021 18:06:36 +0100

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit b468b54f7cbe7bcc9354a9ce4cca644cd79e94ce
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Sun Dec 12 19:12:25 2021 +0300

    test_timeout: avoid busy-waiting
---
 src/testcurl/test_timeout.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/src/testcurl/test_timeout.c b/src/testcurl/test_timeout.c
index 8742b9ff..bcc1ad91 100644
--- a/src/testcurl/test_timeout.c
+++ b/src/testcurl/test_timeout.c
@@ -39,6 +39,47 @@
 #include <unistd.h>
 #endif
 
+
+/**
+ * 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 (EINTR != errno)
+      externalErrorExit ();
+    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
+  fprintf (stderr, "No sleep function available on this system.\n");
+#endif
+}
+
+
 static int oneone;
 
 static int withTimeout = 0;
@@ -125,6 +166,7 @@ static size_t
 putBuffer_fail (void *stream, size_t size, size_t nmemb, void *ptr)
 {
   (void) stream; (void) size; (void) nmemb; (void) ptr;        /* Unused. 
Silent compiler warning. */
+  _MHD_sleep (100); /* Avoid busy-waiting */
   return 0;
 }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]