> Am 27.08.2023 um 20:35 schrieb Patrick Monnerat via curl-library 
> <curl-library@lists.haxx.se>:
> 
> 
> 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 */
}
curl_multi_iter_free(iter);

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]);
    if(easy)
      return easy;
    ++miter->i;
  }
  return NULL;
}

> 
> -- 
> Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
> Etiquette:   https://curl.se/mail/etiquette.html

-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html

Reply via email to