cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: aborting curl_easy_perform()

From: Daniel Stenberg <daniel-curl_at_haxx.se>
Date: Mon, 22 Aug 2005 08:33:33 +0200 (CEST)

On Mon, 22 Aug 2005, Gary Wisniewski wrote:

> I have the need to abort a curl_easy_perform() instantly, or close to it, at
> any time during it's operation, whether connecting, transferring, or waiting
> for a timeout.
>
> I have seen this a lot on the mailing list, and as far as I know this is
> still not an available feature. Is this true?

It is still true, yes.

> From what I have read, the suggestion has been to return an error from
> within a callback. However, there are times (such as waiting for a
> connection) when no callback is called.

The only time it can't call the progress callback is when it awaits a DNS
response (if not built to use an alternative asynch resolver). During all
other situation, it is meant to call callbacks and failure to do so would be a
bug.

> This is, I believe, a fairly typical situation. I have a multi-threaded
> program, and one of the threads is initiating or executing a transfer.
> Other threads, oblivious to this, may be operating a control panel or some
> other UI component which, at the user's whim, may be clicked and cause the
> chosen transfer to immediately terminate. I can't have the user "waiting"
> for this. It needs to be instant.

If you use your imagination you can figure out other ways to achieve the same
thing and give the user a good impression.

For example, you can start a new thread for the next transfer and allow the
previous transfer thread to take its time to detect the "kill" situation and
thus exit it "as soon as possible" without the user of the application
noticing. That removes the need for "immediate" abort.

> I am going to implement some method of doing this and send a patch.
> However, I wanted to be SURE that nobody else is implementing the same
> thing, or that there is no better way before I spend the time doing so.

I think you can be fairly sure no one else is working on this.

The reason for this is also that this is not an easily fixed problem. In fact,
I'm not even sure it can be fixed to provide such a function.

I'm glad you feel you want to step in and help us improve the library, but
this really isn't an easy solved issue.

> My method will be to create a new curl_easy_setopt called CURLOPT_ABORTFLAG,
> which is called like this:
>
> volatile long abort_flag = 0;
> curl_easy_setopt(curlhandle, CURLOPT_ABORTFLAG, (long)&abort_flag);
>
> At any time, any asynchronous thread can set abort flag to 1 in order to
> cause CURL to abort the current operation.
>
> Is this reasonable?

Not really. How would that help the situation when the library is blocked by a
function call to a system call for name resolving?

-- 
  Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
Received on 2005-08-22