Revision: 4783 http://tigervnc.svn.sourceforge.net/tigervnc/?rev=4783&view=rev Author: ossman_ Date: 2011-11-08 12:42:41 +0000 (Tue, 08 Nov 2011) Log Message: ----------- Add helper to easily determine how much time has passed since some previous event.
Modified Paths: -------------- trunk/common/rfb/util.cxx trunk/common/rfb/util.h Modified: trunk/common/rfb/util.cxx =================================================================== --- trunk/common/rfb/util.cxx 2011-11-08 12:12:02 UTC (rev 4782) +++ trunk/common/rfb/util.cxx 2011-11-08 12:42:41 UTC (rev 4783) @@ -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 @@ 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; + } }; Modified: trunk/common/rfb/util.h =================================================================== --- trunk/common/rfb/util.h 2011-11-08 12:12:02 UTC (rev 4782) +++ trunk/common/rfb/util.h 2011-11-08 12:42:41 UTC (rev 4783) @@ -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 @@ 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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ RSA(R) Conference 2012 Save $700 by Nov 18 Register now http://p.sf.net/sfu/rsa-sfdev2dev1 _______________________________________________ Tigervnc-commits mailing list Tigervnc-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tigervnc-commits