]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: make `curlx_wait_ms()` and use it
authorViktor Szakats <commit@vsz.me>
Mon, 16 Jun 2025 13:20:17 +0000 (15:20 +0200)
committerViktor Szakats <commit@vsz.me>
Thu, 19 Jun 2025 13:57:37 +0000 (15:57 +0200)
Move function to curlx/, change all callers.

Also:
- src: replace local implementation.
- tests/client: replace local ad-hoc sleep code.
- tests/libtest: replace local `wait_ms()` implementation.
- lib1531: replace local ad-hoc sleep code.
- tests/server: replace local, simplified copy.
- tests/server: formatting, drop some unused headers.

Closes #17641

45 files changed:
lib/Makefile.inc
lib/curlx/curlx.h
lib/curlx/wait.c [new file with mode: 0644]
lib/curlx/wait.h [moved from src/tool_sleep.h with 86% similarity]
lib/easy.c
lib/multi.c
lib/select.c
lib/select.h
lib/vtls/openssl.c
packages/vms/gnv_link_curl.com
src/Makefile.inc
src/tool_cb_rea.c
src/tool_operate.c
src/tool_sleep.c [deleted file]
tests/client/Makefile.inc
tests/client/first.h
tests/client/ws_data.c
tests/client/ws_pingpong.c
tests/libtest/Makefile.inc
tests/libtest/first.c
tests/libtest/first.h
tests/libtest/lib1506.c
tests/libtest/lib1515.c
tests/libtest/lib1517.c
tests/libtest/lib1531.c
tests/libtest/lib1542.c
tests/libtest/lib1565.c
tests/libtest/lib2301.c
tests/libtest/lib2304.c
tests/libtest/lib2402.c
tests/libtest/lib2404.c
tests/libtest/lib2502.c
tests/libtest/lib670.c
tests/libtest/test.h
tests/server/Makefile.inc
tests/server/dnsd.c
tests/server/mqttd.c
tests/server/rtspd.c
tests/server/sockfilt.c
tests/server/socksd.c
tests/server/sws.c
tests/server/tftpd.c
tests/server/util.c
tests/unit/unit2600.c
winbuild/MakefileBuild.vc

index fd2546b1d70f0e335413a32d4ca10167afd371a9..8e33a23f6cc0b87b4bc7d03c4646d6636d2ea1df 100644 (file)
@@ -34,6 +34,7 @@ LIB_CURLX_CFILES = \
   curlx/timediff.c \
   curlx/timeval.c  \
   curlx/version_win32.c \
+  curlx/wait.c     \
   curlx/warnless.c \
   curlx/winapi.c
 
@@ -49,6 +50,7 @@ LIB_CURLX_HFILES = \
   curlx/timediff.h \
   curlx/timeval.h  \
   curlx/version_win32.h \
+  curlx/wait.h     \
   curlx/warnless.h \
   curlx/winapi.h
 
index e3598c23a02fd977e5af98f8b76c8d9731699041..5b97ec5b83da137cb6678f0dee30f22b36c6353e 100644 (file)
@@ -65,6 +65,9 @@
 #include "timeval.h"
 #include "timediff.h"
 
+#include "wait.h"
+/* for curlx_wait_ms */
+
 #include "winapi.h"
 /* for curlx_winapi_strerror */
 
diff --git a/lib/curlx/wait.c b/lib/curlx/wait.c
new file mode 100644 (file)
index 0000000..f568fb6
--- /dev/null
@@ -0,0 +1,97 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * SPDX-License-Identifier: curl
+ *
+ ***************************************************************************/
+
+#include "../curl_setup.h"
+
+#ifndef HAVE_SELECT
+#error "We cannot compile without select() support."
+#endif
+
+#include <limits.h>
+
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#elif defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+
+#ifdef MSDOS
+#include <dos.h>  /* delay() */
+#endif
+
+#include "timediff.h"
+#include "wait.h"
+
+/*
+ * Internal function used for waiting a specific amount of ms in
+ * Curl_socket_check() and Curl_poll() when no file descriptor is provided to
+ * wait on, just being used to delay execution. Winsock select() and poll()
+ * timeout mechanisms need a valid socket descriptor in a not null file
+ * descriptor set to work. Waiting indefinitely with this function is not
+ * allowed, a zero or negative timeout value will return immediately. Timeout
+ * resolution, accuracy, as well as maximum supported value is system
+ * dependent, neither factor is a critical issue for the intended use of this
+ * function in the library.
+ *
+ * Return values:
+ *   -1 = system call error, or invalid timeout value
+ *    0 = specified timeout has elapsed, or interrupted
+ */
+int curlx_wait_ms(timediff_t timeout_ms)
+{
+  int r = 0;
+
+  if(!timeout_ms)
+    return 0;
+  if(timeout_ms < 0) {
+    SET_SOCKERRNO(SOCKEINVAL);
+    return -1;
+  }
+#if defined(MSDOS)
+  delay((unsigned int)timeout_ms);
+#elif defined(_WIN32)
+  /* prevent overflow, timeout_ms is typecast to ULONG/DWORD. */
+#if TIMEDIFF_T_MAX >= ULONG_MAX
+  if(timeout_ms >= ULONG_MAX)
+    timeout_ms = ULONG_MAX-1;
+    /* do not use ULONG_MAX, because that is equal to INFINITE */
+#endif
+  Sleep((DWORD)timeout_ms);
+#else
+  /* avoid using poll() for this since it behaves incorrectly with no sockets
+     on Apple operating systems */
+  {
+    struct timeval pending_tv;
+    r = select(0, NULL, NULL, NULL, curlx_mstotv(&pending_tv, timeout_ms));
+  }
+#endif /* _WIN32 */
+  if(r) {
+    if((r == -1) && (SOCKERRNO == SOCKEINTR))
+      /* make EINTR from select or poll not a "lethal" error */
+      r = 0;
+    else
+      r = -1;
+  }
+  return r;
+}
similarity index 86%
rename from src/tool_sleep.h
rename to lib/curlx/wait.h
index de1d7e256b9f8c8ec121d2f3315985e8ea40d2fd..208bc20accb18d6698a1bf305a3c5f6d28d57012 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef HEADER_CURL_TOOL_SLEEP_H
-#define HEADER_CURL_TOOL_SLEEP_H
+#ifndef HEADER_CURL_WAIT_H
+#define HEADER_CURL_WAIT_H
 /***************************************************************************
  *                                  _   _ ____  _
  *  Project                     ___| | | |  _ \| |
@@ -23,8 +23,9 @@
  * SPDX-License-Identifier: curl
  *
  ***************************************************************************/
