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
curlx/timediff.c \
curlx/timeval.c \
curlx/version_win32.c \
+ curlx/wait.c \
curlx/warnless.c \
curlx/winapi.c
curlx/timediff.h \
curlx/timeval.h \
curlx/version_win32.h \
+ curlx/wait.h \
curlx/warnless.h \
curlx/winapi.h
#include "timeval.h"
#include "timediff.h"
+#include "wait.h"
+/* for curlx_wait_ms */
+
#include "winapi.h"
/* for curlx_winapi_strerror */
--- /dev/null
+/***************************************************************************
+ * _ _ ____ _
+ * 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;
+}
-#ifndef HEADER_CURL_TOOL_SLEEP_H
-#define HEADER_CURL_TOOL_SLEEP_H
+#ifndef HEADER_CURL_WAIT_H
+#define HEADER_CURL_WAIT_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* 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 */
#include "amigaos.h"
#include "macos.h"
#include "curlx/warnless.h"
+#include "curlx/wait.h"
#include "sigpipe.h"
#include "vssh/ssh.h"
#include "setopt.h"
#endif
pollrc = 0;
if(ev->ms > 0)
- Curl_wait_ms(ev->ms);
+ curlx_wait_ms(ev->ms);
}
ev->msbump = FALSE; /* reset here */
#include "http.h"
#include "select.h"
#include "curlx/warnless.h"
+#include "curlx/wait.h"
#include "speedcheck.h"
#include "conncache.h"
#include "multihandle.h"
timeout */
else if(sleep_ms < 0)
sleep_ms = timeout_ms;
- Curl_wait_ms(sleep_ms);
+ curlx_wait_ms(sleep_ms);
}
}
#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
(!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
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
}
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
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
#include "../connect.h"
#include "../slist.h"
#include "../select.h"
+#include "../curlx/wait.h"
#include "vtls.h"
#include "vtls_int.h"
#include "vtls_scache.h"
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) *
[.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, -
../lib/curlx/timediff.c \
../lib/curlx/timeval.c \
../lib/curlx/version_win32.c \
+ ../lib/curlx/wait.c \
../lib/curlx/warnless.c
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 = \
tool_parsecfg.c \
tool_progress.c \
tool_setopt.c \
- tool_sleep.c \
tool_ssls.c \
tool_stderr.c \
tool_strdup.c \
tool_sdecls.h \
tool_setopt.h \
tool_setup.h \
- tool_sleep.h \
tool_ssls.h \
tool_stderr.h \
tool_strdup.h \
#include "tool_operate.h"
#include "tool_util.h"
#include "tool_msgs.h"
-#include "tool_sleep.h"
#include <memdebug.h> /* keep this as LAST include */
}
else
/* sleep half a period */
- tool_go_sleep(25);
+ curlx_wait_ms(25);
}
return per->noprogress ? 0 : CURL_PROGRESSFUNC_CONTINUE;
#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"
returncode = post_per_transfer(global, per, result, &retry, &delay_ms);
if(retry) {
- tool_go_sleep(delay_ms);
+ curlx_wait_ms(delay_ms);
continue;
}
"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));
}
}
}
+++ /dev/null
-/***************************************************************************
- * _ _ ____ _
- * 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
-}
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 = \
#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");\
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);
}
}
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);
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 = \
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;
entry_func_t ptr;
};
+#include "curlx.h"
+
#endif /* HEADER_LIBTEST_FIRST_H */
abort_on_test_timeout();
}
- wait_ms(1); /* to ensure different end times */
+ curlx_wait_ms(1); /* to ensure different end times */
}
test_cleanup:
}
if(i < count)
- sleep(DNS_TIMEOUT + 1);
+ curlx_wait_ms((DNS_TIMEOUT + 1) * 1000);
}
test_cleanup:
/* 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;
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().
/* 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)
(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);
return;
if(t2301_recv_pong(curl, "foobar"))
return;
- sleep(2);
+ curlx_wait_ms(2000);
} while(i++ < 10);
t2301_websocket_close(curl);
}
curl_mprintf("Connection closed\n");
return;
}
- sleep(2);
+ curlx_wait_ms(2000);
} while(i++ < 10);
t2304_websocket_close(curl);
}
abort_on_test_timeout();
}
- wait_ms(1); /* to ensure different end times */
+ curlx_wait_ms(1); /* to ensure different end times */
}
test_cleanup:
abort_on_test_timeout();
}
- wait_ms(1); /* to ensure different end times */
+ curlx_wait_ms(1); /* to ensure different end times */
}
test_cleanup:
abort_on_test_timeout();
}
- wait_ms(1); /* to ensure different end times */
+ curlx_wait_ms(1); /* to ensure different end times */
}
test_cleanup:
break;
#ifdef _WIN32
if(maxfd == -1)
- Sleep(100);
+ curlx_wait_ms(100);
else
#endif
rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcept, &timeout);
#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
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;
../../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
#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>
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;
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;
}
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;
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;
written = swrite(sock, buffer, num);
if(written < 0) {
if((SOCKEWOULDBLOCK == SOCKERRNO) || (EAGAIN == SOCKERRNO)) {
- wait_ms(10);
+ curlx_wait_ms(10);
goto retry;
}
sendfailure = TRUE;
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;
}
}
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;
}
'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;
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);
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++) {
if(CURL_SOCKET_BAD == msgsock)
goto sws_cleanup;
if(req->delay)
- wait_ms(req->delay);
+ curlx_wait_ms(req->delay);
} while(msgsock > 0);
active--;
}
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]);
#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>
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:
#include <netdb.h>
#endif
-#ifdef MSDOS
-#include <dos.h> /* delay() */
-#endif
-
#include <curlx.h> /* from the private lib dir */
/* adjust for old MSVC */
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
***************************************************************************/
#include "curlcheck.h"
+#include <curlx.h>
+
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
}
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;
$(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 \
$(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