mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
lib: make curlx_wait_ms() and use it
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
This commit is contained in:
parent
9fc05357ef
commit
35d0c047ce
@ -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
|
||||
|
||||
|
||||
@ -65,6 +65,9 @@
|
||||
#include "timeval.h"
|
||||
#include "timediff.h"
|
||||
|
||||
#include "wait.h"
|
||||
/* for curlx_wait_ms */
|
||||
|
||||
#include "winapi.h"
|
||||
/* for curlx_winapi_strerror */
|
||||
|
||||
|
||||
97
lib/curlx/wait.c
Normal file
97
lib/curlx/wait.c
Normal file
@ -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;
|
||||
}
|
||||
@ -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 */
|
||||
@ -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 */
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
64
lib/select.c
64
lib/select.c
@ -36,75 +36,19 @@
|
||||
#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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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) *
|
||||
|
||||
@ -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, -
|
||||
|
||||
@ -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 \
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
@ -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 = \
|
||||
|
||||
@ -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");\
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 = \
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -32,4 +32,6 @@ struct entry_s {
|
||||
entry_func_t ptr;
|
||||
};
|
||||
|
||||
#include "curlx.h"
|
||||
|
||||
#endif /* HEADER_LIBTEST_FIRST_H */
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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().
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -49,10 +49,6 @@
|
||||
#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;
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -42,12 +42,6 @@
|
||||
#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>
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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]);
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -37,10 +37,6 @@
|
||||
#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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user