-#include "tool_setup.h"
 
-void tool_go_sleep(long ms);
+#include "../curl_setup.h"
 
-#endif /* HEADER_CURL_TOOL_SLEEP_H */
+int curlx_wait_ms(timediff_t timeout_ms);
+
+#endif /* HEADER_CURL_WAIT_H */
index 73b60f7f675f3cd6c3d8e209403369f0de0c637b..b9e3fa31e2b0010f09cd3a8826290be1c43b7ca1 100644 (file)
@@ -67,6 +67,7 @@
 #include "amigaos.h"
 #include "macos.h"
 #include "curlx/warnless.h"
+#include "curlx/wait.h"
 #include "sigpipe.h"
 #include "vssh/ssh.h"
 #include "setopt.h"
@@ -611,7 +612,7 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
 #endif
       pollrc = 0;
       if(ev->ms > 0)
-        Curl_wait_ms(ev->ms);
+        curlx_wait_ms(ev->ms);
     }
 
     ev->msbump = FALSE; /* reset here */
index 79a0935c1060802958d85d629e46dcf7d786e81a..3114e6aecb9334682eef99b3e083c89a1f84953c 100644 (file)
@@ -42,6 +42,7 @@
 #include "http.h"
 #include "select.h"
 #include "curlx/warnless.h"
+#include "curlx/wait.h"
 #include "speedcheck.h"
 #include "conncache.h"
 #include "multihandle.h"
@@ -1458,7 +1459,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi,
          timeout */
       else if(sleep_ms < 0)
         sleep_ms = timeout_ms;
-      Curl_wait_ms(sleep_ms);
+      curlx_wait_ms(sleep_ms);
     }
   }
 
index ee239b7321761d1fb985fae838eaa9fa3d6c4009..2353c474df3ae147ce0de39213665fb9a026f22c 100644 (file)
 #include <unistd.h>
 #endif
 
-#ifdef MSDOS
-#include <dos.h>  /* delay() */
-#endif
-
 #include <curl/curl.h>
 
 #include "urldata.h"
 #include "connect.h"
 #include "select.h"
 #include "curlx/timediff.h"
+#include "curlx/wait.h"
 #include "curlx/warnless.h"
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
 #include "curl_memory.h"
 #include "memdebug.h"
 
-/*
- * Internal function used for waiting a specific amount of ms in
- * Curl_socket_check() and Curl_poll() when no file descriptor is provided to
- * wait on, just being used to delay execution. Winsock select() and poll()
- * timeout mechanisms need a valid socket descriptor in a not null file
- * descriptor set to work. Waiting indefinitely with this function is not
- * allowed, a zero or negative timeout value will return immediately. Timeout
- * resolution, accuracy, as well as maximum supported value is system
- * dependent, neither factor is a critical issue for the intended use of this
- * function in the library.
- *
- * Return values:
- *   -1 = system call error, or invalid timeout value
- *    0 = specified timeout has elapsed, or interrupted
- */
-int Curl_wait_ms(timediff_t timeout_ms)
-{
-  int r = 0;
-
-  if(!timeout_ms)
-    return 0;
-  if(timeout_ms < 0) {
-    SET_SOCKERRNO(SOCKEINVAL);
-    return -1;
-  }
-#if defined(MSDOS)
-  delay((unsigned int)timeout_ms);
-#elif defined(_WIN32)
-  /* prevent overflow, timeout_ms is typecast to ULONG/DWORD. */
-#if TIMEDIFF_T_MAX >= ULONG_MAX
-  if(timeout_ms >= ULONG_MAX)
-    timeout_ms = ULONG_MAX-1;
-    /* do not use ULONG_MAX, because that is equal to INFINITE */
-#endif
-  Sleep((DWORD)timeout_ms);
-#else
-  /* avoid using poll() for this since it behaves incorrectly with no sockets
-     on Apple operating systems */
-  {
-    struct timeval pending_tv;
-    r = select(0, NULL, NULL, NULL, curlx_mstotv(&pending_tv, timeout_ms));
-  }
-#endif /* _WIN32 */
-  if(r) {
-    if((r == -1) && (SOCKERRNO == SOCKEINTR))
-      /* make EINTR from select or poll not a "lethal" error */
-      r = 0;
-    else
-      r = -1;
-  }
-  return r;
-}
-
 #ifndef HAVE_POLL
 /*
  * This is a wrapper around select() to aid in Windows compatibility. A
@@ -132,7 +76,7 @@ static int our_select(curl_socket_t maxfd,   /* highest socket number */
      (!fds_write || fds_write->fd_count == 0) &&
      (!fds_err || fds_err->fd_count == 0)) {
     /* no sockets, just wait */
-    return Curl_wait_ms(timeout_ms);
+    return curlx_wait_ms(timeout_ms);
   }
 #endif
 
