From 5fb327754ab4d202fca903dd5bd6b546b340eecb Mon Sep 17 00:00:00 2001 From: Andy Green Date: Mon, 10 Oct 2016 23:21:48 +0800 Subject: [PATCH] adjust_timeout: with default lws_plat_service_tsi allow beings passed 0 timeout Some people are calling service with zero timeout, taking care of not busywaiting by some other external arrangements. Adapt the forced service signalling to survive this. --- lib/lws-plat-unix.c | 11 ++++------- lib/lws-plat-win.c | 13 +++++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/lws-plat-unix.c b/lib/lws-plat-unix.c index 2c6cfcd4..f228e332 100644 --- a/lib/lws-plat-unix.c +++ b/lib/lws-plat-unix.c @@ -130,19 +130,16 @@ lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) } context->service_tid = context->service_tid_detected; - timeout_ms = lws_service_adjust_timeout(context, timeout_ms, tsi); /* * is there anybody with pending stuff that needs service forcing? */ - if (!timeout_ms) { + if (!lws_service_adjust_timeout(context, 1, tsi)) { /* -1 timeout means just do forced service */ lws_plat_service_tsi(context, -1, pt->tid); /* still somebody left who wants forced service? */ - if (!lws_service_adjust_timeout(context, 1, pt->tid)) { - /* yes... come back again later */ - //lwsl_debug("%s: done again\n", __func__); - } - return 0; + if (!lws_service_adjust_timeout(context, 1, pt->tid)) + /* yes... come back again quickly */ + timeout_ms = 0; } n = poll(pt->fds, pt->fds_count, timeout_ms); diff --git a/lib/lws-plat-win.c b/lib/lws-plat-win.c index be7d577c..180ed467 100644 --- a/lib/lws-plat-win.c +++ b/lib/lws-plat-win.c @@ -212,8 +212,17 @@ lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) i--; } - /* if we know something needs service already, don't wait in poll */ - timeout_ms = lws_service_adjust_timeout(context, timeout_ms, tsi); + /* + * is there anybody with pending stuff that needs service forcing? + */ + if (!lws_service_adjust_timeout(context, 1, tsi)) { + /* -1 timeout means just do forced service */ + lws_plat_service_tsi(context, -1, pt->tid); + /* still somebody left who wants forced service? */ + if (!lws_service_adjust_timeout(context, 1, pt->tid)) + /* yes... come back again quickly */ + timeout_ms = 0; + } ev = WSAWaitForMultipleEvents( 1, pt->events , FALSE, timeout_ms, FALSE); if (ev == WSA_WAIT_EVENT_0) {