diff options
author | Daniel Stenberg <daniel@haxx.se> | 2017-06-07 13:16:56 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2017-06-14 15:46:39 +0100 |
commit | adef394ac5390e80227c949cbea4a7c22a114677 (patch) | |
tree | 182b36490d31233aff436b329d3d33ae13f9d4bf /lib/timeval.c | |
parent | 11c2fb04467520b82f2251629710e6d4a0798700 (diff) | |
download | curl-adef394ac5390e80227c949cbea4a7c22a114677.tar.gz |
timers: store internal time stamps as time_t instead of doubles
This gives us accurate precision and it allows us to avoid storing "no
time" for systems with too low timer resolution as we then bump the time
up to 1 microsecond. Should fix test 573 on windows.
Remove the now unused curlx_tvdiff_secs() function.
Maintains the external getinfo() API with using doubles.
Fixes #1531
Diffstat (limited to 'lib/timeval.c')
-rw-r--r-- | lib/timeval.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/timeval.c b/lib/timeval.c index bed44c573..1012b4e39 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2017, 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 @@ -130,14 +130,24 @@ time_t curlx_tvdiff(struct timeval newer, struct timeval older) } /* - * Same as curlx_tvdiff but with full usec resolution. + * 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 seconds with subsecond resolution. + * Returns: the time difference in number of microseconds. For too large diffs + * it returns max value. */ -double curlx_tvdiff_secs(struct timeval newer, struct timeval older) +time_t Curl_tvdiff_us(struct timeval newer, struct timeval older) { - if(newer.tv_sec != older.tv_sec) - return (double)(newer.tv_sec-older.tv_sec)+ - (double)(newer.tv_usec-older.tv_usec)/1000000.0; - return (double)(newer.tv_usec-older.tv_usec)/1000000.0; + time_t diff = newer.tv_sec-older.tv_sec; +#if SIZEOF_TIME_T < 8 + /* for 32bit time_t systems */ + if(diff >= (0x7fffffff/1000000)) + return 0x7fffffff; +#else + /* for 64bit time_t systems */ + if(diff >= (0x7fffffffffffffff/1000000)) + return 0x7fffffffffffffff; +#endif + return (newer.tv_sec-older.tv_sec)*1000000+ + (time_t)(newer.tv_usec-older.tv_usec); } |