[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Asynchronous callbacks
[Thread Prev] | [Thread Next]
- Subject: Asynchronous callbacks
- From: Matteo <matpen@xxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Fri, 26 Feb 2016 19:09:44 +0100
- To: libssh@xxxxxxxxxx
Hi all, I am trying to make use of libssh's callbacks in an asynchronous way, but I cannot find any example of this in the documentation. My goal would be to accomplish the following: 1) establish a connection 2) setup callbacks (eg. "channel_data_function") 3) execute a remote command 4) enter event loop and have the callbacks automatically called However, I realize that the channel callbacks are called only when closing the channel. Since I do not know when the command finished, I do not know when to close the channel. Synchronous code works, here a simplified version: [...] session.connect(); session.userauthPassword(mypass); channel->openSession(); ssh_channel_callbacks_struct channel_callbacks; channel_callbacks.userdata = nullptr; channel_callbacks.channel_data_function = &data_callback; [...] ssh_callbacks_init(&channel_callbacks); channel->setCallbacks(&channel_callbacks); //I introduced this function in the cpp wrapper to conveniently call ssh_set_channel_callbacks() [...] channel->requestExec(command); usleep(5000000L); //wait for the command to finish channel->close(); //this fires all callbacks delete channel; session.disconnect(); The workaround I have used until now is to use a separate thread to continuously call channel->readNonblocking() and check channel->isEof() to detect the end of the command, but this seems to be a cumbersome solution. Can anyone provide any hints, or a pointer to start my research? Thank you in advance! Matteo
Archive administrator: postmaster@lists.cynapses.org