Subject: Re: not getting all the data with libssh2_channel_exec and libssh2_channel_read

Re: not getting all the data with libssh2_channel_exec and libssh2_channel_read

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 7 Jan 2010 19:46:28 +0100 (CET)

On Thu, 7 Jan 2010, Peter Stuge wrote:

>> In my reading, the man page is quite clear that returning 0 is
>> indeed not an error.
>
> Only implicitly.

Let me quote what the libssh2_channel_read_ex man page says:

      Note that a return value of zero (0) can in fact be a legitimate value
      and only signals that no payload data was read. It is not an error.

That is about as explicit you can get in my book.

> But even if it was more clear, the behavior is quite counter-intuitive.
> (Compare read() or even SSL_read() where 0 is a special case.)

My man page for read() says the following on RETURN VALUE:

        Upon successful completion, read() and pread() shall return a non-
        negative integer indicating the number of bytes actually read. Other‐
        wise, the functions shall return -1 and set errno to indicate the
        error.

... there's no special case for 0 there.

But yes, SSL_read() special cases 0 but that (again) only shows the need for
a non-blocking mode...

You do surprise me though, as I was under the impression you wanted 0 to be a
non-error case. If 0 is not a legitimate return code, what is the function to
returned when no "payload data" has read and no error occurred?

-- 
  / daniel.haxx.se

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-01-07