diff options
author | Alberto Gonzalez Iniesta <agi@inittab.org> | 2016-12-27 18:25:47 +0100 |
---|---|---|
committer | Alberto Gonzalez Iniesta <agi@inittab.org> | 2016-12-27 18:25:47 +0100 |
commit | 79f3537f69e125f19f59c36aa090120a63186a54 (patch) | |
tree | 2089a3b7dac990841dbc2e4d9b2f535b82dbb0af /src/compat/compat-gettimeofday.c | |
parent | f2137fedb30cb87448eb03b2f288920df6187571 (diff) | |
parent | 3a2bbdb05ca6a6996e424c9fb225cb0d53804125 (diff) |
Merge tag 'upstream/2.4.0'
Upstream version 2.4.0
Diffstat (limited to 'src/compat/compat-gettimeofday.c')
-rw-r--r-- | src/compat/compat-gettimeofday.c | 98 |
1 files changed, 51 insertions, 47 deletions
diff --git a/src/compat/compat-gettimeofday.c b/src/compat/compat-gettimeofday.c index 19feaae..d53e360 100644 --- a/src/compat/compat-gettimeofday.c +++ b/src/compat/compat-gettimeofday.c @@ -5,7 +5,7 @@ * packet encryption, packet authentication, and * packet compression. * - * Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <sales@openvpn.net> + * Copyright (C) 2002-2017 OpenVPN Technologies, Inc. <sales@openvpn.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -48,12 +48,12 @@ static unsigned int last_msec = 0; static int bt_last = 0; static void -gettimeofday_calibrate (void) +gettimeofday_calibrate(void) { - const time_t t = time(NULL); - const DWORD gtc = GetTickCount(); - gtc_base = t - gtc/1000; - gtc_last = gtc; + const time_t t = time(NULL); + const DWORD gtc = GetTickCount(); + gtc_base = t - gtc/1000; + gtc_last = gtc; } /* @@ -62,68 +62,72 @@ gettimeofday_calibrate (void) * more processor cycles than GetTickCount. */ int -gettimeofday (struct timeval *tv, void *tz) +gettimeofday(struct timeval *tv, void *tz) { - const DWORD gtc = GetTickCount(); - int bt = 0; - time_t sec; - unsigned int msec; - const int backtrack_hold_seconds = 10; + const DWORD gtc = GetTickCount(); + int bt = 0; + time_t sec; + unsigned int msec; + const int backtrack_hold_seconds = 10; - (void)tz; + (void)tz; - /* recalibrate at the dreaded 49.7 day mark */ - if (!gtc_base || gtc < gtc_last) - gettimeofday_calibrate (); - gtc_last = gtc; + /* recalibrate at the dreaded 49.7 day mark */ + if (!gtc_base || gtc < gtc_last) + { + gettimeofday_calibrate(); + } + gtc_last = gtc; - sec = gtc_base + gtc / 1000; - msec = gtc % 1000; + sec = gtc_base + gtc / 1000; + msec = gtc % 1000; - if (sec == last_sec) + if (sec == last_sec) { - if (msec < last_msec) - { - msec = last_msec; - bt = 1; - } + if (msec < last_msec) + { + msec = last_msec; + bt = 1; + } } - else if (sec < last_sec) + else if (sec < last_sec) { - /* We try to dampen out backtracks of less than backtrack_hold_seconds. - Larger backtracks will be passed through and dealt with by the - TIME_BACKTRACK_PROTECTION code (if enabled) */ - if (sec > last_sec - backtrack_hold_seconds) - { - sec = last_sec; - msec = last_msec; - } - bt = 1; + /* We try to dampen out backtracks of less than backtrack_hold_seconds. + * Larger backtracks will be passed through and dealt with by the + * TIME_BACKTRACK_PROTECTION code (if enabled) */ + if (sec > last_sec - backtrack_hold_seconds) + { + sec = last_sec; + msec = last_msec; + } + bt = 1; } - tv->tv_sec = (long)last_sec = (long)sec; - tv->tv_usec = (last_msec = msec) * 1000; + tv->tv_sec = (long)last_sec = (long)sec; + tv->tv_usec = (last_msec = msec) * 1000; - if (bt && !bt_last) - gettimeofday_calibrate (); - bt_last = bt; + if (bt && !bt_last) + { + gettimeofday_calibrate(); + } + bt_last = bt; - return 0; + return 0; } -#else +#else /* ifdef _WIN32 */ #ifdef HAVE_TIME_H #include <time.h> #endif int -gettimeofday (struct timeval *tv, void *tz) +gettimeofday(struct timeval *tv, void *tz) { - (void)tz; - tv->tv_sec = time(NULL); - tv->tv_usec = 0; - return 0; + (void)tz; + tv->tv_sec = time(NULL); + tv->tv_usec = 0; + return 0; } #endif /* _WIN32 */ |