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

Re: possible issue with bsd_poll() on Windows


On Friday, 6 July 2018 00:53:52 CEST John Dunn wrote:
> I am seeing issues using non-blocking sockets on Windows. In particular, if
> I attempt to connect to either a non-reachable host or a host that doesn't
> have the specified port open the ssh_connect() call will never fail and
> will be stuck in a loop returning SSH_AGAIN. This same code behaves
> perfectly fine running on Linux.
> 
> I think I've tracked down the issue to the bsd_poll implementation in
> poll.c. The documentation for select (
> https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-s
> elect ) notes
> 
> 	Out-of-band data will only be reported in this way if the option
> SO_OOBINLINE is FALSE. If a socket is processing a connect call
> (nonblocking), failure of the connect attempt is indicated in exceptfds
> (application must then call getsockopt SO_ERROR to determine the error
> value to describe why the failure occurred). This document does not define
> which other errors will be included.
> 
> In bsd_poll if exceptfds is set it only ORs in POLLPRI | POLLRDBAND. It does
> not follow the suggestions in the documentation to call getsockopt to get
> the connection error. I've hacked in a call to getsockopt that checks to
> see if the error is WSAECONNREFUSED which does then report the connection
> failure but the error reported later via ssh_get_error is 'Unknown error'.
> I don't fully understand how bsd_poll is intended to return errors so I
> don't know the best way to bubble the error up.

bsd_poll() implements poll() [1] on Windows.

The manpage states: On error, -1 is returned, and errno is set appropriately. 

So I think this is what you need to do, setting the right errno (ECONNREFUSED) 
for WSAECONNREFUSED and return -1.


To contribute a patch, see the SubmittingPatches document in the git repo :-)


> On a related note, is reporting this via the email list the best way or
> should I submit a bug to https://bugs.libssh.org/?

Both work fine.


Cheers,


	Andreas


[1] https://linux.die.net/man/2/poll

-- 
Andreas Schneider                 asn@xxxxxxxxxxxxxx
GPG-ID:     8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D



Follow-Ups:
RE: possible issue with bsd_poll() on WindowsJohn Dunn <John.Dunn@xxxxxxx>
References:
possible issue with bsd_poll() on WindowsJohn Dunn <John.Dunn@xxxxxxx>
Archive administrator: postmaster@lists.cynapses.org