X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=unix%2Fuxplink.c;h=c0261578eb2b7e1727305adfe724a8c5fafc8fc5;hb=d0beed9aba20865b9829e3203b4067e8822a0f4d;hp=6bc1b61b188917e02683252792f750c435e4707d;hpb=2daa1b737c9f2c8ac70de0aa8662aac7a33f281b;p=PuTTY.git diff --git a/unix/uxplink.c b/unix/uxplink.c index 6bc1b61b..c0261578 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -670,8 +670,27 @@ int main(int argc, char **argv) ret = select(maxfd, &rset, &wset, &xset, ptv); if (ret == 0) now = next; - else - now = GETTICKCOUNT(); + else { + long newnow = GETTICKCOUNT(); + /* + * Check to see whether the system clock has + * changed massively during the select. + */ + if (newnow - now < 0 || newnow - now > next - now) { + /* + * If so, look at the elapsed time in the + * select and use it to compute a new + * tickcount_offset. + */ + long othernow = now + tv.tv_sec * 1000 + tv.tv_usec / 1000; + /* So we'd like GETTICKCOUNT to have returned othernow, + * but instead it return newnow. Hence ... */ + tickcount_offset += othernow - newnow; + now = othernow; + } else { + now = newnow; + } + } } while (ret < 0 && errno == EINTR); if (ret < 0) {