[PATCH 4/5] sftp-client: split download/upload buffer sizes
Mike Frysinger
vapier at gentoo.org
Mon Nov 30 15:57:03 AEDT 2020
Now that the server will tell us its limits, we can use those to select
good upload & download sizes since they are usually very different. In
practice, the default download is still 64KiB (due to the server), but
the upload increases from 64KiB to 255KiB when using newer OpenSSH
servers.
---
sftp-client.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/sftp-client.c b/sftp-client.c
index ef3906477bd5..62397ed62503 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -83,7 +83,8 @@ extern int showprogress;
struct sftp_conn {
int fd_in;
int fd_out;
- u_int transfer_buflen;
+ u_int download_buflen;
+ u_int upload_buflen;
u_int num_requests;
u_int version;
u_int msg_id;
@@ -412,7 +413,7 @@ do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests,
ret->msg_id = 1;
ret->fd_in = fd_in;
ret->fd_out = fd_out;
- ret->transfer_buflen =
+ ret->download_buflen = ret->upload_buflen =
transfer_buflen ? transfer_buflen : DEFAULT_COPY_BUFLEN;
ret->num_requests =
num_requests ? num_requests : DEFAULT_NUM_REQUESTS;
@@ -503,14 +504,10 @@ do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests,
/* If the caller did not specify, find a good value */
if (transfer_buflen == 0) {
- /* TODO: We should have sep read & write limits */
- ret->transfer_buflen =
- MINIMUM(limits.read_length, limits.write_length);
- debug("Using smaller of server transfer limits "
- "[read:%llu, write:%llu] -> %u",
- (unsigned long long)limits.read_length,
- (unsigned long long)limits.write_length,
- ret->transfer_buflen);
+ ret->download_buflen = limits.read_length;
+ ret->upload_buflen = limits.write_length;
+ debug("Using server download size %u", ret->download_buflen);
+ debug("Using server upload size %u", ret->upload_buflen);
}
/* Use the server limit to scale down our value only */
@@ -523,15 +520,17 @@ do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests,
}
/* Some filexfer v.0 servers don't support large packets */
- if (ret->version == 0)
- ret->transfer_buflen = MINIMUM(ret->transfer_buflen, 20480);
+ if (ret->version == 0) {
+ ret->download_buflen = MINIMUM(ret->download_buflen, 20480);
+ ret->upload_buflen = MINIMUM(ret->upload_buflen, 20480);
+ }
ret->limit_kbps = limit_kbps;
if (ret->limit_kbps > 0) {
bandwidth_limit_init(&ret->bwlimit_in, ret->limit_kbps,
- ret->transfer_buflen);
+ ret->download_buflen);
bandwidth_limit_init(&ret->bwlimit_out, ret->limit_kbps,
- ret->transfer_buflen);
+ ret->upload_buflen);
}
return ret;
@@ -1326,7 +1325,7 @@ do_download(struct sftp_conn *conn, const char *remote_path,
else
size = 0;
- buflen = conn->transfer_buflen;
+ buflen = conn->download_buflen;
if ((msg = sshbuf_new()) == NULL)
fatal_f("sshbuf_new failed");
@@ -1791,7 +1790,7 @@ do_upload(struct sftp_conn *conn, const char *local_path,
}
startid = ackid = id + 1;
- data = xmalloc(conn->transfer_buflen);
+ data = xmalloc(conn->upload_buflen);
/* Read from local and write to remote */
offset = progress_counter = (resume ? c->size : 0);
@@ -1811,7 +1810,7 @@ do_upload(struct sftp_conn *conn, const char *local_path,
if (interrupted || status != SSH2_FX_OK)
len = 0;
else do
- len = read(local_fd, data, conn->transfer_buflen);
+ len = read(local_fd, data, conn->upload_buflen);
while ((len == -1) &&
(errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
--
2.28.0
More information about the openssh-unix-dev
mailing list