Browse Source

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
tags/v1.1.90
Pierre Ossman 12 years ago
parent
commit
5bc20a6993
2 changed files with 21 additions and 0 deletions
  1. 16
    0
      common/rfb/util.cxx
  2. 5
    0
      common/rfb/util.h

+ 16
- 0
common/rfb/util.cxx View File

#include <config.h> #include <config.h>
#endif #endif


#include <sys/time.h>

#include <rfb/util.h> #include <rfb/util.h>


// Provide strcasecmp() and/or strncasecmp() if absent on this system. // Provide strcasecmp() and/or strncasecmp() if absent on this system.
dest[src ? destlen-1 : 0] = 0; 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;
}
}; };

+ 5
- 0
common/rfb/util.h View File

#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>


struct timeval;

namespace rfb { namespace rfb {


// -=- Class to handle cleanup of arrays of characters // -=- Class to handle cleanup of arrays of characters
inline int secsToMillis(int secs) { inline int secsToMillis(int secs) {
return (secs < 0 || secs > (INT_MAX/1000) ? INT_MAX : secs * 1000); 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 // Some platforms (e.g. Windows) include max() and min() macros in their

Loading…
Cancel
Save