summaryrefslogtreecommitdiffstats
path: root/src/openvpn/otime.c
diff options
context:
space:
mode:
authorAlon Bar-Lev <alon.barlev@gmail.com>2012-02-29 22:12:15 +0200
committerDavid Sommerseth <davids@redhat.com>2012-03-22 22:53:39 +0100
commit3d163bc544ab9dfc62d9a2c865f8abb865bf6eb3 (patch)
treed4ec60463290c45c2b201797099214d854edc042 /src/openvpn/otime.c
parentdc81e743989640cc681a40e69455cc9fc736ab9c (diff)
downloadopenvpn-3d163bc544ab9dfc62d9a2c865f8abb865bf6eb3.tar.gz
openvpn-3d163bc544ab9dfc62d9a2c865f8abb865bf6eb3.tar.xz
openvpn-3d163bc544ab9dfc62d9a2c865f8abb865bf6eb3.zip
build: move gettimeofday() emulation to compat
Remove all references to gettimeofday() from main project. SIDE EFFECT: mingw will use its own internal gettimeofday(). Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com> Acked-by: David Sommerseth <davids@redhat.com> Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'src/openvpn/otime.c')
-rw-r--r--src/openvpn/otime.c84
1 files changed, 3 insertions, 81 deletions
diff --git a/src/openvpn/otime.c b/src/openvpn/otime.c
index 173573c..2c1e5b1 100644
--- a/src/openvpn/otime.c
+++ b/src/openvpn/otime.c
@@ -36,7 +36,7 @@
time_t now = 0; /* GLOBAL */
-#if TIME_BACKTRACK_PROTECTION && defined(HAVE_GETTIMEOFDAY)
+#if TIME_BACKTRACK_PROTECTION
static time_t now_adj = 0; /* GLOBAL */
time_t now_usec = 0; /* GLOBAL */
@@ -76,7 +76,7 @@ update_now_usec (struct timeval *tv)
now_usec = tv->tv_usec;
}
-#endif /* TIME_BACKTRACK_PROTECTION && defined(HAVE_GETTIMEOFDAY) */
+#endif /* TIME_BACKTRACK_PROTECTION */
/*
* Return a numerical string describing a struct timeval.
@@ -120,13 +120,7 @@ time_string (time_t t, int usec, bool show_usec, struct gc_arena *gc)
}
else
{
-#ifdef HAVE_GETTIMEOFDAY
- if (gettimeofday (&tv, NULL))
-#endif
- {
- tv.tv_sec = time (NULL);
- tv.tv_usec = 0;
- }
+ gettimeofday (&tv, NULL);
}
t = tv.tv_sec;
@@ -185,78 +179,6 @@ frequency_limit_event_allowed (struct frequency_limit *f)
return true;
}
-#ifdef WIN32
-
-static time_t gtc_base = 0;
-static DWORD gtc_last = 0;
-static time_t last_sec = 0;
-static unsigned int last_msec = 0;
-static bool bt_last = false;
-
-static void
-gettimeofday_calibrate (void)
-{
- const time_t t = time(NULL);
- const DWORD gtc = GetTickCount();
- gtc_base = t - gtc/1000;
- gtc_last = gtc;
-}
-
-/*
- * Rewritten by JY for OpenVPN 2.1, after I realized that
- * QueryPerformanceCounter takes nearly 2 orders of magnitude
- * more processor cycles than GetTickCount.
- */
-int
-gettimeofday (struct timeval *tv, void *tz)
-{
- const DWORD gtc = GetTickCount();
- bool bt = false;
- time_t sec;
- unsigned int msec;
- const int backtrack_hold_seconds = 10;
-
- /* 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;
-
- if (sec == last_sec)
- {
- if (msec < last_msec)
- {
- msec = last_msec;
- bt = true;
- }
- }
- 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 = true;
- }
-
- tv->tv_sec = last_sec = sec;
- tv->tv_usec = (last_msec = msec) * 1000;
-
- if (bt && !bt_last)
- gettimeofday_calibrate ();
- bt_last = bt;
-
- return 0;
-}
-
-#endif /* WIN32 */
-
#ifdef TIME_TEST
void
time_test (void)