[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Simplify ssh_channel_poll


Hi folks,

Is there a reason why ssh_channel_poll has a separate body of code
from ssh_channel_poll_timeout?  It would seem that ssh_channel_poll
("poll with immediate timeout") should be a special case of
ssh_channel_poll_timeout.  I have a patch that makes this change
(which cuts a number of lines of code) attached.

It is true that this changes the (internal, not related to the spec)
behavior in the case where some data is already in the buffer, since
ssh_channel_poll_timeout always tries a poll, whereas ssh_channel_poll
doesn't if there's already data available.  However, this behavior
could be added back to ssh_channel_poll_timeout if desired and we
would still save code.

Thanks,
- Alan
From 329dd02283191fe8830b62082fae60586b005a01 Mon Sep 17 00:00:00 2001
From: Alan Dunn <amdunn@xxxxxxxxx>
Date: Fri, 7 Feb 2014 07:39:44 -0600
Subject: [PATCH] channels: Simplify ssh_channel_poll


Signed-off-by: Alan Dunn <amdunn@xxxxxxxxx>
---
 src/channels.c |   31 +------------------------------
 1 file changed, 1 insertion(+), 30 deletions(-)

diff --git a/src/channels.c b/src/channels.c
index b6f59f5..7c33bad 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -2927,36 +2927,7 @@ int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count
  * @see ssh_channel_is_eof()
  */
 int ssh_channel_poll(ssh_channel channel, int is_stderr){
-  ssh_buffer stdbuf;
-
-  if(channel == NULL) {
-      return SSH_ERROR;
-  }
-
-  stdbuf = channel->stdout_buffer;
-
-  if (is_stderr) {
-    stdbuf = channel->stderr_buffer;
-  }
-
-  if (buffer_get_rest_len(stdbuf) == 0 && channel->remote_eof == 0) {
-    if (channel->session->session_state == SSH_SESSION_STATE_ERROR){
-      return SSH_ERROR;
-    }
-    if (ssh_handle_packets(channel->session, SSH_TIMEOUT_NONBLOCKING)==SSH_ERROR) {
-      return SSH_ERROR;
-    }
-  }
-
-  if (buffer_get_rest_len(stdbuf) > 0){
-  	return buffer_get_rest_len(stdbuf);
-  }
-
-  if (channel->remote_eof) {
-    return SSH_EOF;
-  }
-
-  return buffer_get_rest_len(stdbuf);
+  return ssh_channel_poll_timeout(channel, 0, is_stderr);
 }
 
 /**
-- 
1.7.9.5


Archive administrator: postmaster@lists.cynapses.org