From 55f5f74658a9b3f16d57d751e303e8af51161d1f Mon Sep 17 00:00:00 2001 From: cpq Date: Fri, 25 Dec 2020 19:24:51 +0000 Subject: [PATCH] Add mingw gcc and g++ tests --- Makefile | 11 ++++++++++- mongoose.c | 33 ++++++++++++++++++--------------- src/http.c | 4 ++-- src/sock.c | 29 ++++++++++++++++------------- 4 files changed, 46 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index b851affd..46ad8404 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ SSL ?= MBEDTLS CDIR ?= $(realpath $(CURDIR)) VC98 = docker run --rm -e WINEDEBUG=-all -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/vc98 VC2017 = docker run --rm -e WINEDEBUG=-all -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/vc2017 +MINGW = docker run --rm -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/mingw GCC = docker run --rm -v $(CDIR):$(CDIR) -w $(CDIR) mdashnet/cc2 VCFLAGS = /nologo /W3 /O2 /I. $(DEFS) $(TFLAGS) CLANG ?= clang # /usr/local/opt/llvm\@9/bin/clang @@ -30,7 +31,7 @@ CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL)/include LDFLAGS ?= -L$(OPENSSL)/lib -lssl -lcrypto endif -all: mg_prefix test test++ ex vc98 vc2017 linux linux++ infer fuzz +all: mg_prefix test test++ ex vc98 vc2017 mingw mingw++ linux linux++ infer fuzz ex: @for X in $(EXAMPLES); do $(MAKE) -C $$X $(EXAMPLE_TARGET); done @@ -77,6 +78,14 @@ vc2017: Makefile mongoose.c mongoose.h test/unit_test.c $(VC2017) wine64 cl mongoose.c test/unit_test.c $(VCFLAGS) ws2_32.lib /Fe$@.exe $(VC2017) wine64 $@.exe +mingw: Makefile mongoose.c mongoose.h test/unit_test.c + $(MINGW) i686-w64-mingw32-gcc mongoose.c test/unit_test.c -W -Wall -Werror -I. $(DEFS) -lwsock32 -o test.exe + $(VC98) wine test.exe + +mingw++: Makefile mongoose.c mongoose.h test/unit_test.c + $(MINGW) i686-w64-mingw32-g++ mongoose.c test/unit_test.c -W -Wall -Werror -I. $(DEFS) -lwsock32 -o test.exe + # Note: for some reason, a binary built with mingw g++, fails to run + #linux: CFLAGS += -DMG_ENABLE_IPV6=$(IPV6) linux: CFLAGS += -fsanitize=address,undefined linux: Makefile mongoose.c mongoose.h test/unit_test.c diff --git a/mongoose.c b/mongoose.c index c4d404bf..76d3158b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -821,7 +821,6 @@ typedef struct win32_dir { int gettimeofday(struct timeval *tv, void *tz) { FILETIME ft; unsigned __int64 tmpres = 0; - static int tzflag = 0; if (tv != NULL) { GetSystemTimeAsFileTime(&ft); @@ -833,6 +832,7 @@ int gettimeofday(struct timeval *tv, void *tz) { tv->tv_sec = (long) (tmpres / 1000000UL); tv->tv_usec = (long) (tmpres % 1000000UL); } + (void) tz; return 0; } @@ -864,7 +864,7 @@ DIR *opendir(const char *name) { if (name == NULL) { SetLastError(ERROR_BAD_ARGUMENTS); - } else if ((d = malloc(sizeof(*d))) == NULL) { + } else if ((d = (DIR *) malloc(sizeof(*d))) == NULL) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); } else { to_wchar(name, wpath, sizeof(wpath) / sizeof(wpath[0])); @@ -2496,7 +2496,7 @@ static int mg_sock_recv(struct mg_connection *c, void *buf, int len, #if MG_ENABLE_IPV6 if (c->peer.is_ip6) slen = sizeof(usa.sin6); #endif - n = recvfrom(FD(c), buf, len, 0, &usa.sa, &slen); + n = recvfrom(FD(c), (char *) buf, len, 0, &usa.sa, &slen); if (n > 0) { if (c->peer.is_ip6) { #if MG_ENABLE_IPV6 @@ -2509,7 +2509,7 @@ static int mg_sock_recv(struct mg_connection *c, void *buf, int len, } } } else { - n = recv(FD(c), buf, len, MSG_NONBLOCKING); + n = recv(FD(c), (char *) buf, len, MSG_NONBLOCKING); } *fail = (n == 0) || (n < 0 && mg_sock_failed()); return n; @@ -2524,9 +2524,9 @@ static int mg_sock_send(struct mg_connection *c, const void *buf, int len, #if MG_ENABLE_IPV6 if (c->peer.is_ip6) slen = sizeof(usa.sin6); #endif - n = sendto(FD(c), buf, len, 0, &usa.sa, slen); + n = sendto(FD(c), (char *) buf, len, 0, &usa.sa, slen); } else { - n = send(FD(c), buf, len, MSG_NONBLOCKING); + n = send(FD(c), (char *) buf, len, MSG_NONBLOCKING); } *fail = (n == 0) || (n < 0 && mg_sock_failed()); return n; @@ -2610,18 +2610,18 @@ SOCKET mg_open_listener(const char *url) { // SO_REUSEADDR was designed for, and leads to hard-to-track failure // scenarios. Therefore, SO_REUSEADDR was disabled on Windows unless // SO_EXCLUSIVEADDRUSE is supported and set on a socket. - !setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) && + !setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) && #endif #if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE) // "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" - !setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (void *) &on, + !setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &on, sizeof(on)) && #endif bind(fd, &usa.sa, slen) == 0 && // NOTE(lsm): FreeRTOS uses backlog value as a connection limit (type == SOCK_DGRAM || listen(fd, 128) == 0)) { mg_set_non_blocking_mode(fd); - } else if (fd >= 0) { + } else if (fd != INVALID_SOCKET) { LOG(LL_ERROR, ("Failed to listen on %s, errno %d", url, MG_SOCK_ERRNO)); closesocket(fd); fd = INVALID_SOCKET; @@ -2692,22 +2692,25 @@ static void setsockopts(struct mg_connection *c) { #if MG_ARCH == MG_ARCH_FREERTOS FreeRTOS_FD_SET(c->fd, c->mgr->ss, eSELECT_READ | eSELECT_EXCEPT); #else - int on = 1, cnt = 3, intvl = 20; + int on = 1; #if !defined(SOL_TCP) #define SOL_TCP IPPROTO_TCP #endif - setsockopt(FD(c), SOL_TCP, TCP_NODELAY, (void *) &on, sizeof(on)); + setsockopt(FD(c), SOL_TCP, TCP_NODELAY, (char *) &on, sizeof(on)); #if defined(TCP_QUICKACK) - setsockopt(FD(c), SOL_TCP, TCP_QUICKACK, (void *) &on, sizeof(on)); + setsockopt(FD(c), SOL_TCP, TCP_QUICKACK, (char *) &on, sizeof(on)); #endif - setsockopt(FD(c), SOL_SOCKET, SO_KEEPALIVE, (void *) &on, sizeof(on)); + setsockopt(FD(c), SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on)); #if ESP32 || ESP8266 || defined(__linux__) int idle = 60; setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)); #endif #ifndef _WIN32 - setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)); - setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)); + { + int cnt = 3, intvl = 20; + setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)); + setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)); + } #endif #endif } diff --git a/src/http.c b/src/http.c index 691ebd13..bc764593 100644 --- a/src/http.c +++ b/src/http.c @@ -427,7 +427,6 @@ typedef struct win32_dir { int gettimeofday(struct timeval *tv, void *tz) { FILETIME ft; unsigned __int64 tmpres = 0; - static int tzflag = 0; if (tv != NULL) { GetSystemTimeAsFileTime(&ft); @@ -439,6 +438,7 @@ int gettimeofday(struct timeval *tv, void *tz) { tv->tv_sec = (long) (tmpres / 1000000UL); tv->tv_usec = (long) (tmpres % 1000000UL); } + (void) tz; return 0; } @@ -470,7 +470,7 @@ DIR *opendir(const char *name) { if (name == NULL) { SetLastError(ERROR_BAD_ARGUMENTS); - } else if ((d = malloc(sizeof(*d))) == NULL) { + } else if ((d = (DIR *) malloc(sizeof(*d))) == NULL) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); } else { to_wchar(name, wpath, sizeof(wpath) / sizeof(wpath[0])); diff --git a/src/sock.c b/src/sock.c index 4265f0ad..3c5ea5f0 100644 --- a/src/sock.c +++ b/src/sock.c @@ -87,7 +87,7 @@ static int mg_sock_recv(struct mg_connection *c, void *buf, int len, #if MG_ENABLE_IPV6 if (c->peer.is_ip6) slen = sizeof(usa.sin6); #endif - n = recvfrom(FD(c), buf, len, 0, &usa.sa, &slen); + n = recvfrom(FD(c), (char *) buf, len, 0, &usa.sa, &slen); if (n > 0) { if (c->peer.is_ip6) { #if MG_ENABLE_IPV6 @@ -100,7 +100,7 @@ static int mg_sock_recv(struct mg_connection *c, void *buf, int len, } } } else { - n = recv(FD(c), buf, len, MSG_NONBLOCKING); + n = recv(FD(c), (char *) buf, len, MSG_NONBLOCKING); } *fail = (n == 0) || (n < 0 && mg_sock_failed()); return n; @@ -115,9 +115,9 @@ static int mg_sock_send(struct mg_connection *c, const void *buf, int len, #if MG_ENABLE_IPV6 if (c->peer.is_ip6) slen = sizeof(usa.sin6); #endif - n = sendto(FD(c), buf, len, 0, &usa.sa, slen); + n = sendto(FD(c), (char *) buf, len, 0, &usa.sa, slen); } else { - n = send(FD(c), buf, len, MSG_NONBLOCKING); + n = send(FD(c), (char *) buf, len, MSG_NONBLOCKING); } *fail = (n == 0) || (n < 0 && mg_sock_failed()); return n; @@ -201,18 +201,18 @@ SOCKET mg_open_listener(const char *url) { // SO_REUSEADDR was designed for, and leads to hard-to-track failure // scenarios. Therefore, SO_REUSEADDR was disabled on Windows unless // SO_EXCLUSIVEADDRUSE is supported and set on a socket. - !setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) && + !setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) && #endif #if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE) // "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" - !setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (void *) &on, + !setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &on, sizeof(on)) && #endif bind(fd, &usa.sa, slen) == 0 && // NOTE(lsm): FreeRTOS uses backlog value as a connection limit (type == SOCK_DGRAM || listen(fd, 128) == 0)) { mg_set_non_blocking_mode(fd); - } else if (fd >= 0) { + } else if (fd != INVALID_SOCKET) { LOG(LL_ERROR, ("Failed to listen on %s, errno %d", url, MG_SOCK_ERRNO)); closesocket(fd); fd = INVALID_SOCKET; @@ -283,22 +283,25 @@ static void setsockopts(struct mg_connection *c) { #if MG_ARCH == MG_ARCH_FREERTOS FreeRTOS_FD_SET(c->fd, c->mgr->ss, eSELECT_READ | eSELECT_EXCEPT); #else - int on = 1, cnt = 3, intvl = 20; + int on = 1; #if !defined(SOL_TCP) #define SOL_TCP IPPROTO_TCP #endif - setsockopt(FD(c), SOL_TCP, TCP_NODELAY, (void *) &on, sizeof(on)); + setsockopt(FD(c), SOL_TCP, TCP_NODELAY, (char *) &on, sizeof(on)); #if defined(TCP_QUICKACK) - setsockopt(FD(c), SOL_TCP, TCP_QUICKACK, (void *) &on, sizeof(on)); + setsockopt(FD(c), SOL_TCP, TCP_QUICKACK, (char *) &on, sizeof(on)); #endif - setsockopt(FD(c), SOL_SOCKET, SO_KEEPALIVE, (void *) &on, sizeof(on)); + setsockopt(FD(c), SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on)); #if ESP32 || ESP8266 || defined(__linux__) int idle = 60; setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)); #endif #ifndef _WIN32 - setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)); - setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)); + { + int cnt = 3, intvl = 20; + setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)); + setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)); + } #endif #endif }