0

I am working on a module which uses 10 queues to handle threads and each of them send curl requests using curl_easy interface (along with Lock) so that; a single connection is maintained till the response is not received. I want to enhance request handling by using curl_multi interface where curl requests are sent by the thread and handled in parallel fashion.

I have created a separate code to implement it. I created 3 threads for instance, being handled one by one, the first thread sends request to curl_multi till it's running and there are transfers existing, which allocates resources using curl_easy interface for each transfer.

I have gone through a lot of examples but cannot figure out how to implement it in C++. Also because I have recently learnt multi threading and curl concepts in C++ I need assistance with the approach.

I expect a single thread should be able to send curl requests till the user doesn't stop sending.

Update - I have added two threads and each sends two requests simultaneously. curl_multi is being handled by an array of handles, for curl_easy. I want to keep it free of arrays because that is limiting the number of requests.

Can it be made asynchronous and accept all transfers and exit only when the client/user does. There are enough examples of curl_multi therefore I am not clear of its implementation.

1 Answers1

0

Reading the curl_multidocumentation, it doesn't seem as you have to create different threads for this, as it works via your multiple easy handles added to the multi handle object. You then call curl_multi_perform to start all transfers in a non-blocking way.

I expect a single thread should be able to send curl requests till the user doesn't stop sending.

I don't understand what you mean by this, do you mean that you just want to keep those connections alive until everything is transferred? If so, curl_multi already gives you info on the progress of your transfers which can help you determine what to do.

Hope it helps

Olivier Samson
  • 609
  • 4
  • 13
  • Thank you for the response! Yeah I want to keep the connections alive till all the requests are transferred and their responses received. Different threads are for load distribution only which was being used earlier. – Nabeela Rizvi Mar 28 '19 at 06:58
  • @NabeelaRizvi I would look up the linked documentation, as it explains two different implementation you could go for, with the functions and objects related to each of them. This might help choose a solution that is best for you. Anyways, `curl_multi_perform` can be called a number of times (and I'm guessing this results in the requests being re-sent) to finish the transfers. – Olivier Samson Mar 28 '19 at 07:13