Subject: Re: Incomplete read of channel 0 data from remote host.

Re: Incomplete read of channel 0 data from remote host.

From: Peter Stuge <peter_at_stuge.se>
Date: Fri, 23 Jul 2010 15:58:01 +0200

Ted Lemon wrote:
> I'm having a weird problem that I suspect is a failure to
> understand how the library works, and I'm wondering if somebody can
> clue me in.

I think maybe SSH rathern than the library. Let's see if we can find
the problem.

> My code is running in non-blocking mode. My app successfully
> connects to the remote host and authenticates, creates a channel,
> and starts a shell.

You do not request a PTY?

> Then when I try to read the initial output of the shell, I get
> nothing--libssh2_channel_read_ex returns EAGAIN.
>
> So I added some code to send "ls\n". Okay, now I get the initial
> login banner, and part of the ls output, but again it stops before
> I get a prompt.

This suggests that something along the way is being line buffered.
TTYs (including PTYs) are character based, so would not be, but if
you're running the shell without a PTY then maybe it's connected to
sshd on the server through a line buffered pipe.

> It looks like the code is returning EAGAIN when it already has some
> data, because it wants to fill up my input buffer (256 bytes)
> before returning any data at all. Does that make sense?

No. libssh2 never keeps anything from you. It's much simpler than
that.

> Is there a call I'm supposed to do to figure out how much data is
> available to be read?

Nope. Though this is not such a bad idea, we've been discussing ways
to improve the API and something like this has come up.

> I couldn't make sense of all the calls for getting and setting
> windows--is that what I'm missing?

No, windows is a fairly low-level part of the SSH protocol, so
nothing that applications should deal with.

> Anyway, thanks in advance for any advice you can give me!

Check that your connection to the shell is not line buffered
anywhere.

Also, note that you will need terminal emulation if you want to use
any more fancy formatting over the connection. Of course you can
always use the "dumb" terminal, but it isn't so sexy.

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