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

Re: non-blocking mode is not working in 0.6.3


Hi,

When you enable the nonblocking mode, all libssh functions return
SSH_AGAIN till there's something to read on the socket. What you see
here is normal, you must either use the blocking mode or select() on the
libssh fd, or use ssh_poll_ctx objects from libssh.

Aris

Le 2/08/14 01:49, Liang Qin a écrit :
> Hello, I'm trying to use libssh 0.6.3, but I found that I can not
> connect to SSH server if I set it to non-blocking mode with:
>   ssh_set_blocking(sess, 0);
> The ssh_connect function always return SSH_AGAIN in non-blocking mode.
> when I comment this line out, I can connect to SSH server correctly
>
> Any idea of this?
>
> Thanks
>
>
> my code:
> bool ssh_test(int fd,  port_t port, ip_t ip)
> {
>
>   ssh_session sess = ssh_new();
>   if(sess == NULL){
>     debug("fail in ssh_new\n");
>     return false;
>   }
>
>   //set options
>   ssh_set_blocking(sess, 0);
>   ssh_options_set(sess, SSH_OPTIONS_FD, &fd);
>   int ret = ssh_connect(sess);
>   if(ret){
>     debug("failed to connect to ssh %08lx:%d, ret = [%d].\n", ip,
> port, ret);
>     goto cleanup;
>   }
>   debug("ssh connect succeed, ret = [%d]\n", ret);
>
> cleanup:
>   if(sess)
>     ssh_free(sess);
>   if(fd != -1)
>     close(fd);
>
>   return true;
> }
>
>


References:
non-blocking mode is not working in 0.6.3Liang Qin <lqin@xxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org