From ae1912cb0d494b48d514d937826c9fe83ec96c4d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Dec 1999 14:20:26 +0000 Subject: Initial revision --- lib/timeval.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 lib/timeval.c (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c new file mode 100644 index 000000000..8ad25325f --- /dev/null +++ b/lib/timeval.c @@ -0,0 +1,93 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Curl. + * + * The Initial Developer of the Original Code is Daniel Stenberg. + * + * Portions created by the Initial Developer are Copyright (C) 1998. + * All Rights Reserved. + * + * ------------------------------------------------------------ + * Main author: + * - Daniel Stenberg + * + * http://curl.haxx.nu + * + * $Source$ + * $Revision$ + * $Date$ + * $Author$ + * $State$ + * $Locker$ + * + * ------------------------------------------------------------ + ****************************************************************************/ + +#ifdef WIN32 +#include +#endif +#include "timeval.h" + +#ifndef HAVE_GETTIMEOFDAY + +#ifdef WIN32 +int +gettimeofday (struct timeval *tp, void *nothing) +{ + 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; + return 1; +} +#define HAVE_GETTIMEOFDAY +#endif +#endif + +struct timeval tvnow () +{ + struct timeval now; +#ifdef HAVE_GETTIMEOFDAY + gettimeofday (&now, NULL); +#else + now.tv_sec = (long) time(NULL); + now.tv_usec = 0; +#endif + return now; +} + +double tvdiff (struct timeval t1, struct timeval t2) +{ + return (double)(t1.tv_sec - t2.tv_sec) + ((t1.tv_usec-t2.tv_usec)/1000000.0); +} + +long tvlong (struct timeval t1) +{ + return t1.tv_sec; +} -- cgit v1.2.1 From 1ef3600a0731fef8f59563a1e49981f1b64b9746 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 20 Jun 2000 15:31:26 +0000 Subject: haxx.nu => haxx.se --- lib/timeval.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 8ad25325f..155aa79cb 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -24,9 +24,9 @@ * * ------------------------------------------------------------ * Main author: - * - Daniel Stenberg + * - Daniel Stenberg * - * http://curl.haxx.nu + * http://curl.haxx.se * * $Source$ * $Revision$ -- cgit v1.2.1 From 24dee483e9e925c2ab79dd582f70c9a55ab9ba4d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 3 Jan 2001 09:29:33 +0000 Subject: dual-license fix --- lib/timeval.c | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 155aa79cb..9e5182883 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -5,38 +5,21 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ + * Copyright (C) 2000, Daniel Stenberg, , et al. * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. + * In order to be useful for every potential user, curl and libcurl are + * dual-licensed under the MPL and the MIT/X-derivate licenses. * - * The Original Code is Curl. + * 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 MPL or the MIT/X-derivate + * licenses. You may pick one of these licenses. * - * The Initial Developer of the Original Code is Daniel Stenberg. + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. * - * Portions created by the Initial Developer are Copyright (C) 1998. - * All Rights Reserved. - * - * ------------------------------------------------------------ - * Main author: - * - Daniel Stenberg - * - * http://curl.haxx.se - * - * $Source$ - * $Revision$ - * $Date$ - * $Author$ - * $State$ - * $Locker$ - * - * ------------------------------------------------------------ - ****************************************************************************/ + * $Id$ + *****************************************************************************/ #ifdef WIN32 #include -- cgit v1.2.1 From 4031104404c6ceed5e57134125dcdb6cac51c564 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 5 Jan 2001 10:11:41 +0000 Subject: Internal symbols that aren't static are now prefixed with 'Curl_' --- lib/timeval.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 9e5182883..74bf10695 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -53,7 +53,7 @@ gettimeofday (struct timeval *tp, void *nothing) #endif #endif -struct timeval tvnow () +struct timeval Curl_tvnow () { struct timeval now; #ifdef HAVE_GETTIMEOFDAY @@ -65,12 +65,12 @@ struct timeval tvnow () return now; } -double tvdiff (struct timeval t1, struct timeval t2) +double Curl_tvdiff (struct timeval t1, struct timeval t2) { return (double)(t1.tv_sec - t2.tv_sec) + ((t1.tv_usec-t2.tv_usec)/1000000.0); } -long tvlong (struct timeval t1) +long Curl_tvlong (struct timeval t1) { return t1.tv_sec; } -- cgit v1.2.1 From 4ae3bd71ea5b29f60cfe7835c171661b5066081a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 13 Mar 2001 07:53:06 +0000 Subject: Curl_tvnow is now properly declared with (void) --- lib/timeval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 74bf10695..dfae21a30 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -53,7 +53,7 @@ gettimeofday (struct timeval *tp, void *nothing) #endif #endif -struct timeval Curl_tvnow () +struct timeval Curl_tvnow (void) { struct timeval now; #ifdef HAVE_GETTIMEOFDAY -- cgit v1.2.1 From 6147879837a53d22c9be04e7a4fc315a297ba2b3 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Fri, 7 Sep 2001 04:01:32 +0000 Subject: Added formatting sections for emacs and vim --- lib/timeval.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index dfae21a30..0535c1511 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -74,3 +74,11 @@ long Curl_tvlong (struct timeval t1) { return t1.tv_sec; } + +/* + * local variables: + * eval: (load-file "../curl-mode.el") + * end: + * vim600: et sw=2 ts=2 sts=2 tw=78 fdm=marker + * vim<600: et sw=2 ts=2 sts=2 tw=78 + */ -- cgit v1.2.1 From f0fa858885a490c4184f82e7273656be83a5c586 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 1 Oct 2001 22:50:20 +0000 Subject: added comment to the tvdiff --- lib/timeval.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 0535c1511..4099ede99 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -65,6 +65,10 @@ struct timeval Curl_tvnow (void) return now; } +/* + * Make sure that the first argument is the more recent time, as otherwise + * we'll get a weird negative time-diff back... + */ double Curl_tvdiff (struct timeval t1, struct timeval t2) { return (double)(t1.tv_sec - t2.tv_sec) + ((t1.tv_usec-t2.tv_usec)/1000000.0); -- cgit v1.2.1 From 8e91d5de8e4e17ce3d4936cc91171d09726e7bb3 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Thu, 11 Oct 2001 09:32:19 +0000 Subject: looks nicer and is better compatible with older vim versions --- lib/timeval.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 4099ede99..d30ff74b2 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -83,6 +83,6 @@ long Curl_tvlong (struct timeval t1) * local variables: * eval: (load-file "../curl-mode.el") * end: - * vim600: et sw=2 ts=2 sts=2 tw=78 fdm=marker - * vim<600: et sw=2 ts=2 sts=2 tw=78 + * vim600: fdm=marker + * vim: et sw=2 ts=2 sts=2 tw=78 */ -- cgit v1.2.1 From 532bca41e59e10a86c356058831cf046a3ba78c9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 12 Oct 2001 12:32:20 +0000 Subject: Curl_tvdiff() now returns a millisecond diff, no double like before --- lib/timeval.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index d30ff74b2..f9284349d 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -69,9 +69,10 @@ struct timeval Curl_tvnow (void) * Make sure that the first argument is the more recent time, as otherwise * we'll get a weird negative time-diff back... */ -double Curl_tvdiff (struct timeval t1, struct timeval t2) +long Curl_tvdiff (struct timeval t1, struct timeval t2) { - return (double)(t1.tv_sec - t2.tv_sec) + ((t1.tv_usec-t2.tv_usec)/1000000.0); + return (t1.tv_sec*1000 + t1.tv_usec/1000)- + (t2.tv_sec*1000 + t2.tv_usec/1000); } long Curl_tvlong (struct timeval t1) -- cgit v1.2.1 From 92aedf850e2e81fd0e1e319c6432a07168c0c4b7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 12 Nov 2001 22:10:09 +0000 Subject: made Curl_tvdiff round the diff better and make the subtraction before the multiply to not wrap-around --- lib/timeval.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index f9284349d..cd4461376 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -69,10 +69,10 @@ struct timeval Curl_tvnow (void) * Make sure that the first argument is the more recent time, as otherwise * we'll get a weird negative time-diff back... */ -long Curl_tvdiff (struct timeval t1, struct timeval t2) +long Curl_tvdiff (struct timeval newer, struct timeval older) { - return (t1.tv_sec*1000 + t1.tv_usec/1000)- - (t2.tv_sec*1000 + t2.tv_usec/1000); + return (newer.tv_sec-older.tv_sec)*1000+ + (499+newer.tv_usec-older.tv_usec)/1000; } long Curl_tvlong (struct timeval t1) -- cgit v1.2.1 From 974f314f5785156af6983675aeb28313cc8ba2ea Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 19 Mar 2002 07:54:55 +0000 Subject: copyright string (year) update --- lib/timeval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index cd4461376..d076eccdf 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2000, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. -- cgit v1.2.1 From 9aec0fc7deaeb3c80ac61d6aeaf2dcc1d8e1e266 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 3 Jun 2002 12:46:32 +0000 Subject: T. Bharath fixed higher resolution time for windows builds --- lib/timeval.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index d076eccdf..140bc5506 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -32,22 +32,36 @@ int gettimeofday (struct timeval *tp, void *nothing) { - 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; - return 1; +#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; + Ticks = timeGetTime(); + tp->tv_sec = Ticks%1000; + tp->tv_usec = (Ticks - (tp->tv_sec*1000))*1000; + +#endif + return 1; } #define HAVE_GETTIMEOFDAY #endif -- cgit v1.2.1 From 2443e1f38c38c4fe2611e330990dfe6296da19aa Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 26 Jun 2002 06:47:18 +0000 Subject: T. Bharath fixed his mm lib timer resolution fix --- lib/timeval.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 140bc5506..664f6a96d 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -56,10 +56,14 @@ gettimeofday (struct timeval *tp, void *nothing) ** of 1ms.Need to link against winmm.lib for this **/ unsigned long Ticks = 0; + unsigned long Sec =0; + unsigned long Usec = 0; Ticks = timeGetTime(); - tp->tv_sec = Ticks%1000; - tp->tv_usec = (Ticks - (tp->tv_sec*1000))*1000; - + + Sec = Ticks/1000; + Usec = (Ticks - (Sec*1000))*1000; + tp->tv_sec = Sec; + tp->tv_usec = Usec; #endif return 1; } -- cgit v1.2.1 From ba4e69bebc8f7f32f3bc7faa1e13e7580754075b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 3 Sep 2002 11:52:59 +0000 Subject: updated source code boilerplate/header --- lib/timeval.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 664f6a96d..7ed605160 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | @@ -7,19 +7,19 @@ * * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * - * In order to be useful for every potential user, curl and libcurl are - * dual-licensed under the MPL and the MIT/X-derivate licenses. - * + * 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 http://curl.haxx.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 MPL or the MIT/X-derivate - * licenses. You may pick one of these licenses. + * 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. * * $Id$ - *****************************************************************************/ + ***************************************************************************/ #ifdef WIN32 #include -- cgit v1.2.1 From f26a338a54e04d0a6907f5d2479d8b0fa9daf297 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Jan 2003 21:08:12 +0000 Subject: copyright year update in the source header --- lib/timeval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 7ed605160..78c7f4449 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From a7c72b7abf1213c471f3fd11e6b8e3a37d526f60 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Jan 2003 10:14:20 +0000 Subject: removed the local variables for emacs and vim, use the new sample.emacs way for emacs, and vim users should provide a similar non-polluting style --- lib/timeval.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 78c7f4449..7ab711631 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -97,11 +97,3 @@ long Curl_tvlong (struct timeval t1) { return t1.tv_sec; } - -/* - * local variables: - * eval: (load-file "../curl-mode.el") - * end: - * vim600: fdm=marker - * vim: et sw=2 ts=2 sts=2 tw=78 - */ -- cgit v1.2.1 From 749f5387c19449209615b282ac738032f2a890e7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 14 Oct 2003 12:00:45 +0000 Subject: Gisle Vanem's IPv6-on-Windows patch applied! --- lib/timeval.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 7ab711631..cb0ae1249 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -21,14 +21,13 @@ * $Id$ ***************************************************************************/ -#ifdef WIN32 -#include -#endif #include "timeval.h" #ifndef HAVE_GETTIMEOFDAY #ifdef WIN32 +#include + int gettimeofday (struct timeval *tp, void *nothing) { -- cgit v1.2.1 From a0edfb90c22a25b2198fd1d67b5678d28090ee1f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 4 Jan 2004 12:10:14 +0000 Subject: make our private version of gettimeofday() static --- lib/timeval.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index cb0ae1249..736d5631d 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -1,16 +1,16 @@ /*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2004, Daniel Stenberg, , 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 http://curl.haxx.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. @@ -28,8 +28,7 @@ #ifdef WIN32 #include -int -gettimeofday (struct timeval *tp, void *nothing) +static int gettimeofday(struct timeval *tp, void *nothing) { #ifdef WITHOUT_MM_LIB SYSTEMTIME st; @@ -63,23 +62,26 @@ gettimeofday (struct timeval *tp, void *nothing) Usec = (Ticks - (Sec*1000))*1000; tp->tv_sec = Sec; tp->tv_usec = Usec; -#endif - return 1; +#endif /* WITHOUT_MM_LIB */ + return 0; +} +#else /* WIN32 */ +/* non-win32 version of Curl_gettimeofday() */ +static int gettimeofday(struct timeval *tp, void *nothing) +{ + (void)nothing; /* we don't support specific time-zones */ + tp->tv_sec = (long)time(NULL); + tp->tv_usec = 0; + return 0; } -#define HAVE_GETTIMEOFDAY -#endif -#endif +#endif /* WIN32 */ +#endif /* HAVE_GETTIMEOFDAY */ struct timeval Curl_tvnow (void) { - struct timeval now; -#ifdef HAVE_GETTIMEOFDAY - gettimeofday (&now, NULL); -#else - now.tv_sec = (long) time(NULL); - now.tv_usec = 0; -#endif - return now; + struct timeval now; + (void)gettimeofday(&now, NULL); + return now; } /* @@ -94,5 +96,5 @@ long Curl_tvdiff (struct timeval newer, struct timeval older) long Curl_tvlong (struct timeval t1) { - return t1.tv_sec; + return t1.tv_sec; } -- cgit v1.2.1 From e545e33d5fd4f021220f09cf8fb05c66db2a4bf4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 11 Mar 2004 13:13:35 +0000 Subject: Gisle Vanem's fixes to use CURL_SOCKET_BAD more instead of -1 for sockets. --- lib/timeval.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 736d5631d..dff9aa841 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -63,6 +63,7 @@ static int gettimeofday(struct timeval *tp, void *nothing) tp->tv_sec = Sec; tp->tv_usec = Usec; #endif /* WITHOUT_MM_LIB */ + (void)nothing; return 0; } #else /* WIN32 */ -- cgit v1.2.1 From cd160a66c96f769e821d22bb7d4f2b36dd6f4be2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 30 Mar 2004 08:11:54 +0000 Subject: added more comments for what the functions return --- lib/timeval.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index dff9aa841..b9bd1f994 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -78,7 +78,8 @@ static int gettimeofday(struct timeval *tp, void *nothing) #endif /* WIN32 */ #endif /* HAVE_GETTIMEOFDAY */ -struct timeval Curl_tvnow (void) +/* Return the current time in a timeval struct */ +struct timeval Curl_tvnow(void) { struct timeval now; (void)gettimeofday(&now, NULL); @@ -88,14 +89,17 @@ struct timeval Curl_tvnow (void) /* * Make sure that the first argument is the more recent time, as otherwise * we'll get a weird negative time-diff back... + * + * Returns: the time difference in number of milliseconds. */ -long Curl_tvdiff (struct timeval newer, struct timeval older) +long Curl_tvdiff(struct timeval newer, struct timeval older) { return (newer.tv_sec-older.tv_sec)*1000+ (499+newer.tv_usec-older.tv_usec)/1000; } -long Curl_tvlong (struct timeval t1) +/* return the number of seconds in the given input timeval struct */ +long Curl_tvlong(struct timeval t1) { return t1.tv_sec; } -- cgit v1.2.1 From 780b962336cfe614406b0e56fde3f0a130693d6c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 6 Apr 2004 10:15:10 +0000 Subject: provide these functions as curlx_* ones as this enables the curl app to re-use these sources and functions for subsecond resolution timing --- lib/timeval.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index b9bd1f994..20ac6ea96 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -79,7 +79,7 @@ static int gettimeofday(struct timeval *tp, void *nothing) #endif /* HAVE_GETTIMEOFDAY */ /* Return the current time in a timeval struct */ -struct timeval Curl_tvnow(void) +struct timeval curlx_tvnow(void) { struct timeval now; (void)gettimeofday(&now, NULL); @@ -92,10 +92,10 @@ struct timeval Curl_tvnow(void) * * Returns: the time difference in number of milliseconds. */ -long Curl_tvdiff(struct timeval newer, struct timeval older) +long curlx_tvdiff(struct timeval newer, struct timeval older) { return (newer.tv_sec-older.tv_sec)*1000+ - (499+newer.tv_usec-older.tv_usec)/1000; + (newer.tv_usec-older.tv_usec)/1000; } /* return the number of seconds in the given input timeval struct */ -- cgit v1.2.1 From 2fd463e979ca57c07be4c54e945c33de8651c17c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 9 Apr 2004 09:36:31 +0000 Subject: Dirk Manske increased the resolution for what the CURLINFO_*_TIME return. --- lib/timeval.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 20ac6ea96..11f3d7a06 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -98,6 +98,17 @@ long curlx_tvdiff(struct timeval newer, struct timeval older) (newer.tv_usec-older.tv_usec)/1000; } +/* + * Same as curlx_tvdiff but with full usec resolution. + * + * Returns: the time difference in seconds with subsecond resolution. + */ +double curlx_tvdiff_secs(struct timeval newer, struct timeval older) +{ + return (double)(newer.tv_sec-older.tv_sec)+ + (double)(newer.tv_usec-older.tv_usec)/1000000.0; +} + /* return the number of seconds in the given input timeval struct */ long Curl_tvlong(struct timeval t1) { -- cgit v1.2.1 From 7e00076586d7c93e1bf6ea25182b7aa70d9ffc90 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Fri, 17 Dec 2004 18:32:41 +0000 Subject: required for Watcom. --- lib/timeval.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 11f3d7a06..ce866ca82 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -26,6 +26,7 @@ #ifndef HAVE_GETTIMEOFDAY #ifdef WIN32 +#include #include static int gettimeofday(struct timeval *tp, void *nothing) -- cgit v1.2.1 From d6c5d24af3627ec12721e7d286d426ed12901b55 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sun, 18 Dec 2005 15:36:14 +0000 Subject: Cleanup windows header includes. Where aplicable, inclusion of windows.h winsock.h winsock2.h ws2tcpip.h is done in setup.h --- lib/timeval.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index ce866ca82..11f3d7a06 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -26,7 +26,6 @@ #ifndef HAVE_GETTIMEOFDAY #ifdef WIN32 -#include #include static int gettimeofday(struct timeval *tp, void *nothing) -- cgit v1.2.1 From bda1e9aeab019d003036a3ec24193605bc191b3a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 9 Jan 2006 13:17:14 +0000 Subject: Made the copyright year match the latest modification's year. --- lib/timeval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 11f3d7a06..bb9c0a174 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From afdfa4bed24c9f937bc49807c6d547ac3a158525 Mon Sep 17 00:00:00 2001 From: Gunter Knauf Date: Sat, 30 Jun 2007 20:08:13 +0000 Subject: minor patches to enable building for NetWare CLIB. sent by Dmitry Mityugov. --- lib/timeval.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index bb9c0a174..a2e9665bb 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -68,6 +68,9 @@ static int gettimeofday(struct timeval *tp, void *nothing) } #else /* WIN32 */ /* non-win32 version of Curl_gettimeofday() */ +#if (defined(NETWARE) && !defined(__NOVELL_LIBC__)) +#include +#endif static int gettimeofday(struct timeval *tp, void *nothing) { (void)nothing; /* we don't support specific time-zones */ -- cgit v1.2.1 From ca3e5a6322c8e9b18dd5dd3997d6e5a06216cbf1 Mon Sep 17 00:00:00 2001 From: Gunter Knauf Date: Sat, 30 Jun 2007 23:45:57 +0000 Subject: moved includes to setup.h so that the project headers also pick them up (eleminate gcc warning). --- lib/timeval.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index a2e9665bb..bb9c0a174 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -68,9 +68,6 @@ static int gettimeofday(struct timeval *tp, void *nothing) } #else /* WIN32 */ /* non-win32 version of Curl_gettimeofday() */ -#if (defined(NETWARE) && !defined(__NOVELL_LIBC__)) -#include -#endif static int gettimeofday(struct timeval *tp, void *nothing) { (void)nothing; /* we don't support specific time-zones */ -- cgit v1.2.1 From 19479ea0217c93fd2973168084d1bb724eb8a34f Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 9 May 2008 16:31:51 +0000 Subject: Internal time differences now use monotonic time source if available. This also implies the removal of the winmm.lib dependency for WIN32. --- lib/timeval.c | 103 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 52 insertions(+), 51 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index bb9c0a174..b36633384 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -23,69 +23,70 @@ #include "timeval.h" -#ifndef HAVE_GETTIMEOFDAY +#if defined(WIN32) && !defined(MSDOS) -#ifdef WIN32 -#include - -static int gettimeofday(struct timeval *tp, void *nothing) +struct timeval curlx_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 curlx_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 curlx_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 curlx_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... -- cgit v1.2.1 From 60dd765b3dd73bd957bff42a990ba391c843a9ff Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 10 May 2008 23:50:55 +0000 Subject: fix syntax error: missing semicolon --- lib/timeval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index b36633384..0bedfbe81 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -52,7 +52,7 @@ struct timeval curlx_tvnow(void) */ struct timeval now; struct timespec tsnow; - (void)clock_gettime(CLOCK_MONOTONIC, &tsnow) + (void)clock_gettime(CLOCK_MONOTONIC, &tsnow); now.tv_sec = tsnow.tv_sec; now.tv_usec = tsnow.tv_nsec / 1000; return now; -- cgit v1.2.1 From ed80eb5b0f11d70db37e8a3b0406fa906842a962 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 12 May 2008 02:04:21 +0000 Subject: configure script will now define HAVE_CLOCK_GETTIME_MONOTONIC symbol only when function clock_gettime() is available and the monotonic timer is also available. Otherwise, in some cases, librt or libposix4 could be used for linking even when finally not using the clock_gettime() function due to lack of the monotonic clock. --- lib/timeval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 0bedfbe81..74f0b3a2f 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -39,7 +39,7 @@ struct timeval curlx_tvnow(void) return now; } -#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) +#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC) struct timeval curlx_tvnow(void) { -- cgit v1.2.1 From 97333deb3f6713d7d12168c8980d69cc60961063 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 2 Jul 2008 03:04:56 +0000 Subject: fallback to gettimeofday when monotonic clock is unavailable at run-time --- lib/timeval.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 74f0b3a2f..25ae76329 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -52,9 +52,24 @@ struct timeval curlx_tvnow(void) */ 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; + if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) { + now.tv_sec = tsnow.tv_sec; + now.tv_usec = tsnow.tv_nsec / 1000; + } + /* + ** Even when the configure process has truly detected monotonic clock + ** availability, it might happen that it is not actually available at + ** run-time. When this occurs simply fallback to other time source. + */ +#ifdef HAVE_GETTIMEOFDAY + else + (void)gettimeofday(&now, NULL); +#else + else { + now.tv_sec = (long)time(NULL); + now.tv_usec = 0; + } +#endif return now; } -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- lib/timeval.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index 25ae76329..cb39308e0 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -18,7 +18,6 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * - * $Id$ ***************************************************************************/ #include "timeval.h" -- cgit v1.2.1 From 97d7a9260e4f2f335b3632180877c25e0efdc8e3 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 25 Nov 2011 13:51:55 +0100 Subject: tvdiff_secs(): sub-zero time difference adjustment Skip a floating point addition operation when integral part of time difference is zero. This avoids potential floating point addition rounding problems while preserving decimal part value. --- lib/timeval.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/timeval.c') diff --git a/lib/timeval.c b/lib/timeval.c index cb39308e0..2fd720144 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -120,8 +120,11 @@ long curlx_tvdiff(struct timeval newer, struct timeval older) */ double curlx_tvdiff_secs(struct timeval newer, struct timeval older) { - return (double)(newer.tv_sec-older.tv_sec)+ - (double)(newer.tv_usec-older.tv_usec)/1000000.0; + if(newer.tv_sec != older.tv_sec) + return (double)(newer.tv_sec-older.tv_sec)+ + (double)(newer.tv_usec-older.tv_usec)/1000000.0; + else + return (double)(newer.tv_usec-older.tv_usec)/1000000.0; } /* return the number of seconds in the given input timeval struct */ -- cgit v1.2.1