cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to list easy handles from a multi handle

From: Ray Satiro via curl-library <curl-library_at_cool.haxx.se>
Date: Wed, 8 Jun 2016 16:15:15 -0400

On 6/8/2016 6:12 AM, Jeroen Ooms wrote:
> On Tue, Jun 7, 2016 at 1:02 AM, Ray Satiro via curl-library
> <curl-library_at_cool.haxx.se> wrote:
>> >What he was getting at I think is you could propose a patch if you wanted.
>> >
>> >If you are in a pinch it's for sure very discouraged to do this but if
>> >you're comfortable with type punning you could access the internal linked
>> >list of easy handles for a multi. I experimented with that this afternoon.
>> >It's an internal structure that may change in the future though so you'd
>> >need to check each version you choose to support. See:
>> >https://gist.github.com/jay/5b68c1bde985b1b2d23f2b583a26e5ad
> Hmm this is certainly interesting. I'm rather not start hacking though
> because I'm writing bindings that should work across versions of
> libcurl. However if such a feature were to be added to a future
> version of libcurl, we could something like this as a fallback
> implementation to support for older versions of libcurl.
>
> However I still wonder how other applications deal with this problem.
> This must have come up before, perhaps I'm missing something.
>
> Suppose you implement a browser-like application where async (e.g.
> ajax) requests are continuously added to a global multi handle.
> Suppose you implement one multi-handle per browser tab. Now if the
> user closes the tab, we need to cleanup the multi handle and "pending"
> easy-handles from that multi handle.
>
> Is the recommended approach to keep track of this ourselves by
> implementing a double-linked list of easy handles in C, in which we
> manually append and remove pointers to the easy handles when they are
> added/removed to the multi handle?

As far as I know there's no way to do it other than what either of us
has already suggested, but maybe someone with more experience here knows
otherwise?

Using a doubly linked list of easy handles that you can add/remove from
may have some performance impact if you have a very large number of them
and are removing arbitrary easy handles as they are completed, since
that would mean traversing your list until you find the ones you want to
remove and cleanup. In that case you could either associate your list
item in the easy handle so you can call curl_easy_getinfo with
CURLINFO_PRIVATE and go right to it or try a binary tree like red-black.

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-06-08