www.libssh2.org | Daily snapshots | Mailing list archive | Docs | Examples | github

Archive Index This month's Index

Subject: Re: Callback for channel data ready

Re: Callback for channel data ready

From: Mitchell Hashimoto <mitchell.hashimoto_at_gmail.com>
Date: Thu, 1 Mar 2012 18:26:34 -0800


On Wed, Feb 29, 2012 at 7:42 PM, Peter Stuge <peter_at_stuge.se> wrote:

> Hi Mitchell,
> Mitchell Hashimoto wrote:
> > > > but I was hoping perhaps there was a better way?
> > >
> > > Sorry not at this time. I think we want callbacks though, so feel
> > > free to discuss and send patches. :)
> >
> > Understood. Thanks.
> >
> > I haven't been using libssh2 long enough to feel comfortable enough
> > in suggesting API improvements, since I haven't quite immersed
> > myself in the "libssh2 way."
> There is no such thing.. libssh2 has evolved, and must continue to
> evolve. The libssh2 API can and should be expanded to become more
> useful, and the definition of useful should basically come from it's
> users.
> > But I agree that callbacks would be fantastic.
> So how would that work?

Haha! I can appreciate that point of view.

I suppose now that I think about it, a callback would be somewhat
difficult, since the client controls the sockets. So even though ideally in
my head libssh2 would tell me when I should read, I understand that is not
really feasible.

Instead, I believe it would be nice to do something like the following:

int libssh2_session_ready_channels(LIBSSH2_SESSION *, LIBSSH2_CHANNEL **)

Where this would return a LIBSSH2_ERROR_EAGAIN if the socket would block
when nonblocking is on, and the return value would basically behave just
like any other libssh2 call. It would return `0` when it was a success.
Normal libssh2 behavior. If 0 is returned, then the second parameter is set
to a pointer to a single channel that is ready to be read, or NULL if none
are ready. This would allow this sort of behavior:

int rc = 0;
while ((rc = libssh2_session_ready_channels(sess, &channel)) == 0 &&
channel != NULL) {
    // Read from `channel`

Again, like I said, I don't know the internal structure of libssh2 or
the feasibility of such a thing, but I can see looping through channels to
become overwhelming.

What do you think?


> //Peter
> _______________________________________________
> libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-03-02

the libssh2 team