curl_mime_data_cb() with curl_easy_duphandle()
Date: Thu, 2 Jan 2020 11:29:17 +0100
first, a happy new year to all of you!
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
curl_mime_data_cb(part, -1, readfunc, seekfunc, NULL, arg)
and have set up readfunc() and seekfunc() to open a stream (unless the
stream is already open), and then to read and seek, respectively. The
stream is closed whenever readfunc() or seekfunc() fail, or when the
last read is signaled by readfunc() returning 0. arg is a pointer to a
structure which holds the filename and a stream handle (where NULL
signals that the stream is closed). Note that the stream is not
I'm not using freefunc(), because I had noticed (libcurl 7.67.0) that
freefunc() may be called only after the original handle *and* a
duplicated handle was curl_exec()'d, and both streams had been fully
read. So I came up with the solution described above.
Now the question is whether this solution is sound regarding potential
timeouts (or any other failure conditions) during sending the data. In
other words, does libcurl guarantee that readfunc() is always called
until it returns failure or 0? Or is it possible that libcurl may just
stop calling readfunc() in some cases, and calling freefunc() instead to
short-circuit? If the latter, would it be guaranteed that freefunc() is
called before readfunc() is called on a duplicated handle?
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?
Since the cURL manual doesn't seem to answer these questions, any
further insights are welcome!
You may also want to refer to <https://github.com/php/php-src/pull/5045>.
Received on 2020-01-02