From fd64dc5a9952ecd1d4de5a7c8d871580f084f8c1 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 19 Apr 2012 09:41:12 +0200 Subject: [PATCH] Bugfix: Make sure timeval is valid. --- base/application.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/base/application.cpp b/base/application.cpp index 16dba4575..f7ba08925 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -79,13 +79,15 @@ void Application::RunEventLoop(void) nfds = fd; } - long sleep = (long)(Timer::GetNextCall() - time(NULL)); + time_t now = time(NULL); + time_t next = Timer::GetNextCall(); + long sleep = (next < now) ? 0 : (next - now); if (m_ShuttingDown) break; timeval tv; - tv.tv_sec = sleep; + tv.tv_sec = (sleep < 0) ? 0 : sleep; tv.tv_usec = 0; int ready;