GUACAMOLE-239: When available, use CLOCK_MONOTONIC to prevent backwards running time

This commit is contained in:
Roman Stoffel 2017-03-23 23:06:24 +01:00
parent da7b77d2ec
commit ddc1aa0b5f

View File

@ -33,9 +33,13 @@ guac_timestamp guac_timestamp_current() {
struct timespec current; struct timespec current;
/* Get current time */ /* Get current time, monotonically increasing */
#ifdef CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &current);
#else
clock_gettime(CLOCK_REALTIME, &current); clock_gettime(CLOCK_REALTIME, &current);
#endif
/* Calculate milliseconds */ /* Calculate milliseconds */
return (guac_timestamp) current.tv_sec * 1000 + current.tv_nsec / 1000000; return (guac_timestamp) current.tv_sec * 1000 + current.tv_nsec / 1000000;