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: Getting a list of easy handles in a multi handle - possible?

From: Stefan Eissing via curl-library <>
Date: Mon, 28 Aug 2023 11:05:52 +0200

> Am 27.08.2023 um 20:35 schrieb Patrick Monnerat via curl-library <>:
> On 8/27/23 18:01, Daniel Stenberg via curl-library wrote:
>> On Sun, 27 Aug 2023, Henrik Holst via curl-library wrote:
>>> CURL **handles = curl_multi_get_handles(multi);
>>> where the last position in *handles would be NULL to indicate the end? Yes it would require libcurl to allocate a list and populate it at the call, but the allocation had to be done in this case anyway and returning a complete list at once avoids the problem with adds/dels during iteration of the list.
>> A benefit with this API design is that it can be freed with the already existing curl_free() function.
> +1
> IMO the best proposal yet :-) I don't see any drawback.

The tricky part is to handle iterations when easy handles are removed and freed during the iteration. If we save pointers, this can become tedious.

An alternative would be to have an opaque CURL_ITER* which holds the list of transfer ids XFER_ID (curl_off_t) as internal state at the time of creation. It would be, for now, more costly to look up the transfer for an XFER_ID, but it easily can handle additions/removals.

CURLM_ITER *iter = curl_multi_iter_create(multi);

while((easy = curlm_iter(iter)) {
   /* manipiulate in any way */

Internally that would be something like:

struct curlm_iter {
  CURLM *multi;
  size_t count, i;
  curl_off_t xfer_ids[1]; /* allocated to fit */

CURL *curlm_iter(CURLM_ITER *iter) {
  struct curlm_iter *miter = (struct curlm_iter*)iter;
  CURL *easy;
  while(miter && miter->i < miter->count) {
    easy = get_easy_for_xfer_id(miter->multi, miter->xfer_ids[miter->i]);
      return easy;
  return NULL;

> --
> Unsubscribe:
> Etiquette:

Received on 2023-08-28