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_mime_data_cb() with curl_easy_duphandle()

From: Patrick Monnerat via curl-library <curl-library_at_cool.haxx.se>
Date: Fri, 3 Jan 2020 17:17:36 +0100

On 1/2/20 11:29 AM, Christoph M. Becker via curl-library wrote:
> Hi all,
>
> first, a happy new year to all of you!

Hi Christoph,

Best wishes to you too.

>
> I'm looking for clarification of the behavior of curl_mime_data_cb().
> Since I'm having to deal with handles possibly duplicated by
> curl_easy_duphandle(), I'm calling...

As noted in https://curl.haxx.se/libcurl/c/curl_mime_data_cb.html:

-----

Care must be taken if the part is bound to a curl easy handle that is
later duplicated: the arg pointer argument is also duplicated, resulting
in the pointed item to be shared between the original and the copied
handle. In particular, special attention should be given to the freefunc
procedure code since it will be called twice with the same argument.

-----

You have to deal with that.

 From your explanations, there are two possible cases:

1) The file handle is shared between the handles: on curl's point of
view, this is OK. But beware: reading from a handle advances the file
offset for both handles!

2) You prefer to duplicate the file handle (In other words, there are
some handle-specific data in the arg structure). Resolving this is
tricky and IMHO the easiest way to perform it is to rebuild the mime
structure yourself for the new handle after curl_easy_duphandle() call.

> Also, I wonder how that would work in combination with the
> curl_multi_*() functions. Say, two duplicate handles are combined to a
> multi handle; couldn't that result in readfunc() being called
> interleaved on the original and the duplicated handle?
Yes they can. Easy handles attached to a multi handle are processed
asynchronously and you have no control on the real operation sequence.
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-01-03