int got_some_output = -1;
ptrdiff_t count = SPECPDL_INDEX ();
+ /* Close to the current time if known, an invalid timespec otherwise. */
+ struct timespec now = invalid_timespec ();
+
FD_ZERO (&Available);
FD_ZERO (&Writeok);
else if (time_limit > 0 || nsecs > 0)
{
wait = TIMEOUT;
- end_time = timespec_add (current_timespec (),
- make_timespec (time_limit, nsecs));
+ now = current_timespec ();
+ end_time = timespec_add (now, make_timespec (time_limit, nsecs));
}
else
wait = INFINITY;
/* Exit if already run out. */
if (wait == TIMEOUT)
{
- struct timespec now = current_timespec ();
+ if (!timespec_valid_p (now))
+ now = current_timespec ();
if (timespec_cmp (end_time, now) <= 0)
break;
timeout = timespec_sub (end_time, now);
}
else
{
-
/* Set the timeout for adaptive read buffering if any
process has non-zero read_output_skip and non-zero
read_output_delay, and we are not reading output for a
&& timespec_valid_p (timer_delay)
&& timespec_cmp (timer_delay, timeout) < 0)
{
- struct timespec timeout_abs = timespec_add (current_timespec (),
- timeout);
+ if (!timespec_valid_p (now))
+ now = current_timespec ();
+ struct timespec timeout_abs = timespec_add (now, timeout);
if (!timespec_valid_p (got_output_end_time)
- || timespec_cmp (timeout_abs,
- got_output_end_time) < 0)
+ || timespec_cmp (timeout_abs, got_output_end_time) < 0)
got_output_end_time = timeout_abs;
timeout = timer_delay;
}
else
got_output_end_time = invalid_timespec ();
+ /* NOW can become inaccurate if time can pass during pselect. */
+ if (timeout.tv_sec > 0 || timeout.tv_nsec > 0)
+ now = invalid_timespec ();
+
#if defined (HAVE_NS)
nfds = ns_select
#elif defined (HAVE_GLIB)
haven't lowered our timeout due to timers or SIGIO and
have waited a long amount of time due to repeated
timers. */
- struct timespec now = current_timespec ();
- if (wait < TIMEOUT
- || (wait == TIMEOUT && timespec_cmp (end_time, now) <= 0)
- || (!process_skipped && got_some_output > 0
- && (!timespec_valid_p (got_output_end_time)
- || timespec_cmp (got_output_end_time, now) <= 0)
- && (timeout.tv_sec > 0 || timeout.tv_nsec > 0)))
+ if (wait < TIMEOUT)
break;
+ struct timespec cmp_time
+ = (wait == TIMEOUT
+ ? end_time
+ : (!process_skipped && got_some_output > 0
+ && (timeout.tv_sec > 0 || timeout.tv_nsec > 0))
+ ? got_output_end_time
+ : invalid_timespec ());
+ if (timespec_valid_p (cmp_time))
+ {
+ now = current_timespec ();
+ if (timespec_cmp (cmp_time, now) <= 0)
+ break;
+ }
}
if (nfds < 0)