cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_easy_cleanup and curl-multi

From: Daniel Stenberg <daniel-curl_at_haxx.se>
Date: Wed, 8 Jun 2005 08:30:01 +0200 (CEST)

On Tue, 7 Jun 2005, Zibiao.Wei_at_atxinc.com wrote:

> I am new to libcurl. My first question is how to reuse curl_easy_handle in
> curl_multi.
>
> My test shows I have to follow these steps:
> 1. Set an url to an easy_handle.
> 2. Add the easy_handle to multi_handle.
> 3. curl_multi_perform
> 4. Remove easy_handle from multi_handle
> 5. Set another url to the easy_handle.
> 6. Add easy_handle to multi_handle again
> 7. curl_multi_perform.
>
> Am I right? Why step 4 and 6 are necessary?

As stupid as it may sound, they are necessary because that's how the multi
interface has been implmented!

Each easy handle has a state within the multi "engine" and when that state
reaches CURLM_STATE_COMPLETED, there's no other way for an app to reset it
back to CURLM_STATE_INIT unless you remove and readd the handle (as the state
is reset on the addition).

There was once talk about allowing curl_multi_add_handle() on an already added
handle, that would simply reset the state and thus restart that transfer.

Another option would be to add an entirely new function solely for that
purpose.

> Then I tried to download an url using an easy_handle through a multi_handle.
> If it failed, I would change the url to another mirror server and use the
> same easy_handle and multi_handle (remove easy, set new url, add to multi).
> This works for me, but when I finally call curl_easy_cleanup, I got an
> error:
>
> First-chance exception at 0x0040b0f7 in ATXCommX05.exe: 0xC0000005: Access
> violation reading location 0x00000048.

I assume this is 7.14.0 or at least a rather recent version?

Can you write up and show us the code for a complete stand-alone working
version that repeats this problem on a public URL?

If not, can you get a stack strace from the crash point and some relevant
local variable contents?

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