Reformat channel_protocol_select().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@705 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-05-04 10:26:30 +00:00
parent 1afe6b13c5
commit cd71590fe0

View File

@@ -1647,50 +1647,60 @@ int channel_get_exit_status(CHANNEL *channel) {
return channel->exit_status; return channel->exit_status;
} }
/* This function acts as a meta select. */ /*
/* first, channels are analyzed to seek potential can-write or can-read ones. */ * This function acts as a meta select.
/* Then, if no channel has been elected, it goes in a loop with the posix select(2) */ *
/* this is made in two parts : Protocol select and Network select */ * First, channels are analyzed to seek potential can-write or can-read ones,
* then if no channel has been elected, it goes in a loop with the posix
/* the protocol select does not use the network functions at all */ * select(2).
* This is made in two parts: protocol select and network select. The protocol
static int channel_protocol_select(CHANNEL **rchans, CHANNEL **wchans, CHANNEL **echans, * select does not use the network functions at all
CHANNEL **rout, CHANNEL **wout, CHANNEL **eout){ */
static int channel_protocol_select(CHANNEL **rchans, CHANNEL **wchans,
CHANNEL **echans, CHANNEL **rout, CHANNEL **wout, CHANNEL **eout) {
CHANNEL *chan; CHANNEL *chan;
int i,j; int i;
j=0; int j = 0;
for(i=0;rchans[i];++i){
for (i = 0; rchans[i] != NULL; i++) {
chan = rchans[i]; chan = rchans[i];
while (chan->open && ssh_socket_data_available(chan->session->socket)) { while (chan->open && ssh_socket_data_available(chan->session->socket)) {
ssh_handle_packets(chan->session); ssh_handle_packets(chan->session);
} }
if ((chan->stdout_buffer && buffer_get_len(chan->stdout_buffer) > 0) || if ((chan->stdout_buffer && buffer_get_len(chan->stdout_buffer) > 0) ||
(chan->stderr_buffer && buffer_get_len(chan->stderr_buffer) > 0) || (chan->stderr_buffer && buffer_get_len(chan->stderr_buffer) > 0) ||
chan->remote_eof) { chan->remote_eof) {
rout[j] = chan; rout[j] = chan;
++j; j++;
} }
} }
rout[j] = NULL; rout[j] = NULL;
j = 0; j = 0;
for(i=0;wchans[i];++i){ for(i = 0; wchans[i] != NULL; i++) {
chan = wchans[i]; chan = wchans[i];
/* it's not our business to seek if the file descriptor is writable */ /* It's not our business to seek if the file descriptor is writable */
if(ssh_socket_data_writable(chan->session->socket) && chan->open && (chan->remote_window>0)){ if (ssh_socket_data_writable(chan->session->socket) &&
chan->open && (chan->remote_window > 0)) {
wout[j] = chan; wout[j] = chan;
++j; j++;
} }
} }
wout[j] = NULL; wout[j] = NULL;
j = 0; j = 0;
for(i=0;echans[i];++i){ for (i = 0; echans[i] != NULL; i++) {
chan = echans[i]; chan = echans[i];
if (!ssh_socket_is_open(chan->session->socket) || !chan->open) { if (!ssh_socket_is_open(chan->session->socket) || !chan->open) {
eout[j] = chan; eout[j] = chan;
++j; j++;
} }
} }
eout[j] = NULL; eout[j] = NULL;
return 0; return 0;
} }