mirror of
https://github.com/curl/curl.git
synced 2026-07-27 09:47:16 +03:00
curltime: use libcurl time functions in src and tests/server
The curl tool and tests/server used 2 parallel implementations of libcurl's `Curl_now()` and `Curl_timediff()` functions. Make them use the libcurl one. Closes #16653
This commit is contained in:
parent
b1faac8039
commit
436d4a360a
20 changed files with 129 additions and 292 deletions
|
|
@ -27,18 +27,50 @@
|
|||
#ifdef _WIN32
|
||||
|
||||
#include <curl/curl.h>
|
||||
#ifdef BUILDING_LIBCURL
|
||||
#include "system_win32.h"
|
||||
#else
|
||||
#include "version_win32.h"
|
||||
|
||||
static LARGE_INTEGER s_freq;
|
||||
static bool s_isVistaOrGreater;
|
||||
|
||||
/* For tool or tests, we must initialize before calling Curl_now() */
|
||||
void curlx_now_init(void)
|
||||
{
|
||||
if(curlx_verify_windows_version(6, 0, 0, PLATFORM_WINNT,
|
||||
VERSION_GREATER_THAN_EQUAL))
|
||||
s_isVistaOrGreater = true;
|
||||
else
|
||||
s_isVistaOrGreater = false;
|
||||
|
||||
QueryPerformanceFrequency(&s_freq);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* In case of bug fix this function has a counterpart in tool_util.c */
|
||||
struct curltime Curl_now(void)
|
||||
{
|
||||
struct curltime now;
|
||||
if(Curl_isVistaOrGreater) { /* QPC timer might have issues pre-Vista */
|
||||
bool isVistaOrGreater;
|
||||
#ifdef BUILDING_LIBCURL
|
||||
isVistaOrGreater = Curl_isVistaOrGreater;
|
||||
#else
|
||||
isVistaOrGreater = s_isVistaOrGreater;
|
||||
#endif
|
||||
if(isVistaOrGreater) { /* QPC timer might have issues pre-Vista */
|
||||
LARGE_INTEGER count;
|
||||
LARGE_INTEGER freq;
|
||||
#ifdef BUILDING_LIBCURL
|
||||
freq = Curl_freq;
|
||||
#else
|
||||
freq = s_freq;
|
||||
#endif
|
||||
DEBUGASSERT(freq.QuadPart);
|
||||
QueryPerformanceCounter(&count);
|
||||
now.tv_sec = (time_t)(count.QuadPart / Curl_freq.QuadPart);
|
||||
now.tv_usec = (int)((count.QuadPart % Curl_freq.QuadPart) * 1000000 /
|
||||
Curl_freq.QuadPart);
|
||||
now.tv_sec = (time_t)(count.QuadPart / freq.QuadPart);
|
||||
now.tv_usec = (int)((count.QuadPart % freq.QuadPart) * 1000000 /
|
||||
freq.QuadPart);
|
||||
}
|
||||
else {
|
||||
/* Disable /analyze warning that GetTickCount64 is preferred */
|
||||
|
|
|
|||
|
|
@ -28,6 +28,18 @@
|
|||
|
||||
#include "timediff.h"
|
||||
|
||||
#ifndef BUILDING_LIBCURL
|
||||
/* this renames the functions so that the tool code can use the same code
|
||||
without getting symbol collisions */
|
||||
#define Curl_now curlx_now
|
||||
#define Curl_timediff(a,b) curlx_timediff(a,b)
|
||||
#define Curl_timediff_ceil(a,b) curlx_timediff_ceil(a,b)
|
||||
#define Curl_timediff_us(a,b) curlx_timediff_us(a,b)
|
||||
|
||||
/* For tool or tests, we must initialize before calling Curl_now() */
|
||||
void curlx_now_init(void);
|
||||
#endif
|
||||
|
||||
struct curltime {
|
||||
time_t tv_sec; /* seconds */
|
||||
int tv_usec; /* microseconds */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue