[Box Backup-commit] COMMIT r1318 - box/chris/general/lib/common
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Sat Mar 3 21:43:51 GMT 2007
Author: chris
Date: 2007-03-03 21:43:51 +0000 (Sat, 03 Mar 2007)
New Revision: 1318
Modified:
box/chris/general/lib/common/BoxTime.cpp
Log:
Use gettimeofday() if we have it, to return system time more accurately
and avoid spinning (from chris/merge)
Modified: box/chris/general/lib/common/BoxTime.cpp
===================================================================
--- box/chris/general/lib/common/BoxTime.cpp 2007-03-03 21:42:39 UTC (rev 1317)
+++ box/chris/general/lib/common/BoxTime.cpp 2007-03-03 21:43:51 UTC (rev 1318)
@@ -9,7 +9,17 @@
#include "Box.h"
-#include <time.h>
+#ifdef HAVE_SYS_TIME_H
+ #include <sys/time.h>
+#endif
+#ifdef HAVE_TIME_H
+ #include <time.h>
+#endif
+#ifdef HAVE_SYSLOG_H
+ #include <syslog.h>
+#endif
+#include <errno.h>
+#include <string.h>
#include "BoxTime.h"
@@ -19,13 +29,27 @@
//
// Function
// Name: GetCurrentBoxTime()
-// Purpose: Returns the current time as a box time. (1 sec precision)
+// Purpose: Returns the current time as a box time.
+// (1 sec precision, or better if supported by system)
// Created: 2003/10/08
//
// --------------------------------------------------------------------------
box_time_t GetCurrentBoxTime()
{
+ #ifdef HAVE_GETTIMEOFDAY
+ struct timeval tv;
+ if (gettimeofday(&tv, NULL) != 0)
+ {
+ ::syslog(LOG_ERR, "gettimeofday() failed (%s), "
+ "dropping precision", strerror(errno));
+ }
+ else
+ {
+ box_time_t timeNow = (tv.tv_sec * MICRO_SEC_IN_SEC_LL)
+ + tv.tv_usec;
+ return timeNow;
+ }
+ #endif
+
return SecondsToBoxTime(time(0));
}
-
-
More information about the Boxbackup-commit
mailing list