cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: connect error reporting

From: Gisle Vanem <gvanem_at_broadpark.no>
Date: Wed, 12 May 2004 14:23:28 +0200

"Daniel Stenberg" <daniel-curl_at_haxx.se> said:

> So, I take it we can use getsockopt() to get the error in case of failure, but
> I think we should avoid calling it just to verify the connect as is needed on
> non-windows platforms.
>
> 2. When using many threads on windows, this function call becomes a bottle-
> neck. It takes nearly all CPU time, as discussed and researched by Andrew
> Fuller back in October 2003.

That's fine. I'm just interested in more details when a connect fails.

Regarding the CPU usage, it seems the problem occurs when one switch
back to blocking mode. Then even a closesocket() could consume
100% CPU for several seconds (my impression on googling a bit).

I tested Andrew's CurlTest.cpp with 50 threads and, yes the CPU
goes to the roof. But this simple patch fixes that (diff against my
diff):

--- connect.c.orig Wed May 12 14:12:51 2004
+++ connect.c Wed May 12 14:09:28 2004
@@ -404,6 +404,10 @@
   bool rc;
   socklen_t errSize = sizeof(err);

+#ifdef WIN32
+ SleepEx(0, FALSE);
+#endif
+
   if( -1 == getsockopt(sockfd, SOL_SOCKET, SO_ERROR,

---------

I don't have Rational Quantify, but the hint from his post was
ntdll::NtRemoveIoCompletion(). So I'd assume the SleepEx
(or maybe just Sleep(0) would be enough?) would release whatever
mutex/critical-section the ntdll call is waiting on.

Someone got to verify this on Win-NT 4.0, 2000.

--gv
Received on 2004-05-12