aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2011-11-08 12:42:41 +0000
committerPierre Ossman <ossman@cendio.se>2011-11-08 12:42:41 +0000
commit5bc20a699359dfba501880bc776f8fd3c8e5b889 (patch)
tree817cecff8117e1d52daf1a0d6951f33e5dcbd03f /common
parenta830bec4cd22842cbc171cdaa02ad842d53adb53 (diff)
downloadtigervnc-5bc20a699359dfba501880bc776f8fd3c8e5b889.tar.gz
tigervnc-5bc20a699359dfba501880bc776f8fd3c8e5b889.zip
Add helper to easily determine how much time has passed since some previous
event. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4783 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'common')
-rw-r--r--common/rfb/util.cxx16
-rw-r--r--common/rfb/util.h5
2 files changed, 21 insertions, 0 deletions
diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx
index 265114f9..2709f2cc 100644
--- a/common/rfb/util.cxx
+++ b/common/rfb/util.cxx
@@ -34,6 +34,8 @@
#include <config.h>
#endif
+#include <sys/time.h>
+
#include <rfb/util.h>
// Provide strcasecmp() and/or strncasecmp() if absent on this system.
@@ -185,4 +187,18 @@ namespace rfb {
dest[src ? destlen-1 : 0] = 0;
}
+ unsigned msSince(const struct timeval *then)
+ {
+ struct timeval now;
+ unsigned diff;
+
+ gettimeofday(&now, NULL);
+
+ diff = (now.tv_sec - then->tv_sec) * 1000;
+
+ diff += now.tv_usec / 1000;
+ diff -= then->tv_usec / 1000;
+
+ return diff;
+ }
};
diff --git a/common/rfb/util.h b/common/rfb/util.h
index 4124769a..7d90a6b2 100644
--- a/common/rfb/util.h
+++ b/common/rfb/util.h
@@ -30,6 +30,8 @@
#include <limits.h>
#include <string.h>
+struct timeval;
+
namespace rfb {
// -=- Class to handle cleanup of arrays of characters
@@ -85,6 +87,9 @@ namespace rfb {
inline int secsToMillis(int secs) {
return (secs < 0 || secs > (INT_MAX/1000) ? INT_MAX : secs * 1000);
}
+
+ // Returns time elapsed since given moment in milliseconds.
+ unsigned msSince(const struct timeval *then);
}
// Some platforms (e.g. Windows) include max() and min() macros in their