mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Allow channels not to close immediately after two EOFs.
Some kinds of channel, even after they've sent EOF in both directions, still have something to do before they initiate the CLOSE mechanism and wind up the channel completely. For example, a session channel with a subprocess running inside it will want to be sure to send the "exit-status" or "exit-signal" notification, even if that happens after bidirectional EOF of the data channels. Previously, the SSH-2 connection layer had the standard policy that once EOF had been both sent and received, it would start the final close procedure. There's a method chan_want_close() by which a Channel could vary this policy in one direction, by indicating that it wanted the close procedure to commence after EOF was sent in only one direction. Its parameters are a pair of booleans saying whether EOF has been sent, and whether it's been received. Now chan_want_close can vary the policy in the other direction as well: if it returns FALSE even when _both_ parameters are true, the connection layer will honour that, and not send CHANNEL_CLOSE. If it does that, the Channel is responsible for indicating when it _does_ want close later, by calling sshfwd_initiate_close.
This commit is contained in:
parent
82c83c1894
commit
d3a9142dac
2
agentf.c
2
agentf.c
@ -155,7 +155,7 @@ static const struct ChannelVtable agentf_channelvt = {
|
||||
agentf_send_eof,
|
||||
agentf_set_input_wanted,
|
||||
agentf_log_close_msg,
|
||||
chan_no_eager_close,
|
||||
chan_default_want_close,
|
||||
chan_no_exit_status,
|
||||
chan_no_exit_signal,
|
||||
chan_no_exit_signal_numeric,
|
||||
|
@ -33,7 +33,7 @@ static const struct ChannelVtable mainchan_channelvt = {
|
||||
mainchan_send_eof,
|
||||
mainchan_set_input_wanted,
|
||||
mainchan_log_close_msg,
|
||||
chan_no_eager_close,
|
||||
chan_default_want_close,
|
||||
mainchan_rcvd_exit_status,
|
||||
mainchan_rcvd_exit_signal,
|
||||
mainchan_rcvd_exit_signal_numeric,
|
||||
|
@ -450,7 +450,7 @@ static const struct ChannelVtable PortForwarding_channelvt = {
|
||||
pfd_send_eof,
|
||||
pfd_set_input_wanted,
|
||||
pfd_log_close_msg,
|
||||
chan_no_eager_close,
|
||||
chan_default_want_close,
|
||||
chan_no_exit_status,
|
||||
chan_no_exit_signal,
|
||||
chan_no_exit_signal_numeric,
|
||||
|
@ -1153,9 +1153,8 @@ static void ssh2_channel_check_close(struct ssh2_channel *c)
|
||||
return;
|
||||
}
|
||||
|
||||
if ((!((CLOSES_SENT_EOF | CLOSES_RCVD_EOF) & ~c->closes) ||
|
||||
chan_want_close(c->chan, (c->closes & CLOSES_SENT_EOF),
|
||||
(c->closes & CLOSES_RCVD_EOF))) &&
|
||||
if (chan_want_close(c->chan, (c->closes & CLOSES_SENT_EOF),
|
||||
(c->closes & CLOSES_RCVD_EOF)) &&
|
||||
!c->chanreq_head &&
|
||||
!(c->closes & CLOSES_SENT_CLOSE)) {
|
||||
/*
|
||||
|
@ -75,7 +75,7 @@ void chan_remotely_opened_failure(Channel *chan, const char *errtext);
|
||||
|
||||
/* want_close for any channel that wants the default behaviour of not
|
||||
* closing until both directions have had an EOF */
|
||||
int chan_no_eager_close(Channel *, int, int);
|
||||
int chan_default_want_close(Channel *, int, int);
|
||||
|
||||
/* default implementations that refuse all the channel requests */
|
||||
int chan_no_exit_status(Channel *, int);
|
||||
|
@ -339,9 +339,14 @@ void chan_remotely_opened_failure(Channel *chan, const char *errtext)
|
||||
assert(0 && "this channel type should never receive OPEN_FAILURE");
|
||||
}
|
||||
|
||||
int chan_no_eager_close(Channel *chan, int sent_local_eof, int rcvd_remote_eof)
|
||||
int chan_default_want_close(
|
||||
Channel *chan, int sent_local_eof, int rcvd_remote_eof)
|
||||
{
|
||||
return FALSE; /* default: never proactively ask for a close */
|
||||
/*
|
||||
* Default close policy: we start initiating the CHANNEL_CLOSE
|
||||
* procedure as soon as both sides of the channel have seen EOF.
|
||||
*/
|
||||
return sent_local_eof && rcvd_remote_eof;
|
||||
}
|
||||
|
||||
int chan_no_exit_status(Channel *chan, int status)
|
||||
|
@ -124,7 +124,7 @@ static int time_to_die = FALSE;
|
||||
* forwarding too. */
|
||||
void chan_remotely_opened_confirmation(Channel *chan) { }
|
||||
void chan_remotely_opened_failure(Channel *chan, const char *err) { }
|
||||
int chan_no_eager_close(Channel *chan, int s, int r) { return FALSE; }
|
||||
int chan_default_want_close(Channel *chan, int s, int r) { return FALSE; }
|
||||
int chan_no_exit_status(Channel *ch, int s) { return FALSE; }
|
||||
int chan_no_exit_signal(Channel *ch, ptrlen s, int c, ptrlen m)
|
||||
{ return FALSE; }
|
||||
|
Loading…
Reference in New Issue
Block a user