]> source.dussan.org Git - tigervnc.git/commitdiff
Use mingw's gettimeofday()
authorPierre Ossman <ossman@cendio.se>
Mon, 9 Nov 2015 14:27:54 +0000 (15:27 +0100)
committerPierre Ossman <ossman@cendio.se>
Mon, 9 Nov 2015 14:27:54 +0000 (15:27 +0100)
mingw has a perfectly functional gettimeofday() so use that instead
of having multiple copies of our own version.

common/rdr/FdInStream.cxx
common/rfb/Timer.cxx

index 9f35c9fbfcc344f1222df08fe6b3b56823ade580..a8b30857b937feb9cdc8ce26ec7d5895e35fd6cf 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <sys/time.h>
 #ifdef _WIN32
 #include <winsock2.h>
-#ifndef _WIN32_WCE
-#include <sys/timeb.h>
-#endif
 #define read(s,b,l) recv(s,(char*)b,l,0)
 #define close closesocket
 #undef errno
@@ -36,7 +34,6 @@
 #else
 #include <sys/types.h>
 #include <unistd.h>
-#include <sys/time.h>
 #endif
 
 #ifndef vncmin
@@ -161,35 +158,6 @@ int FdInStream::overrun(int itemSize, int nItems, bool wait)
   return nItems;
 }
 
-#ifdef _WIN32
-static void gettimeofday(struct timeval* tv, void*)
-{
-  LARGE_INTEGER counts, countsPerSec;
-  static double usecPerCount = 0.0;
-
-  if (QueryPerformanceCounter(&counts)) {
-    if (usecPerCount == 0.0) {
-      QueryPerformanceFrequency(&countsPerSec);
-      usecPerCount = 1000000.0 / countsPerSec.QuadPart;
-    }
-
-    LONGLONG usecs = (LONGLONG)(counts.QuadPart * usecPerCount);
-    tv->tv_usec = (long)(usecs % 1000000);
-    tv->tv_sec = (long)(usecs / 1000000);
-
-  } else {
-#ifndef _WIN32_WCE
-    struct timeb tb;
-    ftime(&tb);
-    tv->tv_sec = tb.time;
-    tv->tv_usec = tb.millitm * 1000;
-#else
-    throw SystemException("QueryPerformanceCounter", GetLastError());
-#endif
-  }
-}
-#endif
-
 //
 // readWithTimeoutOrCallback() reads up to the given length in bytes from the
 // file descriptor into a buffer.  If the wait argument is false, then zero is
index 5f9c6f2f46f66f30b5229fbd4662afb9079da1e3..676f24e10daa49b50f48bdd119efa8c91f903b24 100644 (file)
 // -=- Timer.cxx
 
 #include <stdio.h>
-#ifdef WIN32
-#ifndef _WIN32_WCE
-#include <sys/timeb.h>
-#endif
-#endif
+#include <sys/time.h>
+
 #include <rfb/Timer.h>
 #include <rfb/util.h>
 #include <rfb/LogWriter.h>
@@ -40,39 +37,6 @@ static LogWriter vlog("Timer");
 #endif
 
 
-// Win32 does not provide gettimeofday, so we emulate it to simplify the
-// Timer code.
-
-#ifdef _WIN32
-static void gettimeofday(struct timeval* tv, void*)
-{
-  LARGE_INTEGER counts, countsPerSec;
-  static double usecPerCount = 0.0;
-
-  if (QueryPerformanceCounter(&counts)) {
-    if (usecPerCount == 0.0) {
-      QueryPerformanceFrequency(&countsPerSec);
-      usecPerCount = 1000000.0 / countsPerSec.QuadPart;
-    }
-
-    LONGLONG usecs = (LONGLONG)(counts.QuadPart * usecPerCount);
-    tv->tv_usec = (long)(usecs % 1000000);
-    tv->tv_sec = (long)(usecs / 1000000);
-
-  } else {
-#ifndef _WIN32_WCE
-    struct timeb tb;
-    ftime(&tb);
-    tv->tv_sec = tb.time;
-    tv->tv_usec = tb.millitm * 1000;
-#else
-    throw SystemException("QueryPerformanceCounter", GetLastError());
-#endif
-  }
-}
-#endif
-
-
 // Millisecond timeout processing helper functions
 
 inline static timeval addMillis(timeval inTime, int millis) {