[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Building interactive shell session


Hi, I'm new to libssh and I'd like to say thank you for the great library!
I'm really excited to build something fun with it.

Currently, I'm following the tutorial and having some issue understanding
about interactive shell session.
I understand that the server and the client communicate through the built
channel in the shell session.
When I executed the following code, somehow the 'ssh_channel_write()' never
returns. I'm assuming this function sends every command from the user to
the server side. Then, the server executes the received command and
'ssh_channel_read_nonblocking' function gets the result of the execution at
the user side. Am I missing something?
Any advice would be greatly helpful!
Thank you.

while (ssh_channel_is_open(channel) &&
>          !ssh_channel_is_eof(channel))
>   {
>     nbytes = ssh_channel_read_nonblocking(channel, buffer, sizeof(buffer),
> 0);
>     if (nbytes < 0) return SSH_ERROR;
>     if (nbytes > 0)
>     {
>       nwritten = write(1, buffer, nbytes);
>       if (nwritten != nbytes) return SSH_ERROR;

    }

    if (!kbhit())
>     {
>       usleep(50000L); // 0.05 second
>       continue;
>     }
>     nbytes = read(0, buffer, sizeof(buffer));
>     if (nbytes < 0) return SSH_ERROR;
>     if (nbytes > 0)
>     {
> *      nwritten = ssh_channel_write(channel, buffer, nbytes);*

*       // never returns *

      if (nwritten != nbytes) return SSH_ERROR;
>     }
>   }


-- 
Best, Sung

Archive administrator: postmaster@lists.cynapses.org