cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to interrupt waitconnect()

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Tue, 11 Jun 2002 15:02:13 +0200 (MET DST)

On Tue, 11 Jun 2002, Hanno L. Kranzhoff wrote:

> this might be a stupid question, but I didn't find an appropriate answer to
> it for a long time now. I'm using libcurl's easy interface (currently
> 7.9.6) with vc6 on win32 to accomplish HTTP form posts.
> curl_easy_perform() is being called inside a single thread to avoid
> blocking. Everything works fine except when I try to connect to a
> non-existing/unreachable server. I know that CURLOPT_CONNECTTIMEOUT
> specifies the time waitconnect() may take to connect to the server.

> But: Is there any way of interrupting waitconnect() before the timeout
> occurs? Let's say because the user wants to cancel the operation
> immediately?

No, there is currently no way to do this. However, I believe that the correct
way would be that libcurl should call the standard progress meter callback
each second (like it does when going idle when transferring) and then the
callback can return an error code to stop the waiting (in the same way it
works otherwise too).

I've been intending to make this fix before. I would gladly accept a patch
that (finally) brings this functionality.

However, this would not abort or cancel name resolving. That can also take
quite some time.

> The only solutions I can think of right now are:
> 1) Simply killing the thread, but there has to be
> a more elegant (and safer) way.

Killing it will make you leak memory and other resources.

> 2) Set CURLOPT_CONNECTTIMEOUT to 1 sec and let curl_easy_perform() fail
> silently for multiple times before displaying an error. This could lead to
> problems with slow connections I guess.

Some connections will take some time. Having the timeout set to 1 will make
your program imcapable of connecting to those hosts.

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
_______________________________________________________________
Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas - http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink
Received on 2002-06-11