Bläddra i källkod

Fix compilation and execution of bandwidth tests in Windows.

oldfaber 12 år sedan
förälder
incheckning
4623862b5c
2 ändrade filer med 17 tillägg och 2 borttagningar
  1. 11 1
      tests/bandwidth-client.c
  2. 6 1
      tests/bandwidth-server-one.c

+ 11 - 1
tests/bandwidth-client.c

@@ -16,11 +16,13 @@
  */
 
 #include <stdio.h>
+#ifndef _MSC_VER
 #include <unistd.h>
+#include <sys/time.h>
+#endif
 #include <string.h>
 #include <stdlib.h>
 #include <time.h>
-#include <sys/time.h>
 #include <errno.h>
 
 #include <modbus.h>
@@ -30,7 +32,15 @@
 uint32_t gettime_ms(void)
 {
     struct timeval tv;
+#if !defined(_MSC_VER)
     gettimeofday (&tv, NULL);
+#else
+    SYSTEMTIME st;
+
+    GetLocalTime(&st);
+    tv.tv_sec = st.wSecond;
+    tv.tv_usec = st.wMilliseconds * 1000;
+#endif
 
     return (uint32_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
 }

+ 6 - 1
tests/bandwidth-server-one.c

@@ -16,10 +16,15 @@
  */
 
 #include <stdio.h>
+#ifndef _MSC_VER
 #include <unistd.h>
+#endif
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
+#if !defined(_WIN32)
+#define closesocket(s) close(s)
+#endif
 
 #include <modbus.h>
 
@@ -86,7 +91,7 @@ int main(int argc, char *argv[])
     printf("Quit the loop: %s\n", modbus_strerror(errno));
 
     modbus_mapping_free(mb_mapping);
-    close(socket);
+    closesocket(socket);
     modbus_free(ctx);
 
     return 0;