[hotssh] gssh: Check for remote EOF in input stream reads



commit cdd73f081a7cc728c546f9a9fc8e461591d30302
Author: Colin Walters <walters verbum org>
Date:   Wed Dec 11 13:21:41 2013 -0500

    gssh: Check for remote EOF in input stream reads
    
    A read of size 0 can mean either EAGAIN or it could mean remote EOF,
    we have to call ssh_channel_is_eof() to distinguish.

 libgssh/gssh-channel-input-stream.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/libgssh/gssh-channel-input-stream.c b/libgssh/gssh-channel-input-stream.c
index a9a1c80..5b8d84e 100644
--- a/libgssh/gssh-channel-input-stream.c
+++ b/libgssh/gssh-channel-input-stream.c
@@ -187,8 +187,10 @@ void
 _gssh_channel_input_stream_iteration (GSshChannelInputStream     *self)
 {
   int rc;
+  int estatus;
   GError *local_error = NULL;
   GTask *prev_task = self->read_task;
+  gboolean is_eof = FALSE;
 
   if (!prev_task)
     return;
@@ -197,14 +199,28 @@ _gssh_channel_input_stream_iteration (GSshChannelInputStream     *self)
   rc = ssh_channel_read_nonblocking (self->channel->libsshchannel,
                                      self->buf, self->count, 0);
   if (rc == 0)
-    return;
+    {
+      is_eof = ssh_channel_is_eof (self->channel->libsshchannel);
+      estatus = ssh_channel_get_exit_status (self->channel->libsshchannel);
+      if (!is_eof)
+        {
+          g_debug ("channel read 0, not eof, estatus=%d", estatus);
+          return;
+        }
+    }
 
   /* This special dance is required because we may have reentered via
      g_task_return() */
   self->read_task = NULL;
 
-  if (rc > 0)
+  if (is_eof)
+    {
+      g_debug ("channel eof");
+      g_task_return_int (prev_task, 0);
+    }
+  else if (rc > 0)
     {
+      g_debug ("channel read %" G_GSSIZE_FORMAT " bytes", (gssize)rc);
       g_task_return_int (prev_task, rc);
     }
   else


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