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

Archive Index This month's Index

Subject: Re: Several direct_tcpip channels in one SSH session

Re: Several direct_tcpip channels in one SSH session

From: Peter Stuge <peter_at_stuge.se>
Date: Wed, 1 Feb 2012 09:49:08 +0100

Denis Malyshkin wrote:
> Is it possible to do opening of several direct_tcpip channels in one SSH
> session simultaneously (in async mode)?
> I.e. to call libssh2_channel_direct_tcpip_ex(...) several times for one
> session without waiting while previous calls to it are completed.
> As I saw in the source code, channel_direct_tcpip(...) uses some
> variables in the 'session' structure (like session->direct_state,
> session->direct_message and so on). So it seems that only one channel
> creation call can be execute for a session at the moment. And the next
> channel can be created only then a creation of the previous one is
> finished (successfully or with error). Is it correct?

Sure, it's pretty clear from the code and indeed your analysis.

The easy way out is to use blocking mode while creating the channels,
and switch to non-blocking only after they exist. This is what the
example/direct-tcpip.c demonstrates.

As an alternative, you can of course block in your code during
creation, and not create number two until the first channel is ready.
This is what you'll need to do if you already process other channels.

Finally, you can of course propose an improvement of the library. I
think it would be great to see an improvement in this area, and if
you come up with a nice solution for direct-tcpip channels then it
could also be applied to all other channel types.

Note that we want to reduce the number of malloc calls in libssh2.

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

the libssh2 team