From 96a8c95b81133a8b6f1bf09d76566b45594e0159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 15 Jun 2016 22:17:34 +0200 Subject: [PATCH] Properly round event timeout for the epoll driver. Avoids continuous 0 msec timeouts just before timers expire. --- source/eventcore/drivers/epoll.d | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/eventcore/drivers/epoll.d b/source/eventcore/drivers/epoll.d index 99718a4..baa8d41 100644 --- a/source/eventcore/drivers/epoll.d +++ b/source/eventcore/drivers/epoll.d @@ -34,11 +34,12 @@ final class EpollEventDriver : PosixEventDriver { import std.algorithm : min; //assert(Fiber.getThis() is null, "processEvents may not be called from within a fiber!"); - auto ts = timeout.toTimeVal; - //print("wait %s", m_events.length); - auto ret = epoll_wait(m_epoll, m_events.ptr, cast(int)m_events.length, timeout == Duration.max ? -1 : cast(int)min(timeout.total!"msecs", int.max)); - //print("wait done %s", ret); + long tomsec; + if (timeout == Duration.max) tomsec = long.max; + else tomsec = (timeout.total!"hnsecs" + 9999) / 10_000; + auto ret = epoll_wait(m_epoll, m_events.ptr, cast(int)m_events.length, tomsec > int.max ? -1 : cast(int)tomsec); + print("wait done %s", ret); if (ret > 0) { foreach (ref evt; m_events[0 .. ret]) {