Commit 4623862b5c974ce7a798750227d7bc7b8502883c
Committed by
Stéphane Raimbault
1 parent
79a7c1ea
Fix compilation and execution of bandwidth tests in Windows.
Showing
2 changed files
with
17 additions
and
2 deletions
tests/bandwidth-client.c
| ... | ... | @@ -16,11 +16,13 @@ |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | #include <stdio.h> |
| 19 | +#ifndef _MSC_VER | |
| 19 | 20 | #include <unistd.h> |
| 21 | +#include <sys/time.h> | |
| 22 | +#endif | |
| 20 | 23 | #include <string.h> |
| 21 | 24 | #include <stdlib.h> |
| 22 | 25 | #include <time.h> |
| 23 | -#include <sys/time.h> | |
| 24 | 26 | #include <errno.h> |
| 25 | 27 | |
| 26 | 28 | #include <modbus.h> |
| ... | ... | @@ -30,7 +32,15 @@ |
| 30 | 32 | uint32_t gettime_ms(void) |
| 31 | 33 | { |
| 32 | 34 | struct timeval tv; |
| 35 | +#if !defined(_MSC_VER) | |
| 33 | 36 | gettimeofday (&tv, NULL); |
| 37 | +#else | |
| 38 | + SYSTEMTIME st; | |
| 39 | + | |
| 40 | + GetLocalTime(&st); | |
| 41 | + tv.tv_sec = st.wSecond; | |
| 42 | + tv.tv_usec = st.wMilliseconds * 1000; | |
| 43 | +#endif | |
| 34 | 44 | |
| 35 | 45 | return (uint32_t) tv.tv_sec * 1000 + tv.tv_usec / 1000; |
| 36 | 46 | } | ... | ... |
tests/bandwidth-server-one.c
| ... | ... | @@ -16,10 +16,15 @@ |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | #include <stdio.h> |
| 19 | +#ifndef _MSC_VER | |
| 19 | 20 | #include <unistd.h> |
| 21 | +#endif | |
| 20 | 22 | #include <string.h> |
| 21 | 23 | #include <stdlib.h> |
| 22 | 24 | #include <errno.h> |
| 25 | +#if !defined(_WIN32) | |
| 26 | +#define closesocket(s) close(s) | |
| 27 | +#endif | |
| 23 | 28 | |
| 24 | 29 | #include <modbus.h> |
| 25 | 30 | |
| ... | ... | @@ -86,7 +91,7 @@ int main(int argc, char *argv[]) |
| 86 | 91 | printf("Quit the loop: %s\n", modbus_strerror(errno)); |
| 87 | 92 | |
| 88 | 93 | modbus_mapping_free(mb_mapping); |
| 89 | - close(socket); | |
| 94 | + closesocket(socket); | |
| 90 | 95 | modbus_free(ctx); |
| 91 | 96 | |
| 92 | 97 | return 0; | ... | ... |