@@ -194,7 +138,7 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
   if((readfd0 == CURL_SOCKET_BAD) && (readfd1 == CURL_SOCKET_BAD) &&
      (writefd == CURL_SOCKET_BAD)) {
     /* no sockets, just wait */
-    return Curl_wait_ms(timeout_ms);
+    return curlx_wait_ms(timeout_ms);
   }
 
   /* Avoid initial timestamp, avoid curlx_now() call, when elapsed
@@ -289,7 +233,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms)
   }
   if(fds_none) {
     /* no sockets, just wait */
-    return Curl_wait_ms(timeout_ms);
+    return curlx_wait_ms(timeout_ms);
   }
 
   /* Avoid initial timestamp, avoid curlx_now() call, when elapsed
index 10968fab7f898eb19ef58b4602befaac6dc953fb..e9cec600f3b7eea9927896faad1ca0bf184ab2a1 100644 (file)
@@ -82,7 +82,6 @@ int Curl_socket_check(curl_socket_t readfd, curl_socket_t readfd2,
   Curl_socket_check(CURL_SOCKET_BAD, CURL_SOCKET_BAD, x, z)
 
 int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms);
-int Curl_wait_ms(timediff_t timeout_ms);
 
 /*
    With Winsock the valid range is [0..INVALID_SOCKET-1] according to
index a32307c05bdfce26182df13d52245f1a94f3f62d..e7a82fffd58b9362dc96e8e7281165a9378ef97b 100644 (file)
@@ -54,6 +54,7 @@
 #include "../connect.h"
 #include "../slist.h"
 #include "../select.h"
+#include "../curlx/wait.h"
 #include "vtls.h"
 #include "vtls_int.h"
 #include "vtls_scache.h"
@@ -1004,7 +1005,7 @@ static CURLcode ossl_seed(struct Curl_easy *data)
     size_t i, i_max;
     for(i = 0, i_max = len / sizeof(struct curltime); i < i_max; ++i) {
       struct curltime tv = curlx_now();
-      Curl_wait_ms(1);
+      curlx_wait_ms(1);
       tv.tv_sec *= (time_t)i + 1;
       tv.tv_usec *= (int)i + 2;
       tv.tv_sec ^= ((curlx_now().tv_sec + (time_t)curlx_now().tv_usec) *
index d7b29f5283147bd06b54a83fe7a435993f16e524..83a8e021e823cdbca179dda923238085bddf6057 100644 (file)
@@ -412,7 +412,7 @@ $       link'ldebug'/exe=[.src]curl.exe/dsf=[.src]curl.dsf -
            [.src]curl-tool_msgs.o, [.src]curl-tool_operate.o, -
            [.src]curl-tool_operhlp.o, -
            [.src]curl-tool_paramhlp.o, [.src]curl-tool_parsecfg.o, -
-           [.src]curl-tool_setopt.o, [.src]curl-tool_sleep.o, -
+           [.src]curl-tool_setopt.o, -
            [.src]curl-tool_urlglob.o, [.src]curl-tool_util.o, -
            [.src]curl-tool_vms.o, [.src]curl-tool_writeenv.o, -
            [.src]curl-tool_writeout.o, [.src]curl-tool_xattr.o, -
index c83154474ac2d3db020840657bfe474c436eb7a4..a4c3ca453a2ebfc28f9e1fc7e423a48c4e052499 100644 (file)
@@ -41,6 +41,7 @@ CURLX_CFILES = \
   ../lib/curlx/timediff.c \
   ../lib/curlx/timeval.c \
   ../lib/curlx/version_win32.c \
+  ../lib/curlx/wait.c \
   ../lib/curlx/warnless.c
 
 CURLX_HFILES = \
@@ -52,6 +53,7 @@ CURLX_HFILES = \
   ../lib/curlx/timediff.h \
   ../lib/curlx/timeval.h \
   ../lib/curlx/version_win32.h \
+  ../lib/curlx/wait.h \
   ../lib/curlx/warnless.h
 
 CURL_CFILES = \
@@ -88,7 +90,6 @@ CURL_CFILES = \
   tool_parsecfg.c \
   tool_progress.c \
   tool_setopt.c \
-  tool_sleep.c \
   tool_ssls.c \
   tool_stderr.c \
   tool_strdup.c \
@@ -136,7 +137,6 @@ CURL_HFILES = \
   tool_sdecls.h \
   tool_setopt.h \
   tool_setup.h \
-  tool_sleep.h \
   tool_ssls.h \
   tool_stderr.h \
   tool_strdup.h \
index 86ae476a225d4ecfa72e4959a752ddc4420089c0..da93a9d3d021a9c09f45f47f54ac4f54e947426d 100644 (file)
@@ -34,7 +34,6 @@
 #include "tool_operate.h"
 #include "tool_util.h"
 #include "tool_msgs.h"
-#include "tool_sleep.h"
 
 #include <memdebug.h> /* keep this as LAST include */
 
