@@ -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;
return (uint32_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
@@ -16,10 +16,15 @@
+#if !defined(_WIN32)
+#define closesocket(s) close(s)
@@ -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;