Centralize logic to get current server time

A few different implementations of computing the current time were
spread out through the code base, most of them using gettimeofday().

This centralizes the logic in CUtil::GetTime() for easier maintenance,
and also allows all call sites to get the benefit of the clock_gettime()
code path on systems that support it.
This commit is contained in:
Tor Arne Vestbø authored and Tor Arne Vestbø committed 2016-07-06 01:16:15 +02:00
1 parent 852c9832a0
commit 02bfb9eaf5
6 files changed
+32 -34

No files matched your search

+1 -13
View File
@@ -216,19 +216,7 @@ void CMessage::InitTime() {
return;
}
#ifdef HAVE_CLOCK_GETTIME
timespec ts;
if (clock_gettime(CLOCK_REALTIME, &ts) == 0) {
m_time.tv_sec = ts.tv_sec;
m_time.tv_usec = ts.tv_nsec / 1000;
return;
}
#endif
if (gettimeofday(&m_time, nullptr)) {
m_time.tv_sec = time(nullptr);
m_time.tv_usec = 0;
}
m_time = CUtils::GetTime();
}
void CMessage::InitType() {