]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Factor out common parts of ssh_unthrottle and sshfwd_unthrottle.
authorBen Harris <bjh21@bjh21.me.uk>
Tue, 17 May 2016 13:57:51 +0000 (15:57 +0200)
committerBen Harris <bjh21@bjh21.me.uk>
Fri, 20 May 2016 20:33:46 +0000 (21:33 +0100)
The SSH-2 code is essentially all shared, but SSH-1 still has some
code specific to the stdout/stderr case.

ssh.c

diff --git a/ssh.c b/ssh.c
index 476518f82cc2014e7c4ab38f7270ab99c3c9656e..51605ab71533b28c751d522d52c442afb5d567d5 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -366,6 +366,7 @@ static void do_ssh2_authconn(Ssh ssh, const unsigned char *in, int inlen,
                             struct Packet *pktin);
 static void ssh2_channel_check_close(struct ssh_channel *c);
 static void ssh_channel_destroy(struct ssh_channel *c);
+static void ssh_channel_unthrottle(struct ssh_channel *c, int bufsize);
 static void ssh2_msg_something_unimplemented(Ssh ssh, struct Packet *pktin);
 
 /*
@@ -5027,21 +5028,11 @@ int sshfwd_write(struct ssh_channel *c, char *buf, int len)
 void sshfwd_unthrottle(struct ssh_channel *c, int bufsize)
 {
     Ssh ssh = c->ssh;
-    int buflimit;
 
     if (ssh->state == SSH_STATE_CLOSED)
        return;
 
-    if (ssh->version == 1) {
-       buflimit = SSH1_BUFFER_LIMIT;
-    } else {
-       buflimit = c->v.v2.locmaxwin;
-       ssh2_set_window(c, bufsize < buflimit ? buflimit - bufsize : 0);
-    }
-    if (c->throttling_conn && bufsize <= buflimit) {
-       c->throttling_conn = 0;
-       ssh_throttle_conn(ssh, -1);
-    }
+    ssh_channel_unthrottle(c, bufsize);
 }
 
 static void ssh_queueing_handler(Ssh ssh, struct Packet *pktin)
@@ -7880,6 +7871,26 @@ static struct Packet *ssh2_chanreq_init(struct ssh_channel *c,
     return pktout;
 }
 
+static void ssh_channel_unthrottle(struct ssh_channel *c, int bufsize)
+{
+    Ssh ssh = c->ssh;
+    int buflimit;
+
+    if (ssh->version == 1) {
+       buflimit = SSH1_BUFFER_LIMIT;
+    } else {
+       if (ssh_is_simple(ssh))
+           buflimit = 0;
+       else
+           buflimit = c->v.v2.locmaxwin;
+       ssh2_set_window(c, bufsize < buflimit ? buflimit - bufsize : 0);
+    }
+    if (c->throttling_conn && bufsize <= buflimit) {
+       c->throttling_conn = 0;
+       ssh_throttle_conn(ssh, -1);
+    }
+}
+
 /*
  * Potentially enlarge the window on an SSH-2 channel.
  */
@@ -11769,7 +11780,6 @@ void ssh_send_packet_from_downstream(Ssh ssh, unsigned id, int type,
 static void ssh_unthrottle(void *handle, int bufsize)
 {
     Ssh ssh = (Ssh) handle;
-    int buflimit;
 
     if (ssh->version == 1) {
        if (ssh->v1_stdout_throttling && bufsize < SSH1_BUFFER_LIMIT) {
@@ -11777,19 +11787,8 @@ static void ssh_unthrottle(void *handle, int bufsize)
            ssh_throttle_conn(ssh, -1);
        }
     } else {
-       if (ssh->mainchan) {
-           ssh2_set_window(ssh->mainchan,
-                           bufsize < ssh->mainchan->v.v2.locmaxwin ?
-                           ssh->mainchan->v.v2.locmaxwin - bufsize : 0);
-           if (ssh_is_simple(ssh))
-               buflimit = 0;
-           else
-               buflimit = ssh->mainchan->v.v2.locmaxwin;
-           if (ssh->mainchan->throttling_conn && bufsize <= buflimit) {
-               ssh->mainchan->throttling_conn = 0;
-               ssh_throttle_conn(ssh, -1);
-           }
-       }
+       if (ssh->mainchan)
+           ssh_channel_unthrottle(ssh->mainchan, bufsize);
     }
 
     /*