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){
chan=rchans[i]; for (i = 0; rchans[i] != NULL; i++) {
while(chan->open && ssh_socket_data_available(chan->session->socket)){ chan = rchans[i];
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) ||
(chan->stderr_buffer && buffer_get_len(chan->stderr_buffer)>0) || if ((chan->stdout_buffer && buffer_get_len(chan->stdout_buffer) > 0) ||
chan->remote_eof){ (chan->stderr_buffer && buffer_get_len(chan->stderr_buffer) > 0) ||
rout[j]=chan; chan->remote_eof) {
++j; rout[j] = chan;
j++;
} }
} }
rout[j]=NULL; rout[j] = NULL;
j=0;
for(i=0;wchans[i];++i){ j = 0;
chan=wchans[i]; for(i = 0; wchans[i] != NULL; i++) {
/* it's not our business to seek if the file descriptor is writable */ chan = wchans[i];
if(ssh_socket_data_writable(chan->session->socket) && chan->open && (chan->remote_window>0)){ /* It's not our business to seek if the file descriptor is writable */
wout[j]=chan; if (ssh_socket_data_writable(chan->session->socket) &&
++j; chan->open && (chan->remote_window > 0)) {
wout[j] = chan;
j++;
} }
} }
wout[j]=NULL; wout[j] = NULL;
j=0;
for(i=0;echans[i];++i){ j = 0;
chan=echans[i]; for (i = 0; echans[i] != NULL; i++) {
if(!ssh_socket_is_open(chan->session->socket) || !chan->open){ chan = echans[i];
eout[j]=chan;
++j; if (!ssh_socket_is_open(chan->session->socket) || !chan->open) {
eout[j] = chan;
j++;
} }
} }
eout[j]=NULL; eout[j] = NULL;
return 0; return 0;
} }