From 786e6dbf35fe8a9b7a3f7289f971a0721baab6bb Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 28 Apr 2017 07:51:34 +0800 Subject: [PATCH] mingw: updates --- README.build.md | 12 ++++++++++-- lib/libuv.c | 10 +++++----- lwsws/main.c | 4 ++-- plugins/protocol_lws_server_status.c | 2 +- plugins/protocol_post_demo.c | 6 +++--- test-server/test-server-http.c | 6 +++--- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/README.build.md b/README.build.md index 8cac4033..c6289530 100644 --- a/README.build.md +++ b/README.build.md @@ -176,7 +176,7 @@ cmake from scratch. 2. Fix up MinGW headers - a) Add the following lines to C:\MinGW\include\winsock2.h: + a) (32-bit) Add the following lines to C:\MinGW\include\winsock2.h: ``` #if(_WIN32_WINNT >= 0x0600) @@ -192,9 +192,17 @@ cmake from scratch. #endif // (_WIN32_WINNT >= 0x0600) ``` + + (64 bit) Update crtdefs.h line 47 to say: + +``` + typedef __int64 ssize_t; +``` + b) Create C:\MinGW\include\mstcpip.h and copy and paste the content from following link into it: - http://wine-unstable.sourcearchive.com/documentation/1.1.32/mstcpip_8h-source.html + (32-bit) http://wine-unstable.sourcearchive.com/documentation/1.1.32/mstcpip_8h-source.html + (64-bit) https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/include/mstcpip.h 3. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html diff --git a/lib/libuv.c b/lib/libuv.c index 8e377fd9..fedf403f 100644 --- a/lib/libuv.c +++ b/lib/libuv.c @@ -331,7 +331,7 @@ lws_libuv_accept(struct lws *wsi, lws_sock_file_fd_type desc) wsi->w_read.context = context; if (wsi->mode == LWSCM_RAW_FILEDESC) uv_poll_init(pt->io_loop_uv, &wsi->w_read.uv_watcher, - desc.filefd); + (int)desc.filefd); else uv_poll_init_socket(pt->io_loop_uv, &wsi->w_read.uv_watcher, desc.sockfd); @@ -571,7 +571,7 @@ lws_plat_plugins_init(struct lws_context *context, const char * const *d) goto bail; } /* we could open it, can we get his init function? */ -#if !defined(WIN32) +#if !defined(WIN32) || defined(__MINGW32__) m = lws_snprintf(path, sizeof(path) - 1, "init_%s", dent.name + 3 /* snip lib... */); path[m - 3] = '\0'; /* snip the .so */ @@ -582,7 +582,7 @@ lws_plat_plugins_init(struct lws_context *context, const char * const *d) #endif if (uv_dlsym(&lib, path, &v)) { uv_dlerror(&lib); - lwsl_err("Failed to get init on %s: %s", + lwsl_err("Failed to get %s on %s: %s", path, dent.name, lib.errmsg); goto bail; } @@ -641,7 +641,7 @@ lws_plat_plugins_destroy(struct lws_context *context) while (plugin) { p = plugin; -#if !defined(WIN32) +#if !defined(WIN32) || defined(__MINGW32__) m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s", plugin->name + 3); path[m - 3] = '\0'; #else @@ -651,7 +651,7 @@ lws_plat_plugins_destroy(struct lws_context *context) if (uv_dlsym(&plugin->lib, path, &v)) { uv_dlerror(&plugin->lib); - lwsl_err("Failed to get init on %s: %s", + lwsl_err("Failed to get %s on %s: %s", path, plugin->name, plugin->lib.errmsg); } else { func = (lws_plugin_destroy_func)v; diff --git a/lwsws/main.c b/lwsws/main.c index f23c24ac..1af5f1b2 100644 --- a/lwsws/main.c +++ b/lwsws/main.c @@ -223,7 +223,7 @@ int main(int argc, char **argv) exit(1); } } - +#ifndef _WIN32 /* * We leave our original process up permanently, because that * suits systemd. @@ -267,7 +267,7 @@ int main(int argc, char **argv) // !!! implemenation needed #endif } - +#endif /* child process */ #ifndef _WIN32 diff --git a/plugins/protocol_lws_server_status.c b/plugins/protocol_lws_server_status.c index 0b34c160..fb6d13f6 100644 --- a/plugins/protocol_lws_server_status.c +++ b/plugins/protocol_lws_server_status.c @@ -95,7 +95,7 @@ uv_timeout_cb_server_status(uv_timer_t *w l -= n; } fd = open(fp->filepath, LWS_O_RDONLY); - if (fd != LWS_INVALID_FILE) { + if (fd >= 0) { n = read(fd, contents, sizeof(contents) - 1); if (n >= 0) { contents[n] = '\0'; diff --git a/plugins/protocol_post_demo.c b/plugins/protocol_post_demo.c index bd9bef65..7560bf5a 100644 --- a/plugins/protocol_post_demo.c +++ b/plugins/protocol_post_demo.c @@ -74,7 +74,7 @@ file_upload_cb(void *data, const char *name, const char *filename, * simple demo use a fixed name so we don't have to deal with * attacks */ #if !defined(LWS_WITH_ESP8266) - pss->fd = open("/tmp/post-file", + pss->fd = (lws_filefd_type)open("/tmp/post-file", O_CREAT | O_TRUNC | O_RDWR, 0600); #endif break; @@ -88,7 +88,7 @@ file_upload_cb(void *data, const char *name, const char *filename, return 1; #if !defined(LWS_WITH_ESP8266) - n = write(pss->fd, buf, len); + n = write((int)pss->fd, buf, len); lwsl_notice("%s: write %d says %d\n", __func__, len, n); #else lwsl_notice("%s: Received chunk size %d\n", __func__, len); @@ -97,7 +97,7 @@ file_upload_cb(void *data, const char *name, const char *filename, if (state == LWS_UFS_CONTENT) break; #if !defined(LWS_WITH_ESP8266) - close(pss->fd); + close((int)pss->fd); pss->fd = LWS_INVALID_FILE; #endif break; diff --git a/test-server/test-server-http.c b/test-server/test-server-http.c index 9c122b70..eeda0f09 100644 --- a/test-server/test-server-http.c +++ b/test-server/test-server-http.c @@ -147,7 +147,7 @@ file_upload_cb(void *data, const char *name, const char *filename, /* we get the original filename in @filename arg, but for * simple demo use a fixed name so we don't have to deal with * attacks */ - pss->post_fd = open("/tmp/post-file", + pss->post_fd = (lws_filefd_type)open("/tmp/post-file", O_CREAT | O_TRUNC | O_RDWR, 0600); break; case LWS_UFS_FINAL_CONTENT: @@ -159,12 +159,12 @@ file_upload_cb(void *data, const char *name, const char *filename, if (pss->file_length > 100000) return 1; - n = write(pss->post_fd, buf, len); + n = write((int)pss->post_fd, buf, len); lwsl_notice("%s: write %d says %d\n", __func__, len, n); } if (state == LWS_UFS_CONTENT) break; - close(pss->post_fd); + close((int)pss->post_fd); pss->post_fd = LWS_INVALID_FILE; break; }