tags:

views:

23

answers:

1

I use libssh2 to login a remote computer, then call libssh2_channel_exec to execute a daemon program, the daemon program will then select a available tcpip port and print the selected prot to console(stdio). Then, the daemon will listen the port for the incomming connect. After these step, the client will read the selected tcp port from stdio by "libssh2_channel_read". I can get the right value. But the question is : When I close the libssh2 channel (libssh2_channel_close()), the program will be blocked, until the remote program is exit. Are there any methods to close the channel whithout close the remote program? Because I use ssh only for the login and the available prot number, that's enougn.

In addition, the remote program uses Qt's QCoreApplication, so after it printing the available prot ,it will enter the event loop of app.exec() to respond the client, so , it must not exit immediately after print the port number.

A: 

There a function in libssh2 can solve my problem..:) "libssh2_session_set_blocking" libssh_session_set_blocking(mysession,0);//this will set the libssh2 working whith non-blocking mode.

The left work to do is ensure the client read all the output of the server, without blocking ,I must control the EOF myself. :) Thanks Stackoverflow, thanks google!

jnblue