From 5c42f97b68aa843693088d398ced48d03922ed9a Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 9 Apr 2016 00:24:12 +0100 Subject: [PATCH] Switch to flow-control-based SFTP uploading. 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 | 4 ++++ psftp.c | 4 ++++ sftp.c | 2 +- sftp.h | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pscp.c b/pscp.c index f6f6c206..9ea423fd 100644 --- 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 784c81b1..a718b794 100644 --- 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 b4421f77..591b60ba 100644 --- 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 c61340c1..309845b0 100644 --- a/sftp.h +++ b/sftp.h @@ -63,8 +63,12 @@ * 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); /* -- 2.45.2