@@ -155,7 +154,7 @@ int tool_readbusy_cb(void *clientp,
     }
     else
       /* sleep half a period */
-      tool_go_sleep(25);
+      curlx_wait_ms(25);
   }
 
   return per->noprogress ? 0 : CURL_PROGRESSFUNC_CONTINUE;
index 2397de1686d9d57e5bb295cba42247093a4ab2b8..a52439caf811ee57d4369f2fe44b8a5e2e5a90dd 100644 (file)
@@ -80,7 +80,6 @@
 #include "tool_paramhlp.h"
 #include "tool_parsecfg.h"
 #include "tool_setopt.h"
-#include "tool_sleep.h"
 #include "tool_ssls.h"
 #include "tool_urlglob.h"
 #include "tool_util.h"
@@ -1965,7 +1964,7 @@ static CURLcode serial_transfers(struct GlobalConfig *global,
 
     returncode = post_per_transfer(global, per, result, &retry, &delay_ms);
     if(retry) {
-      tool_go_sleep(delay_ms);
+      curlx_wait_ms(delay_ms);
       continue;
     }
 
@@ -1998,7 +1997,7 @@ static CURLcode serial_transfers(struct GlobalConfig *global,
                       "waits %ldms as set by --rate",
               milli, (long)(global->ms_per_transfer - milli));
         /* The transfer took less time than wanted. Wait a little. */
-        tool_go_sleep((long)(global->ms_per_transfer - milli));
+        curlx_wait_ms((long)(global->ms_per_transfer - milli));
       }
     }
   }
diff --git a/src/tool_sleep.c b/src/tool_sleep.c
deleted file mode 100644 (file)
index e10584a..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/***************************************************************************
- *                                  _   _ ____  _
- *  Project                     ___| | | |  _ \| |
- *                             / __| | | | |_) | |
- *                            | (__| |_| |  _ <| |___
- *                             \___|\___/|_| \_\_____|
- *
- * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-#include "tool_setup.h"
-
-#ifdef HAVE_SYS_SELECT_H
-#  include <sys/select.h>
-#elif defined(HAVE_UNISTD_H)
-#  include <unistd.h>
-#endif
-
-#ifdef HAVE_POLL_H
-#  include <poll.h>
-#elif defined(HAVE_SYS_POLL_H)
-#  include <sys/poll.h>
-#endif
-
-#ifdef MSDOS
-#  include <dos.h>
-#endif
-
-#include "tool_sleep.h"
-
-#include <memdebug.h> /* keep this as LAST include */
-
-void tool_go_sleep(long ms)
-{
-#if defined(MSDOS)
-  delay(ms);
-#elif defined(_WIN32)
-  Sleep((DWORD)ms);
-#else
-  struct timeval timeout;
-  timeout.tv_sec = ms / 1000L;
-  ms = ms % 1000L;
-  timeout.tv_usec = (int)ms * 1000;
-  select(0, NULL,  NULL, NULL, &timeout);
-#endif
-}
index 604ff515c935f4d8c5699466111e95584b494b3c..5f44f12d0566df4820ec2651d27b8472d500b7f7 100644 (file)
@@ -30,7 +30,9 @@ BUNDLE_SRC = clients.c
 FIRSTFILES = first.c first.h
 
 CURLX_SRCS = \
-  ../../lib/curlx/multibyte.c
+  ../../lib/curlx/multibyte.c \
+  ../../lib/curlx/timediff.c \
+  ../../lib/curlx/wait.c
 
 # All test clients
 TESTFILES = \
