Improve channel_rcv_close().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@680 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-05-03 17:54:16 +00:00
parent 2b705786c0
commit e7fc9ab369

View File

@@ -425,30 +425,42 @@ static void channel_rcv_eof(SSH_SESSION *session) {
leave_function(); leave_function();
} }
static void channel_rcv_close(SSH_SESSION *session){ static void channel_rcv_close(SSH_SESSION *session) {
CHANNEL *channel; CHANNEL *channel;
enter_function(); enter_function();
channel=channel_from_msg(session);
if(!channel){ channel = channel_from_msg(session);
ssh_log(session, SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session)); if (channel == NULL) {
ssh_log(session, SSH_LOG_FUNCTIONS, ssh_get_error(session));
leave_function(); leave_function();
return; return;
} }
ssh_log(session, SSH_LOG_PACKET, ssh_log(session, SSH_LOG_PACKET,
"Received close on channel (%d:%d)", "Received close on channel (%d:%d)",
channel->local_channel, channel->local_channel,
channel->remote_channel); channel->remote_channel);
if((channel->stdout_buffer && buffer_get_rest_len(channel->stdout_buffer)>0)
|| (channel->stderr_buffer && buffer_get_rest_len(channel->stderr_buffer)>0)) if ((channel->stdout_buffer &&
channel->delayed_close=1; buffer_get_rest_len(channel->stdout_buffer) > 0) ||
else (channel->stderr_buffer &&
channel->open=0; buffer_get_rest_len(channel->stderr_buffer) > 0)) {
if(!channel->remote_eof) channel->delayed_close = 1;
} else {
channel->open = 0;
}
if (channel->remote_eof == 0) {
ssh_log(session, SSH_LOG_PACKET, ssh_log(session, SSH_LOG_PACKET,
"Remote host not polite enough to send an eof before close"); "Remote host not polite enough to send an eof before close");
channel->remote_eof=1; }
/* the remote eof doesn't break things if there was still data into read channel->remote_eof = 1;
* buffer because the eof is ignored until the buffer is empty. */ /*
* The remote eof doesn't break things if there was still data into read
* buffer because the eof is ignored until the buffer is empty.
*/
leave_function(); leave_function();
} }