diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-08-31 16:17:15 +0300 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-09-02 11:43:12 +0300 |
commit | 92c8a71abbfdbbfa79bbdb26f5ed9299e5a3b9d1 (patch) | |
tree | 20cfb28ffd2fbec13007397920492e11e063c26b /src/channels.c | |
parent | b5351f2809140921076ef54cc6092b543b5199d2 (diff) | |
download | libssh-92c8a71abbfdbbfa79bbdb26f5ed9299e5a3b9d1.tar.gz libssh-92c8a71abbfdbbfa79bbdb26f5ed9299e5a3b9d1.tar.xz libssh-92c8a71abbfdbbfa79bbdb26f5ed9299e5a3b9d1.zip |
ssh_select converted to ssh_event, and bugfix to ssh_channel_select
Diffstat (limited to 'src/channels.c')
-rw-r--r-- | src/channels.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/channels.c b/src/channels.c index b768eac..3009cb3 100644 --- a/src/channels.c +++ b/src/channels.c @@ -2938,6 +2938,7 @@ int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, int rc; int i; int tm, tm_base; + int firstround=1; struct ssh_timestamp ts; if (timeout != NULL) @@ -2992,15 +2993,7 @@ int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, rchans, wchans, echans); if (rchans[0] != NULL || wchans[0] != NULL || echans[0] != NULL) { /* At least one channel has an event */ - memcpy(readchans, rchans, (count_ptrs(rchans) + 1) * sizeof(ssh_channel )); - memcpy(writechans, wchans, (count_ptrs(wchans) + 1) * sizeof(ssh_channel )); - memcpy(exceptchans, echans, (count_ptrs(echans) + 1) * sizeof(ssh_channel )); - SAFE_FREE(rchans); - SAFE_FREE(wchans); - SAFE_FREE(echans); - if(event) - ssh_event_free(event); - return 0; + break; } /* Add all channels' sessions right into an event object */ if (!event){ @@ -3021,6 +3014,10 @@ int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_event_add_session(event, exceptchans[i]->session); } } + /* Get out if the timeout has elapsed */ + if (!firstround && ssh_timeout_elapsed(&ts, tm_base)){ + break; + } /* Here we go */ rc = ssh_event_dopoll(event,tm); if (rc != SSH_OK){ @@ -3031,10 +3028,17 @@ int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, return rc; } tm = ssh_timeout_update(&ts, tm_base); - - } while(1); /* Return to do loop */ - - /* not reached */ + firstround=0; + } while(1); + + memcpy(readchans, rchans, (count_ptrs(rchans) + 1) * sizeof(ssh_channel )); + memcpy(writechans, wchans, (count_ptrs(wchans) + 1) * sizeof(ssh_channel )); + memcpy(exceptchans, echans, (count_ptrs(echans) + 1) * sizeof(ssh_channel )); + SAFE_FREE(rchans); + SAFE_FREE(wchans); + SAFE_FREE(echans); + if(event) + ssh_event_free(event); return 0; } |