Accept defeat when select(2)ing without a monotonic clock
We prefer to use the monotonic clock because it's never affected by time jumps (such as the user changing the date, or the system adjusting for any other reasons, including automatic leap seconds). But if a system doesn't have a monotonic clock, we simply accept the regular, real time clock and hope it doesn't jump. This is better than the current code that never restarts a call. The side-effect is that a 30-second select may become a 3630-second select if someone sets the clock back one hour. Task-number: QTBUG-22301 Change-Id: Ia5a3bb453cd475f45b03637e2549165589fd2524 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
This commit is contained in:
parent
6dec40628b
commit
c64d602df3
@ -63,12 +63,8 @@ QT_BEGIN_NAMESPACE
|
|||||||
static inline bool time_update(struct timespec *tv, const struct timespec &start,
|
static inline bool time_update(struct timespec *tv, const struct timespec &start,
|
||||||
const struct timespec &timeout)
|
const struct timespec &timeout)
|
||||||
{
|
{
|
||||||
if (!QElapsedTimer::isMonotonic()) {
|
// clock source is (hopefully) monotonic, so we can recalculate how much timeout is left;
|
||||||
// we cannot recalculate the timeout without a monotonic clock as the time may have changed
|
// if it isn't monotonic, we'll simply hope that it hasn't jumped, because we have no alternative
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// clock source is monotonic, so we can recalculate how much timeout is left
|
|
||||||
struct timespec now = qt_gettime();
|
struct timespec now = qt_gettime();
|
||||||
*tv = timeout + start - now;
|
*tv = timeout + start - now;
|
||||||
return tv->tv_sec >= 0;
|
return tv->tv_sec >= 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user