Blame SOURCES/0009-_libssh2_channel_read-Honour-window_size_initial.patch

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