diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2005-08-31 02:20:36 +0000 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2005-08-31 02:20:36 +0000 |
commit | 1b20b8df85e07353f8403a6b55f8206980228639 (patch) | |
tree | dfd9fe6425742cc1c84c11c57f60057a3f32fc29 | |
parent | c7a059f0d316b757714fb3e278044ed30bcdcda3 (diff) | |
download | libssh-1b20b8df85e07353f8403a6b55f8206980228639.tar.gz libssh-1b20b8df85e07353f8403a6b55f8206980228639.tar.xz libssh-1b20b8df85e07353f8403a6b55f8206980228639.zip |
fixed bug in sample that made the client running in infinite loop.
hunted a bug in channel_poll that returned 0 when EOF.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@35 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r-- | libssh/channels.c | 2 | ||||
-rw-r--r-- | libssh/server.c | 1 | ||||
-rw-r--r-- | sample.c | 10 |
3 files changed, 10 insertions, 3 deletions
diff --git a/libssh/channels.c b/libssh/channels.c index a87d338a..31586314 100644 --- a/libssh/channels.c +++ b/libssh/channels.c @@ -674,6 +674,8 @@ int channel_poll(CHANNEL *channel, int is_stderr){ } else return 0; /* nothing is available has said fd_poll */ } + if(channel->remote_eof) + return 1; return buffer_get_len(buffer); } diff --git a/libssh/server.c b/libssh/server.c index 31bae3ba..0f429852 100644 --- a/libssh/server.c +++ b/libssh/server.c @@ -27,6 +27,7 @@ MA 02111-1307, USA. */ #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> +#include <netinet/in.h> #include <netdb.h> #include <errno.h> #include <string.h> @@ -155,7 +155,7 @@ void select_loop(SSH_SESSION *session,CHANNEL *channel){ } } if(outchannel[0]){ - while(channel_poll(outchannel[0],0)){ + while(channel && channel_poll(outchannel[0],0)){ lus=channel_read(outchannel[0],readbuf,0,0); if(lus==-1){ ssh_say(0,"error reading channel : %s\n",ssh_get_error(session)); @@ -163,10 +163,12 @@ void select_loop(SSH_SESSION *session,CHANNEL *channel){ } if(lus==0){ ssh_say(1,"EOF received\n"); + channel_free(channel); + channel=NULL; } else write(1,buffer_get(readbuf),lus); } - while(channel_poll(outchannel[0],1)){ /* stderr */ + while(channel && channel_poll(outchannel[0],1)){ /* stderr */ lus=channel_read(outchannel[0],readbuf,0,1); if(lus==-1){ ssh_say(0,"error reading channel : %s\n",ssh_get_error(session)); @@ -174,11 +176,13 @@ void select_loop(SSH_SESSION *session,CHANNEL *channel){ } if(lus==0){ ssh_say(1,"EOF received\n"); + channel_free(channel); + channel=NULL; } else write(2,buffer_get(readbuf),lus); } } - if(!channel_is_open(channel)){ + if(channel && !channel_is_open(channel)){ channel_free(channel); channel=NULL; } |