index a3e77ee5f367f0a1e7970ca33dd42533a1a438dd..9aabc538e36c94e84607a260bde3e60acdcc4fb4 100644 (file)
@@ -34,18 +34,11 @@ struct entry_s {
 
 #include <curl/curl.h>
 
+#include "curlx.h"
+
 #include <stdlib.h>  /* for calloc(), free(), strtol() */
 #include <string.h>  /* for strchr(), strcmp() */
 
-#ifndef _WIN32
-#include <sys/time.h>  /* for usleep() */
-#include <unistd.h>  /* for usleep() */
-#endif
-
-#ifdef __TANDEM
-#include <cextdecs.h(PROCESS_DELAY_)>  /* for usleep() logic */
-#endif
-
 #define ERR()                                                                 \
   do {                                                                        \
     curl_mfprintf(stderr, "something unexpected went wrong - bailing out!\n");\
index a5677a83f2c76982236d3eb371f93acee2989715..493809f8072b6fa4125cbf4acba73e33e7c8712b 100644 (file)
@@ -136,18 +136,7 @@ static CURLcode data_echo(CURL *curl, size_t count,
 
       if(rblock && sblock) {
         curl_mfprintf(stderr, "EAGAIN, sleep, try again\n");
-#ifdef _WIN32
-        Sleep(100);
-#elif defined(__TANDEM)
-        /* NonStop only defines usleep when building for a threading model */
-# if defined(_PUT_MODEL_) || defined(_KLT_MODEL_)
-        usleep(100*1000);
-# else
-        PROCESS_DELAY_(100*1000);
-# endif
-#else
-        usleep(100*1000);
-#endif
+        curlx_wait_ms(100);
       }
     }
 
index 6af8a9cd22425f80c0da3d59d3fea45976405b94..0059d315e480c2bb94137200dcc5c07e803c23ac 100644 (file)
@@ -75,18 +75,7 @@ static CURLcode pingpong(CURL *curl, const char *payload)
     curl_mfprintf(stderr, "Receive pong\n");
     res = recv_pong(curl, payload);
     if(res == CURLE_AGAIN) {
-#ifdef _WIN32
-      Sleep(100);
-#elif defined(__TANDEM)
-      /* NonStop only defines usleep when building for a threading model */
-# if defined(_PUT_MODEL_) || defined(_KLT_MODEL_)
-      usleep(100*1000);
-# else
-      PROCESS_DELAY_(100*1000);
-# endif
-#else
-      usleep(100*1000);
-#endif
+      curlx_wait_ms(100);
       continue;
     }
     websocket_close(curl);
index ecacd61d575efa5305470727162e4c2abb31e196..db91fe7c2d8876bbaa922bb585dfff62389c5aae 100644 (file)
@@ -34,13 +34,10 @@ UTILS = memptr.c testutil.c testutil.h testtrace.c testtrace.h test.h ../unit/cu
 
 CURLX_SRCS = \
   ../../lib/curlx/warnless.c \
-  ../../lib/curlx/warnless.h \
   ../../lib/curlx/multibyte.c \
-  ../../lib/curlx/multibyte.h \
   ../../lib/curlx/timediff.c \
-  ../../lib/curlx/timediff.h \
   ../../lib/curl_threads.c \
-  ../../lib/curl_threads.h
+  ../../lib/curlx/wait.c
 
 # All libtest programs
 TESTFILES = \
index 3a201fb6dea7dd12f4b8013f5866e669e89a300b..2a828a1b3fcd0fa702a8cb8bc035d82f5932ff01 100644 (file)
@@ -50,21 +50,6 @@ int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
   return select(nfds, rd, wr, exc, tv);
 }
 
-void wait_ms(int ms)
-{
-  if(ms < 0)
-    return;
-#ifdef USE_WINSOCK
-  Sleep((DWORD)ms);
-#else
-  {
-    struct timeval t;
-    curlx_mstotv(&t, ms);
-    select_wrapper(0, NULL, NULL, NULL, &t);
-  }
-#endif
-}
-
 char *libtest_arg2 = NULL;
 char *libtest_arg3 = NULL;
 char *libtest_arg4 = NULL;
index 514861671690c930ecd685ec19ccb4b06c44de93..ad56056dae3a83db432aa6ccec3cc90fafcb7229 100644 (file)
@@ -32,4 +32,6 @@ struct entry_s {
   entry_func_t ptr;
 };
 
+#include "curlx.h"
+
 #endif /* HEADER_LIBTEST_FIRST_H */
index f63156dc9a2c6a1c08135e46feb89997e7c5371a..b47eb4af0633f8472814be79d7279fcc24730ffd 100644 (file)
@@ -114,7 +114,7 @@ static CURLcode test_lib1506(char *URL)
 
       abort_on_test_timeout();
     }
-    wait_ms(1); /* to ensure different end times */
+    curlx_wait_ms(1); /* to ensure different end times */
   }
 
 test_cleanup:
index 7d98cfe61c7ca0010a8bda62309c6dc97e46374f..11cdef6677879f7ad82ad802b98b6ffdc2193229 100644 (file)
@@ -134,7 +134,7 @@ static CURLcode test_lib1515(char *URL)
     }
 
     if(i < count)
-      sleep(DNS_TIMEOUT + 1);
+      curlx_wait_ms((DNS_TIMEOUT + 1) * 1000);
   }
 
 test_cleanup:
index 214a76928b03a8a6d649f109fd22e4a0d6f57136..c997b335816ae994e877e05a08933f8dfb1009d9 100644 (file)
@@ -37,7 +37,7 @@ static size_t t1517_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
 
   /* Wait one second before return POST data          *
    * so libcurl will wait before sending request body */
-  wait_ms(1000);
+  curlx_wait_ms(1000);
 
   if(tocopy < 1 || !pooh->sizeleft)
     return 0;
index e3096d1504b16d5249e149c49e5459529d2dbe06..50698d0b4c1f892e1a00a7e1b8491b5b8aa2aa40 100644 (file)
@@ -107,15 +107,7 @@ static CURLcode test_lib1531(char *URL)
        curl_multi_fdset() doc. */
 
     if(maxfd == -1) {
-#ifdef _WIN32
-      Sleep(100);
-      rc = 0;
-#else
-      /* Portable sleep for platforms other than Windows. */
-      struct timeval wait = {0};
-      wait.tv_usec = 100 * 1000; /* 100ms */
-      rc = select(0, NULL, NULL, NULL, &wait);
-#endif
+      rc = curlx_wait_ms(100);
     }
     else {
       /* Note that on some platforms 'timeout' may be modified by select().
index 32ee236d95cf21182dc00ed632b3b2e8d6a66c9c..95ffbf1d77ebea65c8091ea46433464fd5458e5e 100644 (file)
@@ -63,7 +63,7 @@ static CURLcode test_lib1542(char *URL)
 
   /* CURLOPT_MAXLIFETIME_CONN is inclusive - the connection needs to be 2
    * seconds old */
-  sleep(2);
+  curlx_wait_ms(2000);
 
   res = curl_easy_perform(easy);
   if(res)
index b03b17dec05d96d2e41066d78eee16c1eb2ba27a..455a3026e4be0017a2665a2306204492381cdb09 100644 (file)
@@ -51,7 +51,7 @@ static void *t1565_run_thread(void *ptr)
   (void)ptr;
 
   for(i = 0; i < CONN_NUM; i++) {
-    wait_ms(TIME_BETWEEN_START_SECS * 1000);
+    curlx_wait_ms(TIME_BETWEEN_START_SECS * 1000);
 
     easy_init(easy);
 
index da3f0e53317c02c6d1e34d04c6c229a1b13a7e37..6562a50541d86a39409246342007401684ebea1a 100644 (file)
@@ -84,7 +84,7 @@ static void t2301_websocket(CURL *curl)
       return;
     if(t2301_recv_pong(curl, "foobar"))
       return;
-    sleep(2);
+    curlx_wait_ms(2000);
   } while(i++ < 10);
   t2301_websocket_close(curl);
 }
