Seth Willits wrote:
> So when exactly does channel_read block? I'm trying to determine
> exactly if when I should call read(). i.e., if I'm executing an
> arbitrary command from the user, if it's going to block because
> there is no output, I don't want to call it.
If you need to process multiple fds for events then look at some of
the examples which demostrate how to do this correctly, e.g.
direct_tcpip.c or tcpip-forward.c.
> channel = libssh2_channel_open_session(session);
> libssh2_channel_set_blocking(channel, 1);
> libssh2_channel_exec(channel, "touch 'test.tmp'");
> libssh2_channel_eof(channel); // 0
> libssh2_channel_read(channel, buffer, bufferSize); // 0, no blocking
It does block, but it returns when the remote side reports EOF. Exec
sleep 10s instead of touch for comparison.
> libssh2_channel_eof(channel); // 1
> libssh2_channel_read(channel, buffer, bufferSize); // 0, no blocking
Since the channel is now EOF, nothing can be read anymore.
//Peter
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-05-10