aboutsummaryrefslogtreecommitdiff
path: root/examples/sample.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2011-08-30 22:14:30 +0300
committerAris Adamantiadis <aris@0xbadc0de.be>2011-09-02 11:43:11 +0300
commit7f5206b8ac0bdc96b4afb2602418989d8c332659 (patch)
tree98a329f04fe555cf272739c86e6046414be00485 /examples/sample.c
parentcb2a111fa141f158baaae0f2fa6e474e6a2aca49 (diff)
downloadlibssh-7f5206b8ac0bdc96b4afb2602418989d8c332659.tar.gz
libssh-7f5206b8ac0bdc96b4afb2602418989d8c332659.tar.xz
libssh-7f5206b8ac0bdc96b4afb2602418989d8c332659.zip
sample: fix ssh_channel_read
Diffstat (limited to 'examples/sample.c')
-rw-r--r--examples/sample.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/examples/sample.c b/examples/sample.c
index 83cb01a..0ae8343 100644
--- a/examples/sample.c
+++ b/examples/sample.c
@@ -311,6 +311,7 @@ static void select_loop(ssh_session session,ssh_channel channel){
int lus;
int eof=0;
int maxfd;
+ unsigned int r;
int ret;
while(channel){
do{
@@ -345,8 +346,8 @@ static void select_loop(ssh_session session,ssh_channel channel){
channels[0]=NULL;
}
if(outchannels[0]){
- while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,0)!=0){
- lus=ssh_channel_read(channel,buffer,sizeof(buffer),0);
+ while(channel && ssh_channel_is_open(channel) && (r = ssh_channel_poll(channel,0))!=0){
+ lus=ssh_channel_read(channel,buffer,sizeof(buffer) > r ? r : sizeof(buffer),0);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
ssh_get_error(session));
@@ -364,8 +365,8 @@ static void select_loop(ssh_session session,ssh_channel channel){
return;
}
}
- while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,1)!=0){ /* stderr */
- lus=ssh_channel_read(channel,buffer,sizeof(buffer),1);
+ while(channel && ssh_channel_is_open(channel) && (r = ssh_channel_poll(channel,1))!=0){ /* stderr */
+ lus=ssh_channel_read(channel,buffer,sizeof(buffer) > r ? r : sizeof(buffer),1);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
ssh_get_error(session));