Two related changes to timing code:
[sgt/putty] / unix / uxsftp.c
index a92cfc9..f68685a 100644 (file)
@@ -443,7 +443,7 @@ static int ssh_sftp_do_select(int include_stdin, int no_fds_ok)
     fd_set rset, wset, xset;
     int i, fdcount, fdsize, *fdlist;
     int fd, fdstate, rwx, ret, maxfd;
-    long now = GETTICKCOUNT();
+    unsigned long now = GETTICKCOUNT();
 
     fdlist = NULL;
     fdcount = fdsize = 0;
@@ -489,13 +489,17 @@ static int ssh_sftp_do_select(int include_stdin, int no_fds_ok)
            FD_SET_MAX(0, maxfd, rset);
 
        do {
-           long next, ticks;
+           unsigned long next, then;
+           long ticks;
            struct timeval tv, *ptv;
 
            if (run_timers(now, &next)) {
-               ticks = next - GETTICKCOUNT();
-               if (ticks <= 0)
-                   ticks = 1;         /* just in case */
+               then = now;
+               now = GETTICKCOUNT();
+               if (now - then > next - then)
+                   ticks = 0;
+               else
+                   ticks = next - now;
                tv.tv_sec = ticks / 1000;
                tv.tv_usec = ticks % 1000 * 1000;
                ptv = &tv;