From 42d7865e147abc99249b3ee15ccab36a250ef340 Mon Sep 17 00:00:00 2001 From: cpq Date: Thu, 10 Dec 2020 17:39:40 +0000 Subject: [PATCH] Pre-built desktop server --- Makefile | 2 +- examples/desktop-server/Makefile | 30 +++++++++++++++++++++ examples/{minimal => desktop-server}/main.c | 0 examples/minimal/Makefile | 10 ------- mongoose.c | 6 +++-- src/http.c | 2 +- 6 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 examples/desktop-server/Makefile rename examples/{minimal => desktop-server}/main.c (100%) delete mode 100644 examples/minimal/Makefile diff --git a/Makefile b/Makefile index 401b3900..afd5446b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SRCS = $(wildcard src/*.c) HDRS = $(wildcard src/*.h) -DEFS ?= -DMG_MAX_HTTP_HEADERS=5 -DMG_ENABLE_LINES -DMG_ENABLE_HTTP_DEBUG_ENDPOINT=1 +DEFS ?= -DMG_MAX_HTTP_HEADERS=5 -DMG_ENABLE_LINES -DMG_ENABLE_HTTP_DEBUG_ENDPOINT=1 -DMG_ENABLE_DIRECTORY_LISTING=1 CFLAGS ?= -W -Wall -Werror -Isrc -I. -O0 -g $(DEFS) $(TFLAGS) $(EXTRA) SSL ?= MBEDTLS CDIR ?= $(realpath $(CURDIR)) diff --git a/examples/desktop-server/Makefile b/examples/desktop-server/Makefile new file mode 100644 index 00000000..632710f2 --- /dev/null +++ b/examples/desktop-server/Makefile @@ -0,0 +1,30 @@ +PROG ?= example +ROOT ?= $(realpath $(CURDIR)/../..) +DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_DIRECTORY_LISTING=1 +CFLAGS ?= -I../.. -W -Wall -DMG_ENABLE_IPV6=1 $(DEFS) $(EXTRA) +VCFLAGS = /nologo /W3 /O2 /I../.. $(DEFS) $(EXTRA) +VC98 = docker run --rm -e WINEDEBUG=-all -v $(ROOT):$(ROOT) -w $(CURDIR) docker.io/mdashnet/vc98 +GCC = docker run --rm -v $(ROOT):$(ROOT) -w $(CURDIR) mdashnet/cc2 + +all: $(PROG) + $(DEBUGGER) ./$(PROG) + +$(PROG): + $(CC) ../../mongoose.c main.c -I../.. $(CFLAGS) $(EXTRA) -o $@ + +mongoose_mac: $(PROG) + cp $(PROG) $@ + +mongoose_linux: main.c + $(GCC) $(CC) ../../mongoose.c main.c $(CFLAGS) -o $@ + +mongoose.exe: main.c + $(VC98) wine cl ../../mongoose.c main.c $(VCFLAGS) ws2_32.lib /Fe$@ + +zip: mongoose.exe mongoose_linux mongoose_mac + rm -rf mongoose; mkdir mongoose + cp mongoose.exe mongoose_mac mongoose_linux mongoose + zip -r mongoose.zip mongoose + +clean: + rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb mongoose mongoose_* mongoose.* diff --git a/examples/minimal/main.c b/examples/desktop-server/main.c similarity index 100% rename from examples/minimal/main.c rename to examples/desktop-server/main.c diff --git a/examples/minimal/Makefile b/examples/minimal/Makefile deleted file mode 100644 index 09ac5f8c..00000000 --- a/examples/minimal/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -PROG ?= example - -all: $(PROG) - $(DEBUGGER) ./$(PROG) $(ARGS) - -$(PROG): main.c - $(CC) ../../mongoose.c -I../.. -W -Wall -DMG_ENABLE_LINES=1 -DMG_ENABLE_DIRECTORY_LISTING=1 $(CFLAGS) -o $(PROG) main.c - -clean: - rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb diff --git a/mongoose.c b/mongoose.c index 10576ac0..057dba35 100644 --- a/mongoose.c +++ b/mongoose.c @@ -733,7 +733,7 @@ int gettimeofday(struct timeval *tv, void *tz) { tmpres <<= 32; tmpres |= ft.dwLowDateTime; tmpres /= 10; // convert into microseconds - tmpres -= 11644473600000000ULL; + tmpres -= (int64_t) 11644473600000000; tv->tv_sec = (long) (tmpres / 1000000UL); tv->tv_usec = (long) (tmpres % 1000000UL); } @@ -1051,7 +1051,9 @@ struct mg_connection *mg_http_listen(struct mg_mgr *mgr, const char *url, void mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) { if (new_size == 0) { - mg_iobuf_free(io); + free(io->buf); + io->buf = NULL; + io->len = io->size = 0; } else if (new_size != io->size) { // NOTE(lsm): do not use realloc here. Use malloc/free only, to ease the // porting to some obscure platforms like FreeRTOS diff --git a/src/http.c b/src/http.c index 4f5a1f1c..9f5254dc 100644 --- a/src/http.c +++ b/src/http.c @@ -373,7 +373,7 @@ int gettimeofday(struct timeval *tv, void *tz) { tmpres <<= 32; tmpres |= ft.dwLowDateTime; tmpres /= 10; // convert into microseconds - tmpres -= 11644473600000000ULL; + tmpres -= (int64_t) 11644473600000000; tv->tv_sec = (long) (tmpres / 1000000UL); tv->tv_usec = (long) (tmpres % 1000000UL); }