From bbcd24167f88bb414e7ac6f030ddd566583cf305 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 31 Mar 2016 20:11:53 +0800 Subject: [PATCH] libuv win32 fixes Signed-off-by: Andy Green --- CMakeLists.txt | 4 ++-- lib/libuv.c | 13 +++++++++++-- lib/private-libwebsockets.h | 6 ++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91eba67..f45a70e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -955,7 +955,7 @@ if (NOT LWS_WITHOUT_TESTAPPS) "test-server/test-server-status.c" "test-server/test-server-echogen.c") endif() - if (UNIX AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND LWS_WITH_LIBEV) create_test_app(test-server-libev "test-server/test-server-libev.c" @@ -965,7 +965,7 @@ if (NOT LWS_WITHOUT_TESTAPPS) "test-server/test-server-status.c" "test-server/test-server-echogen.c") endif() - if (UNIX AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND LWS_WITH_LIBUV) create_test_app(test-server-libuv "test-server/test-server-libuv.c" diff --git a/lib/libuv.c b/lib/libuv.c index e74e81d..dfd4c52 100644 --- a/lib/libuv.c +++ b/lib/libuv.c @@ -38,7 +38,11 @@ lws_io_cb(uv_poll_t *watcher, int status, int revents) struct lws_context *context = lws_io->context; struct lws_pollfd eventfd; +#if defined(WIN32) || defined(_WIN32) + eventfd.fd = watcher->sock; +#else eventfd.fd = watcher->io_watcher.fd; +#endif eventfd.events = 0; eventfd.revents = 0; @@ -207,8 +211,13 @@ lws_libuv_io(struct lws *wsi, int flags) { struct lws_context *context = lws_get_context(wsi); struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; +#if defined(WIN32) || defined(_WIN32) + int current_events = wsi->w_read.uv_watcher.io.events & + (UV_READABLE | UV_WRITABLE); +#else int current_events = wsi->w_read.uv_watcher.io_watcher.pevents & (UV_READABLE | UV_WRITABLE); +#endif struct lws_io_watcher *w = &wsi->w_read; if (!LWS_LIBUV_ENABLED(context)) @@ -329,8 +338,8 @@ lws_uv_getloop(struct lws_context *context, int tsi) static void lws_libuv_closewsi(uv_handle_t* handle) { - struct lws *n = NULL, *wsi = (struct lws *)(((void *)handle) - - (void *)(&n->w_read.uv_watcher)); + struct lws *n = NULL, *wsi = (struct lws *)(((char *)handle) - + (char *)(&n->w_read.uv_watcher)); struct lws_context *context = lws_get_context(wsi); lws_close_free_wsi_final(wsi); diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 580e1e7..04d1a89 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -261,6 +261,12 @@ typedef unsigned __int64 u_int64_t; #endif #endif +#include + +#ifndef container_of +#define container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M))) +#endif + #else #include -- 2.7.4