curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Curl_poll and Windows

From: Daniel Stenberg via curl-library <>
Date: Mon, 18 Nov 2019 23:11:26 +0100 (CET)

On Mon, 18 Nov 2019, Jeff Mears via curl-library wrote:

> I just noticed the function Curl_poll in libcurl. It has some things that
> could be improved for usage on Windows.

Cool, in general we have a lack of Windows oriented developers in the project
making such issues and features unfortunately sometimes ending up not getting
the focus they could deserve.

> First, Windows Vista and later have an API called WSAPoll. It works almost
> the same as UNIX poll.

Almost is the key there. We once used it and ditched it due to the "almost"
not being good enough. I blogged about that back in the day

Not saying it can't be used, it just needs to be done with care and attention
to details.

> FD_SET is really slow in Windows.

So slow it actually matters and is worth it for us to replace it with
something else you think?

> The solution is again to build the array yourself. In C++, I've used
> std::vector<SOCKET> to do this, static_asserting that offsetof(fd_set,
> fd_array) == sizeof(SOCKET), which it is, and memcpying a u_int to [0] for
> fd_count. It's a hack, but it works. A custom vector class could also be
> used.

We'll happily welcome patches that improve libcurl, in this area as well as
others! This is all news to me and yet I've toyed with these things for a
while... albeit, not much on Windows.

> Finally, a minor technical detail: Curl_wait_ms is not equivalent to a
> select() on a socket that doesn't fire and hits the timeout. This is
> because select() and WSAPoll() are an "alertable wait state" in Windows.

Reading the code at:

... I would say that we call Sleep() on Windows, and not select.

> A correct Windows implementation of Curl_wait_ms that is intended to mimic
> select() would use SleepEx with the second parameter TRUE, in a loop because
> unlike select(), SleepEx will abort if an APC occurs.

I don't even know what an APC is, but again, we welcome pull requests! =)

I'm not aware of our use of Sleep() there have ever been an issue. That could
of course also be because it doesn't matter much if the sleep would return
prematurely once every blue moon.

  / | Get the best commercial curl support there is - from me
                   | Private help, bug fixes, support, ports, new features
Received on 2019-11-18