Subject: bug#50043: 28.0.50; USABLE_SIGOI undef code paths do not work correctly

From: Ken Brown <[email-masked]>
Date: Wed, 17 Nov 2021 09:59:35 -0500

On 11/17/2021 9:34 AM, Eli Zaretskii wrote:
>> Date: Wed, 17 Nov 2021 09:19:27 -0500
>> Cc: [email-masked], [email-masked]
>> From: Ken Brown <[email-masked]>
>>
>>> What is that more general problem, and when does it rear its ugly
>>> head?
>>
>> The problem is that whenever wait_reading_process_output needs to repeatedly
>> check for input (i.e., read_kbd || !NILP (wait_for_cell) == true), it can get
>> stuck in select for up to 2 seconds on systems without USABLE_SIGIO.  (2 arises
>> here because it's the default value of polling-period.)
> 
> But that can only happen if select is called with a long enough
> timeout, right?

Right.

> Anyway, if the problem is that on these systems select doesn't return
> when there are input events waiting, I guess it's okay to do the
> change there.

Thanks.

> But maybe it will be better to do it the same way we
> decrease the timeout when a timer is expected to expire before the
> timeout: we decrease the timeout, but still remember its value, and
> don't return from waiting before the timeout unless there really was
> some input.  This would avoid affecting unrelated features such as
> accept-process-output.

I think that's already taken care of.  The timeout is recalculated on each 
iteration of the main while loop:

       /* Compute time from now till when time limit is up.  */
       /* Exit if already run out.  */
       if (wait == TIMEOUT)
	{
	  if (!timespec_valid_p (now))
	    now = current_timespec ();
	  if (timespec_cmp (end_time, now) <= 0)
	    break;
	  timeout = timespec_sub (end_time, now);
	}
       else
	timeout = make_timespec (wait < TIMEOUT ? 0 : 100000, 0);

My reduction of timeout to 25 msec occurs after this.

Ken