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

Re: Nonblocking Behaviour for .NET


On 26/05/17 17:43, Jason Curl wrote:
>
> ssh_set_blocking(session, false);
> ssh_connect(session);
> fd = ssh_get_fd(session);
>
> // Here is where  i have a wrapper library to do select(), with the fd
> returned above in the fd_set for writefds.
> FD_SET writefds;
> FD_ZERO(&writefds);
> FD_SET(fd, &writefds);
> sres = select(fd+1, NULL, &writefds, NULL, &timeout); // returns 1
> if (FD_ISSET(fd, &writefds)) rc = ssh_connect(session) // returns -2,
> indicating EAGAIN.
>
> I don't understand the code too well, but there's only one instance of
> SSH_AGAIN and that is:
> if(!ssh_is_blocking(session) &&!ssh_connect_termination(session)){
> returnSSH_AGAIN;
> }
>
> Is there a way to know the connect is finished, or do I have to
> continuously poll with connect? 
Hi Jason,

You get SSH_AGAIN with the second ssh_connect because the socket is
connected, but the key exchange is not completed. We're currently short
on callbacks to announce that the connection is over (well, there's
ssh_status_callback but it wasn't really designed for this purpose), so
yes you have to continue polling (using your own select is fine) +
calling ssh_connect() until it returns != SSH_AGAIN.

the ssh_get_poll_flags() function will return the poll events that
libssh is currently waiting for (e.g. if the output socket is not empty,
SSH_WRITE_PENDING will be returned, and if it's expecting data to read
SSH_READ_PENDING will be set).

Aris



References:
Nonblocking Behaviour for .NETJason Curl <jason@xxxxxxxxxxxxxxxxxxxxxxxx>
Re: Nonblocking Behaviour for .NETJason Curl <jason@xxxxxxxxxxxxxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org