index f3091ee1a3be0188f8b7961e163329946de8e5ff..d4d583ff5ca86a8ffeb9865d775fa2f8533ccdd2 100644 (file)
@@ -104,7 +104,7 @@ static void t2304_websocket(CURL *curl)
       curl_mprintf("Connection closed\n");
       return;
     }
-    sleep(2);
+    curlx_wait_ms(2000);
   } while(i++ < 10);
   t2304_websocket_close(curl);
 }
index be761793b82a5f784b702eb6995a7575c346df29..c7b52027c06eb18552225526904a3efe62270517 100644 (file)
@@ -117,7 +117,7 @@ static CURLcode test_lib2402(char *URL)
 
       abort_on_test_timeout();
     }
-    wait_ms(1); /* to ensure different end times */
+    curlx_wait_ms(1); /* to ensure different end times */
   }
 
 test_cleanup:
index 2737a267ba7ecbd637b94577eee4312b294b10e1..a8c9ed18270923f3025ebe2e005e5b49c2c10236 100644 (file)
@@ -119,7 +119,7 @@ static CURLcode test_lib2404(char *URL)
 
       abort_on_test_timeout();
     }
-    wait_ms(1); /* to ensure different end times */
+    curlx_wait_ms(1); /* to ensure different end times */
   }
 
 test_cleanup:
index 2047e4753f6ebc46f9f7fb9207f0160b76111b75..9b1f8ab73409f0b844673c529fc7c716ec67c3ba 100644 (file)
@@ -121,7 +121,7 @@ static CURLcode test_lib2502(char *URL)
 
       abort_on_test_timeout();
     }
-    wait_ms(1); /* to ensure different end times */
+    curlx_wait_ms(1); /* to ensure different end times */
   }
 
 test_cleanup:
index 981a4e92f9e6997c5b2a106c2145fca28850c322..b26605e3f53b04692893cde3542c2badb0cebfe7 100644 (file)
@@ -202,7 +202,7 @@ static CURLcode test_lib670(char *URL)
         break;
 #ifdef _WIN32
       if(maxfd == -1)
-        Sleep(100);
+        curlx_wait_ms(100);
       else
 #endif
       rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcept, &timeout);
index 369e9c6f045b099a6308610971aa874ce8aee742..92aebff82adc55aadaca9b756d2399acfb3ca127 100644 (file)
 #define CURL_GNUC_DIAG
 #endif
 
-#ifdef _WIN32
-#define sleep(sec) Sleep((sec)*1000)
-#endif
-
 #define test_setopt(A,B,C)                                      \
   if((res = curl_easy_setopt((A), (B), (C))) != CURLE_OK)       \
     goto test_cleanup
@@ -74,8 +70,6 @@ extern struct timeval tv_test_start; /* for test timing */
 extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
                           struct timeval *tv);
 
-extern void wait_ms(int ms); /* wait this many milliseconds */
-
 extern char *hexdump(const unsigned char *buffer, size_t len);
 
 extern int unitfail;
index 378106435230454938117ecddad4ef1ac3b5e93f..062a50300064ce69c1c721b0d27feef6680ee71e 100644 (file)
@@ -41,6 +41,7 @@ CURLX_SRCS = \
   ../../lib/curlx/timediff.c \
   ../../lib/curlx/timeval.c \
   ../../lib/curlx/version_win32.c \
+  ../../lib/curlx/wait.c \
   ../../lib/curlx/warnless.c \
   ../../lib/curlx/winapi.c
 
index 52e2951c0c3209573f6ac2e291b60f3438ff3769..6bb04e0c576b2177fc8a534f9305e289f9e9a7e8 100644 (file)
 #ifdef HAVE_NETDB_H
 #include <netdb.h>
 #endif
-#ifdef HAVE_SYS_FILIO_H
-/* FIONREAD on Solaris 7 */
-#include <sys/filio.h>
-#endif
-
-#include <setjmp.h>
 
 #include <ctype.h>
 
