|
|
68eb44 |
From 5c14f0e6ecfe73da86d3ad20edd60c4756037935 Mon Sep 17 00:00:00 2001
|
|
|
68eb44 |
From: Salvador <sfandino-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>
|
|
|
68eb44 |
Date: Wed, 16 Oct 2013 13:31:31 +0200
|
|
|
68eb44 |
Subject: [PATCH 09/11] _libssh2_channel_read: Honour window_size_initial
|
|
|
68eb44 |
|
|
|
68eb44 |
_libssh2_channel_read was using an arbitrary hard-coded limit to trigger
|
|
|
68eb44 |
the window adjusting code. The adjustment used was also hard-coded and
|
|
|
68eb44 |
arbitrary, 15MB actually, which would limit the usability of libssh2 on
|
|
|
68eb44 |
systems with little RAM.
|
|
|
68eb44 |
|
|
|
68eb44 |
This patch, uses the window_size parameter passed to
|
|
|
68eb44 |
libssh2_channel_open_ex (stored as remote.window_size_initial) plus the
|
|
|
68eb44 |
buflen as the base for the trigger and the adjustment calculation.
|
|
|
68eb44 |
|
|
|
68eb44 |
The memory usage when using the default window size is reduced from 22MB
|
|
|
68eb44 |
to 256KB per channel (actually, if compression is used, these numbers
|
|
|
68eb44 |
should be incremented by ~50% to account for the errors between the
|
|
|
68eb44 |
decompressed packet sizes and the predicted sizes).
|
|
|
68eb44 |
|
|
|
68eb44 |
My tests indicate that this change does not impact the performance of
|
|
|
68eb44 |
transfers across localhost or a LAN, being it on par with that of
|
|
|
68eb44 |
OpenSSH. On the other hand, it will probably slow down transfers on
|
|
|
68eb44 |
networks with high bandwidth*delay when the default window size
|
|
|
68eb44 |
(LIBSSH2_CHANNEL_WINDOW_DEFAULT=256KB) is used.
|
|
|
68eb44 |
|
|
|
68eb44 |
Signed-off-by: Salvador Fandino <sfandino@yahoo.com>
|
|
|
68eb44 |
|
|
|
68eb44 |
[upstream commit 1b3307dda0c58d9023a657747592ac86703b1ff4]
|
|
|
68eb44 |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
68eb44 |
---
|
|
|
68eb44 |
src/channel.c | 11 +++++++----
|
|
|
68eb44 |
1 files changed, 7 insertions(+), 4 deletions(-)
|
|
|
68eb44 |
|
|
|
68eb44 |
diff --git a/src/channel.c b/src/channel.c
|
|
|
68eb44 |
index 82f6980..36c75d2 100644
|
|
|
68eb44 |
--- a/src/channel.c
|
|
|
68eb44 |
+++ b/src/channel.c
|
|
|
68eb44 |
@@ -1758,14 +1758,17 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
|
|
|
68eb44 |
stream_id);
|
|
|
68eb44 |
|
|
|
68eb44 |
/* expand the receiving window first if it has become too narrow */
|
|
|
68eb44 |
- if((channel->read_state == libssh2_NB_state_jump1) ||
|
|
|
68eb44 |
- (channel->remote.window_size < (LIBSSH2_CHANNEL_WINDOW_DEFAULT*30))) {
|
|
|
68eb44 |
+ if( (channel->read_state == libssh2_NB_state_jump1) ||
|
|
|
68eb44 |
+ (channel->remote.window_size < channel->remote.window_size_initial / 4 * 3 + buflen) ) {
|
|
|
68eb44 |
+
|
|
|
68eb44 |
+ uint32_t adjustment = channel->remote.window_size_initial + buflen - channel->remote.window_size;
|
|
|
68eb44 |
+ if (adjustment < LIBSSH2_CHANNEL_MINADJUST)
|
|
|
68eb44 |
+ adjustment = LIBSSH2_CHANNEL_MINADJUST;
|
|
|
68eb44 |
|
|
|
68eb44 |
/* the actual window adjusting may not finish so we need to deal with
|
|
|
68eb44 |
this special state here */
|
|
|
68eb44 |
channel->read_state = libssh2_NB_state_jump1;
|
|
|
68eb44 |
- rc = _libssh2_channel_receive_window_adjust(channel,
|
|
|
68eb44 |
- (LIBSSH2_CHANNEL_WINDOW_DEFAULT*60),
|
|
|
68eb44 |
+ rc = _libssh2_channel_receive_window_adjust(channel, adjustment,
|
|
|
68eb44 |
0, NULL);
|
|
|
68eb44 |
if (rc)
|
|
|
68eb44 |
return rc;
|
|
|
68eb44 |
--
|
|
|
68eb44 |
1.7.1
|
|
|
68eb44 |
|