From 495342c2ae85762fccec2c1e2ff427bdac773d9f Mon Sep 17 00:00:00 2001 From: Andy Green Date: Mon, 25 Sep 2017 11:54:00 +0800 Subject: [PATCH] libuv: use shadow active events mask libuv .events or .pevents in the io watcher don't seem to hold the POLLIN / POLLOUT state correctly. When POLLIN is defeated, using the rx flow control, POLLOUT seems to go away somewhere along the line when trying to OR on to the active mask. This has us track what we enabled outside in a container struct and use that for the mask instead. With this rx flow control works properly with the latest mirror using libuv (it worked fine with poll() event loop without libuv). --- lib/libuv.c | 15 ++++++++------- lib/private-libwebsockets.h | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/libuv.c b/lib/libuv.c index 0e7b734e..117037a2 100644 --- a/lib/libuv.c +++ b/lib/libuv.c @@ -338,14 +338,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.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 defined(WIN32) || defined(_WIN32) +// int current_events = w->uv_watcher.events & +// (UV_READABLE | UV_WRITABLE); +//#else + int current_events = w->actual_events & (UV_READABLE | UV_WRITABLE); +//#endif if (!LWS_LIBUV_ENABLED(context)) return; @@ -384,6 +383,8 @@ lws_libuv_io(struct lws *wsi, int flags) uv_poll_start(&w->uv_watcher, current_events, lws_io_cb); } + + w->actual_events = current_events; } int diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 0bac91e3..3b59cb96 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -696,6 +696,8 @@ struct lws_io_watcher { struct event *event_watcher; #endif struct lws_context *context; + + uint8_t actual_events; }; struct lws_signal_watcher {