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: Christoph M. Becker via curl-library <curl-library_at_cool.haxx.se>
Date: Mon, 6 Jan 2020 17:30:38 +0100

Hi!

On 03.01.2020 at 17:17, Patrick Monnerat via curl-library wrote:

>> 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.

I was afraid of this answer, but thank you very much nonetheless! :)

> 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!

This is exactly my problem.

> 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.

While I understand that rebuilding the mime structure is the easiest
way, that's unfortunately not easy for the PHP binding I'm working on.

I do not understand, though, how it could be possible to deal with
handle-specific data in the arg structure, since I'm not aware how to
determine which cURL handle had called any of the callbacks. What am I
missing?

>> 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.

Well, I have to deal with this, one way or another.

Thanks again for your reply! Much appreciated.

--
Christoph M. Becker
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2020-01-06