Subject: Re: Direct tcp ip channel - session handshake

Re: Direct tcp ip channel - session handshake

From: Maxime Larocque <maxmtl2002_at_yahoo.ca>
Date: Fri, 21 Sep 2012 10:58:28 -0400

Hello Jiri,

Le 21/09/2012 10:10, Jiri a écrit :
> Hi, I am a beginner in network programming and now I have problem with
> using direct tcp channel.
> Using direct_tcp_example is everything working good and I'm able to
> connect with ssh shell to remote server. The same is when using
> threads in application code - in the first thread application wait to
> connection, in the second thread, new connection to localhost and
> local_listenport (something like at direct_tcpip example), new
> session, handshake and authentification - everything is OK.
>

Make sure that you don't share the sessions or channel between thread -
only access libssh2 structure from a single thread. Yes, it will seem to
work right until the system is delivered, and then crash for unknown
reasons :-).

> Problem is when listensocket is set to nonblocking mode. Direct
> channel is created, nonblocking mode set on session and connection is
> realized on localhost. In this case socket is connected
> on redirected port, but handshake returns -37 (LIBSSH2_ERROR_EAGAIN).
> In this new session is set nonblocking mode.
> Is it somehow possible to realize connection to 3rd party host without
> using threads or somethink like that? Thanks a lot!
>

LIBSSH2_ERROR_EAGAIN means that no data is available right now (waiting
for remote or tx socket full...). You should call it again when there is
some activity on the socket (using select or poll or...). In
non-blocking mode, a lot of libssh2 function can produce
LIBSSH2_ERROR_EAGAIN...

Instead of using thread you should use a single select to wait for all
events (local_listenport and ssh socket...). That is a pretty common
networking software behaviour.

As Peter said, study the code...

Maxime

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-09-21