cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: v2 of patch to fix busy-waiting during Windows async name lookup

From: Jamie Lokier <jamie_at_shareable.org>
Date: Thu, 10 Sep 2009 14:03:54 +0100

Darryl Green wrote:
> On Mon, 2009-09-07 at 09:09 -0700, Constantine Sapuntzakis wrote:
> > The dummy socket is always writable.
...
> > Fails on Windows 7 and XP SP3. Haven't tested others - I don' t have
> > them handy right now.
> >
> >
> > I've attached test code. Interestingly, it shows the dummy socket is
> > never readable or exceptable on XP SP3 and Win7. So, the dummy socket
> > trick might work for these two versions of Windows if we ask the
> > caller to check for readability instead of writability.
>
> That seems a good idea. Not sure what exactly various versions of
> windows do with an unbound UDP socket on write, but it is normal on
> other platforms for the first call to sendto on such a socket to perform
> a bind to a random available port. Given that, it isn't surprising that
> the socket is considered "ready for write". I do agree that an unbound
> socket can't logically be ready for read.

I agree with Darryl. This might even be the exacty behaviour that was
added to Windows.

That's normal behaviour and very common in applications, because it's
exactly what you want when making a UDP request to some server.

You're not expected to call bind() for that, unless you want to fix
the source port or source address, and those are both unusual.

Actually, I'm quite surprised that earlier versions of Windows _don't_
indicate writable for the dummy socket. _That's_ a bug which would
break some applications, because they should be able to send.

Maybe Microsoft fixed it at the same time as fixing the select()
result for errors from asynchronous connect() :-)

> > However, this is undocumented behavior or at least very uncommon
> > behavior and thus susceptible to changes across different versions of
> > the Microsoft OS.

If you look into BSD sockets tradition, it's probably being like this
for a very long time. Microsoft follows a lot of BSD sockets
behaviour in great detail - they have to, everyone else does - and a
lot of it isn't documented but expected to work.

Constantine, would you like to check if you can actually call sendto()
on the writable unbound socket (sending to a valid address and
non-zero port), and if that autobinds to a random, unused local port
number (and chooses a local address)? If so I think we can be
confident that "ready for read" is the right condition to use in
select().

The only question will be whether it works in older versions of
Windows, which clearly did not implement select() properly.

Speaking of that, do the latest versions of Windows still require a
dummy socket in select calls? Has anyone checked?

-- Jamie
Received on 2009-09-10