]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - unix/uxsftp.c
Command-line options to log sessions.
[PuTTY.git] / unix / uxsftp.c
index f68685a01c32c414e0d42706c05e7d57888416c5..391da02126233abb52e59276a86d3721a9aef92f 100644 (file)
@@ -444,6 +444,7 @@ static int ssh_sftp_do_select(int include_stdin, int no_fds_ok)
     int i, fdcount, fdsize, *fdlist;
     int fd, fdstate, rwx, ret, maxfd;
     unsigned long now = GETTICKCOUNT();
+    unsigned long next;
 
     fdlist = NULL;
     fdcount = fdsize = 0;
@@ -488,12 +489,19 @@ static int ssh_sftp_do_select(int include_stdin, int no_fds_ok)
        if (include_stdin)
            FD_SET_MAX(0, maxfd, rset);
 
-       do {
-           unsigned long next, then;
-           long ticks;
-           struct timeval tv, *ptv;
+        if (toplevel_callback_pending()) {
+            struct timeval tv;
+            tv.tv_sec = 0;
+            tv.tv_usec = 0;
+            ret = select(maxfd, &rset, &wset, &xset, &tv);
+            if (ret == 0)
+                run_toplevel_callbacks();
+        } else if (run_timers(now, &next)) {
+            do {
+                unsigned long then;
+                long ticks;
+                struct timeval tv;
 
-           if (run_timers(now, &next)) {
                then = now;
                now = GETTICKCOUNT();
                if (now - then > next - then)
@@ -502,16 +510,15 @@ static int ssh_sftp_do_select(int include_stdin, int no_fds_ok)
                    ticks = next - now;
                tv.tv_sec = ticks / 1000;
                tv.tv_usec = ticks % 1000 * 1000;
-               ptv = &tv;
-           } else {
-               ptv = NULL;
-           }
-           ret = select(maxfd, &rset, &wset, &xset, ptv);
-           if (ret == 0)
-               now = next;
-           else
-               now = GETTICKCOUNT();
-       } while (ret < 0 && errno != EINTR);
+                ret = select(maxfd, &rset, &wset, &xset, &tv);
+                if (ret == 0)
+                    now = next;
+                else
+                    now = GETTICKCOUNT();
+            } while (ret < 0 && errno == EINTR);
+        } else {
+            ret = select(maxfd, &rset, &wset, &xset, NULL);
+        }
     } while (ret == 0);
 
     if (ret < 0) {
@@ -536,6 +543,8 @@ static int ssh_sftp_do_select(int include_stdin, int no_fds_ok)
 
     sfree(fdlist);
 
+    run_toplevel_callbacks();
+
     return FD_ISSET(0, &rset) ? 1 : 0;
 }
 
@@ -565,6 +574,7 @@ char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok)
        ret = ssh_sftp_do_select(TRUE, no_fds_ok);
        if (ret < 0) {
            printf("connection died\n");
+            sfree(buf);
            return NULL;               /* woop woop */
        }
        if (ret > 0) {
@@ -575,10 +585,12 @@ char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok)
            ret = read(0, buf+buflen, 1);
            if (ret < 0) {
                perror("read");
+                sfree(buf);
                return NULL;
            }
            if (ret == 0) {
                /* eof on stdin; no error, but no answer either */
+                sfree(buf);
                return NULL;
            }