From 9b9504d925e1426893f115d5a5d945259e158a14 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Tue, 8 Jan 2019 03:01:54 +0100 Subject: [PATCH] windows/waitable: Allow a timeout of 0 --- source/windows/waitable.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/source/windows/waitable.cpp b/source/windows/waitable.cpp index a1e89e6..8754911 100644 --- a/source/windows/waitable.cpp +++ b/source/windows/waitable.cpp @@ -51,10 +51,15 @@ datapath::error datapath::waitable::wait(datapath::waitable* obj, std::chrono::n return datapath::error::Closed; case WAIT_IO_COMPLETION: duration = (std::chrono::high_resolution_clock::now() - start); - timeout = std::chrono::duration_cast(duration).count(); + timeout -= std::chrono::duration_cast(duration).count(); + if (timeout <= 0) { + timeout = 0; + } continue; + default: + return datapath::error::Failure; } - } while (timeout > 0); + } while (timeout >= 0); return datapath::error::TimedOut; } @@ -103,10 +108,15 @@ datapath::error datapath::waitable::wait(datapath::waitable** objs, size_t count return datapath::error::TimedOut; } else if (result == WAIT_IO_COMPLETION) { duration = (std::chrono::high_resolution_clock::now() - start); - timeout = std::chrono::duration_cast(duration).count(); + timeout -= std::chrono::duration_cast(duration).count(); + if (timeout <= 0) { + timeout = 0; + } continue; + } else { + return datapath::error::Failure; } - } while (timeout > 0); + } while (timeout >= 0); return datapath::error::TimedOut; } @@ -154,10 +164,15 @@ datapath::error datapath::waitable::wait_any(datapath::waitable** objs, size_t c return datapath::error::TimedOut; } else if (result == WAIT_IO_COMPLETION) { duration = (std::chrono::high_resolution_clock::now() - start); - timeout = std::chrono::duration_cast(duration).count(); + timeout -= std::chrono::duration_cast(duration).count(); + if (timeout <= 0) { + timeout = 0; + } continue; + } else { + return datapath::error::Failure; } - } while (timeout > 0); + } while (timeout >= 0); return datapath::error::TimedOut; }