Skip to content

multi: add new information extraction methods#17992

Closed
icing wants to merge 5 commits intocurl:masterfrom
icing:multi_getinfo
Closed

multi: add new information extraction methods#17992
icing wants to merge 5 commits intocurl:masterfrom
icing:multi_getinfo

Conversation

@icing
Copy link
Copy Markdown
Contributor

@icing icing commented Jul 22, 2025

(updated after review by @dfandrich and @vszakats)

multi: add new information extraction method

Adds curl_off_t curl_multi_get_offt(CURLM *multi_handle, CURLMinfo_offt info) to the multi interface with enums:

  • CURLMINFO_XFERS_CURRENT: current number of transfers
  • CURLMINFO_XFERS_RUNNING: number of running transfers
  • CURLMINFO_XFERS_PENDING: number of pending transfers
  • CURLMINFO_XFERS_DONE: number of finished transfers to read
  • CURLMINFO_XFERS_ADDED: total number of transfers added, ever

Add documentation for functions and info enums.

Add use in the curl command line tool to replace two static variables counting the same "from the outside".

refs #17870

@icing icing added the feature-window A merge of this requires an open feature window label Jul 22, 2025
@icing icing marked this pull request as ready for review July 22, 2025 11:02
@icing icing requested review from bagder and vszakats July 22, 2025 11:02
Copy link
Copy Markdown
Member

@vszakats vszakats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I like how the type is reflected in the enum name. (It seems useful to keep future type names 4 letters, for readability/alignment.)

It crossed my mind to include _info_ in the function names, but since both have _multi_get_ in them, in sync with an existing getter, it's nicely greppable without adding anything.

Returning the value directly makes the new APIs easy to use. The slight downside is no way to return a failure or a non/missing-value (not in a single call). Existing counterpart curl_easy_getinfo() can return two errors: CURLE_UNKNOWN_OPTION, or CURLE_BAD_FUNCTION_ARGUMENT if the handle is NULL. I think in these cases it's just fine to return zero, as done already.

In some many words: This looks good to me!

Comment thread include/curl/multi.h Outdated
@icing
Copy link
Copy Markdown
Contributor Author

icing commented Jul 22, 2025

I had at first the variant returning CURLMcode. But the values we interrogate (so far) do not fail, unless the enum or the multi handle is wrong. So I changed it to this. Not 100% sure though.

@dfandrich
Copy link
Copy Markdown
Contributor

dfandrich commented Jul 22, 2025 via email

@icing
Copy link
Copy Markdown
Contributor Author

icing commented Jul 22, 2025

I'm thinking uint might not be the best type to use because it can be different sizes on different platforms leading to platform differences.

I chose unsigned int here because our internal transfers identifiers and capacity are unsigned ints since 8.14.0. Since we do not have uint64_t available in our API (I think this would break compatibility), using other types could lead to confusion in casting.

Maybe there is a way out of this, I am not aware of?

Update: the alternative would be to use curl_off_t for all of these. Our transfer count most likely will not exceed that in the next decades...

@vszakats
Copy link
Copy Markdown
Member

Update: the alternative would be to use curl_off_t for all of these. Our transfer count most likely will not exceed that in the next decades...

Sounds sensible. Maybe with an alias indicating the semantic
difference between a number and an offset?

@icing
Copy link
Copy Markdown
Contributor Author

icing commented Jul 23, 2025

Updated PR to only have the curl_off_t variant, renamed the enums.

@icing
Copy link
Copy Markdown
Contributor Author

icing commented Jul 23, 2025

Made #18004 to address the allocation limit failure of test1 on alpine musl.

@bagder
Copy link
Copy Markdown
Member

bagder commented Jul 24, 2025

A pretty major drawback with not being able to return an error: an application can't figure out if the info it asks for is actually zero (or -1?) when in reality the libcurl version it uses is just not new enough to support that info...

@icing
Copy link
Copy Markdown
Contributor Author

icing commented Jul 24, 2025

A pretty major drawback with not being able to return an error: an application can't figure out if the info it asks for is actually zero (or -1?) when in reality the libcurl version it uses is just not new enough to support that info...

Always good to use the latest curl...😌

Yeah, I can switch back to the version that returns a CURLMcode and return CURLM_UNKNOWN_OPTION for unkown infos.

@bagder
Copy link
Copy Markdown
Member

bagder commented Jul 25, 2025

Yeah, I can switch back to the version that returns a CURLMcode and return CURLM_UNKNOWN_OPTION for unknown infos.

I think that will be a better API for when we add new ones in the future.

@icing
Copy link
Copy Markdown
Contributor Author

icing commented Jul 28, 2025

I think that will be a better API for when we add new ones in the future.

Changed now.

@icing icing requested a review from vszakats July 28, 2025 08:15
Comment thread docs/libcurl/curl_multi_get_offt.md Outdated
Comment thread docs/libcurl/curl_multi_get_offt.md Outdated
via DoH, for example).

For the current number of easy handles managed by the multi, use
*CURLMINFO_XFERS_CURRENT*.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the documentation for these options should be converted into their own dedicated man pages like they are for curl_easy_getinfo() and others, but I am also okay with doing that in a separate PR after this is initially merged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that should it grow or if people come with too many questions regarding those.

icing added 5 commits July 31, 2025 11:43
Adds `curl_off_t curl_multi_get_offt(CURLM *multi_handle, CURLMinfo_offt info)`
to the multi interface with enums:

* CURLMINFO_XFERS_CURRENT: current number of transfers
* CURLMINFO_XFERS_RUNNING: number of running transfers
* CURLMINFO_XFERS_PENDING: number of pending transfers
* CURLMINFO_XFERS_DONE: number of finished transfers to read
* CURLMINFO_XFERS_ADDED: total number of transfers added, ever

Add documentation for functions and info enums.

Add use in the curl command line tool to replace two static
variables counting the same "from the outside".

refs curl#17870
@icing icing requested a review from bagder July 31, 2025 12:03
@bagder bagder closed this in 1ad2009 Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous Integration cmdline tool feature-window A merge of this requires an open feature window libcurl API tests

Development

Successfully merging this pull request may close these issues.

4 participants