diff options
author | Yang Tse <yangsita@gmail.com> | 2008-05-09 16:31:51 +0000 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2008-05-09 16:31:51 +0000 |
commit | 19479ea0217c93fd2973168084d1bb724eb8a34f (patch) | |
tree | a8b59cbb90c38f93c414ec5bebee3c60bd5ae887 /src | |
parent | d708ef6731445a84a3d0499a4b13fd09a0dd0520 (diff) |
Internal time differences now use monotonic time source if available.
This also implies the removal of the winmm.lib dependency for WIN32.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.Watcom | 2 | ||||
-rw-r--r-- | src/Makefile.m32 | 2 | ||||
-rw-r--r-- | src/Makefile.vc6 | 6 | ||||
-rw-r--r-- | src/curlutil.c | 103 |
4 files changed, 56 insertions, 57 deletions
diff --git a/src/Makefile.Watcom b/src/Makefile.Watcom index 8f75233a6..942443848 100644 --- a/src/Makefile.Watcom +++ b/src/Makefile.Watcom @@ -7,7 +7,7 @@ CC = wcc386 CFLAGS = -3r -mf -d3 -hc -zff -zgf -zq -zm -s -fr=con -w2 -fpi -oilrtfm & - -bt=nt -d+ -dWIN32 -dHAVE_STRTOLL -dWITHOUT_MM_LIB & + -bt=nt -d+ -dWIN32 -dHAVE_STRTOLL & -dSIZEOF_CURL_OFF_T=8 -dCURLDEBUG -dENABLE_IPV6 -dHAVE_WINSOCK2_H & -I..\include -I..\lib diff --git a/src/Makefile.m32 b/src/Makefile.m32 index 32817e915..3ecd99971 100644 --- a/src/Makefile.m32 +++ b/src/Makefile.m32 @@ -104,7 +104,7 @@ ifndef USE_LDAP_OPENLDAP curl_LDADD += -lwldap32 endif endif -curl_LDADD += -lws2_32 -lwinmm +curl_LDADD += -lws2_32 COMPILE = $(CC) $(INCLUDES) $(CFLAGS) # Makefile.inc provides the CSOURCES and HHEADERS defines diff --git a/src/Makefile.vc6 b/src/Makefile.vc6 index 233242252..49438d1e3 100644 --- a/src/Makefile.vc6 +++ b/src/Makefile.vc6 @@ -10,8 +10,6 @@ ## Comments to: Troy Engel <tengel@sonic.net>
## Updated by: Craig Davison <cd@securityfocus.com>
## release-ssl added by Miklos Nemeth <mnemeth@kfkisystems.com>
-## winmm.lib added by Miklos Nemeth <mnemeth@kfkisystems.com> to
-## support timeGetTime() in curlutil.c
#
#############################################################
@@ -221,8 +219,8 @@ LFLAGS = $(LFLAGS) $(SSL_IMP_LFLAGS) $(ZLIB_LFLAGS) !ENDIF
-LINKLIBS = $(LINKLIBS) wsock32.lib wldap32.lib winmm.lib
-LINKLIBS_DEBUG = $(LINKLIBS_DEBUG) wsock32.lib wldap32.lib winmm.lib
+LINKLIBS = $(LINKLIBS) wsock32.lib wldap32.lib
+LINKLIBS_DEBUG = $(LINKLIBS_DEBUG) wsock32.lib wldap32.lib
all : release
diff --git a/src/curlutil.c b/src/curlutil.c index 0394d80e2..12a7d2e06 100644 --- a/src/curlutil.c +++ b/src/curlutil.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2008, 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 @@ -25,69 +25,70 @@ #include "curlutil.h" -#ifndef HAVE_GETTIMEOFDAY +#if defined(WIN32) && !defined(MSDOS) -#ifdef WIN32 -#include <mmsystem.h> - -static int gettimeofday(struct timeval *tp, void *nothing) +struct timeval cutil_tvnow(void) { -#ifdef WITHOUT_MM_LIB - SYSTEMTIME st; - time_t tt; - struct tm tmtm; - /* mktime converts local to UTC */ - GetLocalTime (&st); - tmtm.tm_sec = st.wSecond; - tmtm.tm_min = st.wMinute; - tmtm.tm_hour = st.wHour; - tmtm.tm_mday = st.wDay; - tmtm.tm_mon = st.wMonth - 1; - tmtm.tm_year = st.wYear - 1900; - tmtm.tm_isdst = -1; - tt = mktime (&tmtm); - tp->tv_sec = tt; - tp->tv_usec = st.wMilliseconds * 1000; -#else - /** - ** The earlier time calculations using GetLocalTime - ** had a time resolution of 10ms.The timeGetTime, part - ** of multimedia apis offer a better time resolution - ** of 1ms.Need to link against winmm.lib for this - **/ - unsigned long Ticks = 0; - unsigned long Sec =0; - unsigned long Usec = 0; - Ticks = timeGetTime(); - - Sec = Ticks/1000; - Usec = (Ticks - (Sec*1000))*1000; - tp->tv_sec = Sec; - tp->tv_usec = Usec; -#endif /* WITHOUT_MM_LIB */ - (void)nothing; - return 0; + /* + ** GetTickCount() is available on _all_ Windows versions from W95 up + ** to nowadays. Returns milliseconds elapsed since last system boot, + ** increases monotonically and wraps once 49.7 days have elapsed. + */ + struct timeval now; + DWORD milliseconds = GetTickCount(); + now.tv_sec = milliseconds / 1000; + now.tv_usec = (milliseconds % 1000) * 1000; + return now; } -#else /* WIN32 */ -/* non-win32 version of Curl_gettimeofday() */ -static int gettimeofday(struct timeval *tp, void *nothing) + +#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) + +struct timeval cutil_tvnow(void) { - (void)nothing; /* we don't support specific time-zones */ - tp->tv_sec = (long)time(NULL); - tp->tv_usec = 0; - return 0; + /* + ** clock_gettime() is granted to be increased monotonically when the + ** monotonic clock is queried. Time starting point is unspecified, it + ** could be the system start-up time, the Epoch, or something else, + ** in any case the time starting point does not change once that the + ** system has started up. + */ + struct timeval now; + struct timespec tsnow; + (void)clock_gettime(CLOCK_MONOTONIC, &tsnow) + now.tv_sec = tsnow.tv_sec; + now.tv_usec = tsnow.tv_nsec / 1000; + return now; } -#endif /* WIN32 */ -#endif /* HAVE_GETTIMEOFDAY */ -/* Return the current time in a timeval struct */ +#elif defined(HAVE_GETTIMEOFDAY) + struct timeval cutil_tvnow(void) { + /* + ** gettimeofday() is not granted to be increased monotonically, due to + ** clock drifting and external source time synchronization it can jump + ** forward or backward in time. + */ struct timeval now; (void)gettimeofday(&now, NULL); return now; } +#else + +struct timeval cutil_tvnow(void) +{ + /* + ** time() returns the value of time in seconds since the Epoch. + */ + struct timeval now; + now.tv_sec = (long)time(NULL); + now.tv_usec = 0; + return now; +} + +#endif + /* * Make sure that the first argument is the more recent time, as otherwise * we'll get a weird negative time-diff back... |