2

I am using libssh.
After calling ssh_channel_write, I have to know whether there has data to read. (But I don't want to retrieve data.)
If there has no data to read (for example, after 10s), I will call ssh_channel_write again.
Both of ssh_channel_read and ssh_channel_read_nonblocking cannot do this. (And checking ssh_get_status with SSH_READ_PENDING also does not work.)
Is there any ways to solve this problem?

jww
  • 97,681
  • 90
  • 411
  • 885
Caesar
  • 971
  • 6
  • 13

1 Answers1

1

It's NonBlocking ...

Use the ssh_select() function. It works quite similar to the regular select(), but uses channels instead of sockets.

int ssh_select (ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd, fd_set *readfds, struct timeval *timeout);

For instance, a single channel implementation:

ssh_channel channels[2];
ssh_channel myChannel = ssh_channel_new (ssh_session session); 

channels[0] = myChannel;
channels[1] = NULL;

struct timeval timeout = (0, 200000); // 0 seconds, 200 millis

int rc = ssh_select (channels, NULL, NULL, NULL, &timeout);

if (rc > 0) {// There is a pending data.
if (rc < 0) // the ssh_select() error.
if (rc == 0) // You've got a broken connection.
Zeev
  • 55
  • 5