Another tweak to EOF policy: invent an outgoing EOF on receipt of an
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 14 Sep 2011 09:09:35 +0000 (09:09 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 14 Sep 2011 09:09:35 +0000 (09:09 +0000)
incoming CHANNEL_CLOSE, if it's the main session channel. The idea is
that invocations such as 'plink -T hostname sh' (running a shell
without a remote pty) can be exited by typing 'exit' to the remote
shell, without plink blocking forever waiting for outgoing EOF.

I think it would be better to do the same for all other channel types
too, but that would need an extra API call which I haven't
implemented yet.

git-svn-id: svn://svn.tartarus.org/sgt/putty@9283 cda61777-01e9-0310-a592-d414129be87e

ssh.c

diff --git a/ssh.c b/ssh.c
index a211213..eee792b 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -6978,6 +6978,24 @@ static void ssh2_msg_channel_close(Ssh ssh, struct Packet *pktin)
     ssh2_channel_got_eof(c);
 
     /*
+     * And we also send an outgoing EOF, if we haven't already, on the
+     * assumption that CLOSE is a pretty forceful announcement that
+     * the remote side is doing away with the entire channel. (If it
+     * had wanted to send us EOF and continue receiving data from us,
+     * it would have just sent CHANNEL_EOF.)
+     *
+     * For the moment, this policy applies to the main session channel
+     * only, because we have a convenient mechanism (ssh->send_ok) for
+     * ceasing to read from our local data source. Ideally I think
+     * we'd do this for auxiliary channels too, which would need an
+     * extra API call in the forwarding modules.
+     */
+    if (c->type == CHAN_MAINSESSION && !(c->closes & CLOSES_SENT_EOF)) {
+        sshfwd_write_eof(ssh->mainchan);
+        ssh->send_ok = 0;          /* now stop trying to read from stdin */
+    }
+
+    /*
      * Now process the actual close.
      */
     if (!(c->closes & CLOSES_RCVD_CLOSE)) {