]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Switch to flow-control-based SFTP uploading.
authorBen Harris <bjh21@bjh21.me.uk>
Fri, 8 Apr 2016 23:24:12 +0000 (00:24 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sat, 9 Apr 2016 16:20:07 +0000 (17:20 +0100)
Formerly PuTTY's SFTP code would transmit (or buffer) a megabyte of data
before even starting to look for acknowledgements, but wouldn't allow
there to be more than a megabyte of unacknowledged data at a time.  Now,
instead, it pays attention to whether the transmit path is blocked, and
transmits iff it isn't.

This should mean that SFTP goes faster over long fat pipes, and also
doesn't end up buffering so much over thin ones.

I practice, I tend to run into other performance limitations (such as
TCP or SSH-2 windows) before this enhancement looks particularly good,
but with an artificial lag of 250 ms on the loopback interface this
patch almost doubles my upload speed, so I think it's worthwhile.

pscp.c
psftp.c
sftp.c
sftp.h

diff --git a/pscp.c b/pscp.c
index f6f6c206b6fad363eac57d9a17aa1bf7b8b29342..9ea423fd00d1f7ddcf29092fca626f1758d7d5bb 100644 (file)
--- a/pscp.c
+++ b/pscp.c
@@ -658,6 +658,10 @@ int sftp_senddata(char *buf, int len)
     back->send(backhandle, buf, len);
     return 1;
 }
+int sftp_sendbuffer(void)
+{
+    return back->sendbuffer(backhandle);
+}
 
 /* ----------------------------------------------------------------------
  * sftp-based replacement for the hacky `pscp -ls'.
diff --git a/psftp.c b/psftp.c
index 784c81b1b88242871f5b76cd679f32adcbd757b1..a718b794dc779ee87b36958891e0188f29e816ee 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -2618,6 +2618,10 @@ int sftp_senddata(char *buf, int len)
     back->send(backhandle, buf, len);
     return 1;
 }
+int sftp_sendbuffer(void)
+{
+    return back->sendbuffer(backhandle);
+}
 
 /*
  *  Short description of parameters.
diff --git a/sftp.c b/sftp.c
index b4421f779e41dd56085bf5c840defa9594e78948..591b60ba1f0d1cf15ed814d11cfc0ee5adec04e0 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -1349,7 +1349,7 @@ struct fxp_xfer *xfer_upload_init(struct fxp_handle *fh, uint64 offset)
 
 int xfer_upload_ready(struct fxp_xfer *xfer)
 {
-    if (xfer->req_totalsize < xfer->req_maxsize)
+    if (sftp_sendbuffer() == 0)
        return 1;
     else
        return 0;
diff --git a/sftp.h b/sftp.h
index c61340c1582273b9e8e723b60f56b2eeeb548e44..309845b0847325ec9e8a0ce6b92a97f0069e428a 100644 (file)
--- a/sftp.h
+++ b/sftp.h
  * until len is available, or it returns failure.
  * 
  * Both functions return 1 on success, 0 on failure.
+ *
+ * sftp_sendbuffer returns the size of the backlog of data in the
+ * transmit queue.
  */
 int sftp_senddata(char *data, int len);
+int sftp_sendbuffer(void);
 int sftp_recvdata(char *data, int len);
 
 /*