Reputation: 9527
In my C++ program, I am downloading data from web. I can have up to 100 downloads in concurent, but they are usually not started at once and often, there can be only 4 etc.
Currently, I am using curl_easy_init
and std::async
to run download in the background.
I have read about curl_multi_init
. From what I understand, it is just an async wrapper made by cURL developers. Am I correct, or is there any other reason, why I should use it instead of multiple async jobs with easy_init?
Upvotes: 0
Views: 273
Reputation: 69902
The curl_multi_
subsystem is fully asynchronous which has a number of advantages, such as:
It does not consume an arbitrary number of threads. Each call to std::async
will create a thread. If this thread creation is unbounded, you will have a program that could run out of resources unexpectedly.
Transfers can be interrupted or cancelled under your control.
It will be more efficient, as all transfers share the same IO loop. The only point of contention is the select()
call (or equivalent for select_multi_socket
).
Upvotes: 2