index 4ece4ff8c9e9172dd02f49c3d341aed54d3f711e..db5007f109c06007a6fcc306f4c0ac7158585747 100644 (file)
@@ -761,11 +761,11 @@ static curl_socket_t mqttd_sockdaemon(curl_socket_t sock,
       logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s",
              error, sstrerror(error));
       if(maxretr) {
-        rc = wait_ms(delay);
+        rc = curlx_wait_ms(delay);
         if(rc) {
           /* should not happen */
           error = SOCKERRNO;
-          logmsg("wait_ms() failed with error (%d) %s",
+          logmsg("curlx_wait_ms() failed with error (%d) %s",
                  error, sstrerror(error));
           sclose(sock);
           return CURL_SOCKET_BAD;
index 0e99365393f6856a0c2f22fca24a2c81fb32ed2e..211759e4fb44e535f5c55a585907188c27047e21 100644 (file)
@@ -964,13 +964,13 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req)
           quarters = num * 4;
           while(quarters > 0) {
             quarters--;
-            res = wait_ms(250);
+            res = curlx_wait_ms(250);
             if(got_exit_signal)
               break;
             if(res) {
               /* should not happen */
               error = SOCKERRNO;
-              logmsg("wait_ms() failed with error (%d) %s",
+              logmsg("curlx_wait_ms() failed with error (%d) %s",
                      error, sstrerror(error));
               break;
             }
index 85314a6288eb8e713f50565b678cb1b4c7d08565..b4e62a50bb4a7bf84d7ad5394b752e05a18a5976 100644 (file)
@@ -1253,11 +1253,11 @@ static curl_socket_t sockfilt_sockdaemon(curl_socket_t sock,
       logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s",
              error, sstrerror(error));
       if(maxretr) {
-        rc = wait_ms(delay);
+        rc = curlx_wait_ms(delay);
         if(rc) {
           /* should not happen */
           error = SOCKERRNO;
-          logmsg("wait_ms() failed with error (%d) %s",
+          logmsg("curlx_wait_ms() failed with error (%d) %s",
                  error, sstrerror(error));
           sclose(sock);
           return CURL_SOCKET_BAD;
index 9739f532e336bed12c2c254d6bb31a6466abbb04..af8083bbdb931d3c382f0e8877b99f6c7c15252a 100644 (file)
@@ -781,11 +781,11 @@ static curl_socket_t socksd_sockdaemon(curl_socket_t sock,
       logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s",
              error, sstrerror(error));
       if(maxretr) {
-        rc = wait_ms(delay);
+        rc = curlx_wait_ms(delay);
         if(rc) {
           /* should not happen */
           error = SOCKERRNO;
-          logmsg("wait_ms() failed with error (%d) %s",
+          logmsg("curlx_wait_ms() failed with error (%d) %s",
                  error, sstrerror(error));
           sclose(sock);
           return CURL_SOCKET_BAD;
index b8f12bedc46094b3fb9916d0ce577e2b3b5b190d..553030e61d0ffa1f1d69d817302f04ca6464ea72 100644 (file)
@@ -1133,7 +1133,7 @@ retry:
     written = swrite(sock, buffer, num);
     if(written < 0) {
       if((SOCKEWOULDBLOCK == SOCKERRNO) || (EAGAIN == SOCKERRNO)) {
-        wait_ms(10);
+        curlx_wait_ms(10);
         goto retry;
       }
       sendfailure = TRUE;
@@ -1157,7 +1157,7 @@ retry:
         int sleep_time = msecs_left > MAX_SLEEP_TIME_MS ?
           MAX_SLEEP_TIME_MS : msecs_left;
         intervals--;
-        wait_ms(sleep_time);
+        curlx_wait_ms(sleep_time);
         msecs_left -= sleep_time;
       }
     }
@@ -1201,11 +1201,11 @@ retry:
           quarters = num * 4;
           while((quarters > 0) && !got_exit_signal) {
             quarters--;
-            res = wait_ms(250);
+            res = curlx_wait_ms(250);
             if(res) {
               /* should not happen */
               error = SOCKERRNO;
-              logmsg("wait_ms() failed with error (%d) %s",
+              logmsg("curlx_wait_ms() failed with error (%d) %s",
                      error, sstrerror(error));
               break;
             }
@@ -1428,7 +1428,7 @@ static void http_connect(curl_socket_t *infdp,
      'end of headers' separate from the server data that follows.
      This is done to prevent triggering libcurl known bug #39. */
   for(loop = 2; (loop > 0) && !got_exit_signal; loop--)
-    wait_ms(250);
+    curlx_wait_ms(250);
   if(got_exit_signal)
     goto http_connect_cleanup;
 
@@ -1593,7 +1593,7 @@ static void http_connect(curl_socket_t *infdp,
             if(!err && req2->connect_request) {
               /* sleep to prevent triggering libcurl known bug #39. */
               for(loop = 2; (loop > 0) && !got_exit_signal; loop--)
-                wait_ms(250);
+                curlx_wait_ms(250);
               if(!got_exit_signal) {
                 /* connect to the server */
                 serverfd[SWS_DATA] = connect_to(ipaddr, req2->connect_port);
@@ -1747,7 +1747,7 @@ static void http_connect(curl_socket_t *infdp,
 
       if(tcp_fin_wr)
         /* allow kernel to place FIN bit packet on the wire */
-        wait_ms(250);
+        curlx_wait_ms(250);
 
       /* socket clearing */
       for(i = 0; i <= max_tunnel_idx; i++) {
@@ -2391,7 +2391,7 @@ static int test_sws(int argc, char *argv[])
         if(CURL_SOCKET_BAD == msgsock)
           goto sws_cleanup;
         if(req->delay)
-          wait_ms(req->delay);
+          curlx_wait_ms(req->delay);
       } while(msgsock > 0);
       active--;
     }
@@ -2423,7 +2423,7 @@ static int test_sws(int argc, char *argv[])
                  wait a very small amount of time before doing so. If this
                  is not done client might get an ECONNRESET before reading
                  a single byte of server-reply. */
-              wait_ms(50);
+              curlx_wait_ms(50);
 
             if(all_sockets[socket_idx] != CURL_SOCKET_BAD) {
               sclose(all_sockets[socket_idx]);
index 0216b5960c67b94efe8d8ff3e238326e8cc63889..8c3484b38905d02af1bb6135388f1bbc992c71ee 100644 (file)
@@ -71,8 +71,7 @@
 #include <netdb.h>
 #endif
 #ifdef HAVE_SYS_FILIO_H
-/* FIONREAD on Solaris 7 */
-#include <sys/filio.h>
+#include <sys/filio.h>  /* FIONREAD on Solaris 7 */
 #endif
 
 #include <setjmp.h>
@@ -1208,7 +1207,7 @@ static void sendtftp(struct testcase *test, const struct formats *pf)
     if(test->writedelay) {
       logmsg("Pausing %d seconds before %d bytes", test->writedelay,
              size);
-      wait_ms(1000*test->writedelay);
+      curlx_wait_ms(1000*test->writedelay);
     }
 
 send_data:
index 1e0531f51499ee35e548d11a8834b389cbf50ba8..9c8d279cee9a9e2693dbaa8e997133b29a74df53 100644 (file)
 #include <netdb.h>
 #endif
 
-#ifdef MSDOS
-#include <dos.h>  /* delay() */
-#endif
-
 #include <curlx.h> /* from the private lib dir */
 
 /* adjust for old MSVC */
@@ -304,53 +300,6 @@ static FILE *test2fopen(long testno, const char *logdir2)
   return stream;
 }
 
-/*
- * Portable function used for waiting a specific amount of ms.
- * Waiting indefinitely with this function is not allowed, a
- * zero or negative timeout value will return immediately.
- *
- * Return values:
- *   -1 = system call error, or invalid timeout value
- *    0 = specified timeout has elapsed
- */
-static int wait_ms(timediff_t timeout_ms)
-{
-  int r = 0;
-
-  if(!timeout_ms)
-    return 0;
-  if(timeout_ms < 0) {
-    SET_SOCKERRNO(SOCKEINVAL);
-    return -1;
-  }
-#if defined(MSDOS)
-  delay((unsigned int)timeout_ms);
-#elif defined(_WIN32)
-  /* prevent overflow, timeout_ms is typecast to ULONG/DWORD. */
-#if TIMEDIFF_T_MAX >= ULONG_MAX
-  if(timeout_ms >= ULONG_MAX)
-    timeout_ms = ULONG_MAX-1;
-    /* do not use ULONG_MAX, because that is equal to INFINITE */
-#endif
-  Sleep((DWORD)timeout_ms);
-#else
-  /* avoid using poll() for this since it behaves incorrectly with no sockets
-     on Apple operating systems */
-  {
-    struct timeval pending_tv;
-    r = select(0, NULL, NULL, NULL, curlx_mstotv(&pending_tv, timeout_ms));
-  }
-#endif /* _WIN32 */
-  if(r) {
-    if((r == -1) && (SOCKERRNO == SOCKEINTR))
-      /* make EINTR from select or poll not a "lethal" error */
-      r = 0;
-    else
-      r = -1;
-  }
-  return r;
-}
-
 #ifdef _WIN32
 #define t_getpid() GetCurrentProcessId()
 #else
index 09af1690290a2725c5b34f373167ab9f189865ed..90b235aa492f900d6b053dd413791d8a054815c3 100644 (file)
@@ -23,6 +23,8 @@
  ***************************************************************************/
 #include "curlcheck.h"
 
+#include <curlx.h>
+
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
@@ -144,7 +146,7 @@ static CURLcode cf_test_connect(struct Curl_cfilter *cf,
   }
   if(duration_ms) {
     infof(data, "%04dms: cf[%s] continuing", (int)duration_ms, ctx->id);
-    Curl_wait_ms(10);
+    curlx_wait_ms(10);
   }
   Curl_expire(data, ctx->fail_delay_ms - duration_ms, EXPIRE_RUN_NOW);
   return CURLE_OK;
index ff95d58420772bb57f3431a52606c14ea6d23a0d..8bdb22d6c4d89b507bb221ba4d007d61d58c6a95 100644 (file)
@@ -696,6 +696,7 @@ CURL_FROM_LIBCURL=\
  $(CURL_DIROBJ)\strparse.obj \
  $(CURL_DIROBJ)\strcase.obj \
  $(CURL_DIROBJ)\timeval.obj \
+ $(CURL_DIROBJ)\wait.obj \
  $(CURL_DIROBJ)\warnless.obj \
  $(CURL_DIROBJ)\multibyte.obj \
  $(CURL_DIROBJ)\version_win32.obj \
@@ -729,6 +730,8 @@ $(CURL_DIROBJ)\multibyte.obj: ../lib/curlx/multibyte.c
        $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curlx/multibyte.c
 $(CURL_DIROBJ)\version_win32.obj: ../lib/curlx/version_win32.c
        $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curlx/version_win32.c
+$(CURL_DIROBJ)\wait.obj: ../lib/curlx/wait.c
+       $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curlx/wait.c
 $(CURL_DIROBJ)\warnless.obj: ../lib/curlx/warnless.c
        $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curlx/warnless.c
 $(CURL_DIROBJ)\dynbuf.obj: ../lib/curlx/dynbuf.c