From 1262d236e55b26ca5a32b6daf404f24c84d70f70 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 22 Sep 2023 20:08:46 +0100 Subject: [PATCH] The pollTimeout must be set to zero if less than zero. --- .../ConsoleDrivers/CursesDriver/UnixMainLoop.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index 373699071..7ffa43eea 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -175,10 +175,18 @@ namespace Terminal.Gui { if (mainLoop.timeouts.Count > 0) { pollTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond); if (pollTimeout < 0) { - // This avoids poll waiting infinitely if pollTimeout=-1 until some action is detected - if (pollTimeout == -1) { - pollTimeout = 0; - } + // This avoids 'poll' waiting infinitely if 'pollTimeout < 0' until some action is detected + // This can occur after IMainLoopDriver.Wakeup is executed where the pollTimeout is less than 0 + // and no event occurred in elapsed time when the 'poll' is start running again. + /* + The 'poll' function in the C standard library uses a signed integer as the timeout argument, where: + + - A positive value specifies a timeout in milliseconds. + - A value of 0 means the poll function will return immediately, checking for events and not waiting. + - A value of -1 means the poll function will wait indefinitely until an event occurs or an error occurs. + - A negative value other than -1 typically indicates an error. + */ + pollTimeout = 0; return true; } } else