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
> 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
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...
Received on 2012-09-21