cURL / Mailing Lists / curl-library / Single Mail

curl-library

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

From: Darryl Green <darryl.green_at_gmail.com>
Date: Thu, 10 Sep 2009 20:59:07 +1000

On Mon, 2009-09-07 at 09:09 -0700, Constantine Sapuntzakis wrote:
> On Mon, Sep 7, 2009 at 5:15 AM, Jamie Lokier <jamie_at_shareable.org>
> wrote:
> Constantine Sapuntzakis wrote:
> > +The dummy descriptor trick does not seem to work on Windows
> XP SP3.
>
> Can you say a bit more about what fails?
>
> The dummy socket is always writable.
>
>
> What is it about the dummy descriptor that fails on XP SP3?
> Does it
> fail every time, or occasionally?
>
> Every time.
>
>
> "Does not seem to work" isn't much of an explanation and it
> doesn't
> give the user much information to decide if they need the
> NODUMMY
> option or not. Does it fail on XP SP4, Vista or Windows 7,
> ME, XP
> embedded, or any other version?
>
> 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.
>
> However, this is undocumented behavior or at least very uncommon
> behavior and thus susceptible to changes across different versions of
> the Microsoft OS.

I also agree it is an uncommon case - but why assume it is broken. I
don't see any logical or implementation reason why an unbound socket
will be treated as ready for read, and you have already shown it isn't
on current mainstream Windows... The minimally hacked about version
attached gives the following results on Debian testing with a 2.6.26
kernel (ie while you don't need a dummy socket on that platform, it
would do no harm).

darryl_at_deepthought:~/curl$ g++ socket_test.cpp
darryl_at_deepthought:~/curl$ ./a.out
rc = 1
readable? no
writable? yes
exception? no
rc = 0
readable? no
rc = 1
writable? yes
rc = 0
exception? no
darryl_at_deepthought:~/curl$

Received on 2009-09-10