aboutsummaryrefslogtreecommitdiff
path: root/libssh
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-05-04 10:17:10 +0000
committerAndreas Schneider <mail@cynapses.org>2009-05-04 10:17:10 +0000
commit43d881ba28ac0b71ad583aebc7b82db646990b56 (patch)
treef9da5e9845ec4e1cd3894c412547d75ef92561ff /libssh
parent3d9fbe8eea901de93a70df5cd1cfa2407583be68 (diff)
downloadlibssh-43d881ba28ac0b71ad583aebc7b82db646990b56.tar.gz
libssh-43d881ba28ac0b71ad583aebc7b82db646990b56.tar.xz
libssh-43d881ba28ac0b71ad583aebc7b82db646990b56.zip
Improve channel_poll() and add a SSH_EOF return value.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@702 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh')
-rw-r--r--libssh/channels.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/libssh/channels.c b/libssh/channels.c
index 686e100..13ddc25 100644
--- a/libssh/channels.c
+++ b/libssh/channels.c
@@ -1582,36 +1582,44 @@ int channel_read_nonblocking(CHANNEL *channel, void *dest, u32 count,
return rc;
}
-/** \brief polls the channel for data to read
- * \param channel channel
- * \param is_stderr boolean to select the stderr stream
- * \return number of bytes available for reading\n
- * 0 if nothing is available\n
- * SSH_ERROR on error
- * \warning When the channel is in EOF state, the function returns 1
- * \see channel_is_eof()
+/**
+ * @brief Polls a channel for data to read.
+ *
+ * @param channel The channel to poll.
+ *
+ * @param is_stderr A boolean to select the stderr stream.
+ *
+ * @return The number of bytes available for reading, 0 if nothing is available
+ * or SSH_ERROR on error.
+ *
+ * @warning When the channel is in EOF state, the function returns SSH_EOF.
+ *
+ * @see channel_is_eof()
*/
int channel_poll(CHANNEL *channel, int is_stderr){
- BUFFER *buffer;
- SSH_SESSION *session=channel->session;
- int r=0;
- enter_function();
- if(is_stderr)
- buffer=channel->stderr_buffer;
- else
- buffer=channel->stdout_buffer;
-
- while(buffer_get_rest_len(buffer)==0 && !channel->remote_eof){
- r=ssh_handle_packets(channel->session);
- if(r<=0)
- break;
- }
- if(channel->remote_eof){
- leave_function();
- return 1;
+ SSH_SESSION *session = channel->session;
+ BUFFER *stdbuf = channel->stdout_buffer;
+ int rc;
+
+ enter_function();
+
+ if (is_stderr) {
+ stdbuf = channel->stderr_buffer;
+ }
+
+ while (buffer_get_rest_len(stdbuf) == 0 && channel->remote_eof == 0) {
+ if (ssh_handle_packets(channel->session) < 0) {
+ break;
}
+ }
+
+ if (channel->remote_eof) {
leave_function();
- return buffer_get_rest_len(buffer);
+ return SSH_EOF;
+ }
+
+ leave_function();
+ return buffer_get_rest_len(stdbuf);
}
/** \brief recover the session in which belong a channel