curl / Mailing Lists / curl-library / Single Mail


Re: Question about curl_multi_remove_handle()

From: Ray Satiro via curl-library <>
Date: Sun, 4 Dec 2016 18:51:55 -0500

On 12/3/2016 7:02 PM, Daniel Stenberg wrote:
>> I guess that the callback functions are triggered by the
>> curl_multi_perform() call, right? What if there's a task switch
>> before the callback function is triggered so that another thread
>> could call curl_multi_remove_handle(). Would that still stop the
>> waiting callback function from being called?
> I don't think libcurl can return back from a function call without
> delivering received data to the data callback.

He seems to be using the same handle from multiple threads at the same
time which isn't supported. In other words, it sounds like he's saying
if thread 1 is in the middle of curl_multi_perform can thread 2 call
curl_multi_remove_handle on an easy handle in that multi and the answer
is no [1].

I think the most immediate way to abort the transfer from thread 2 would
be set some event or synchronization in that thread and then in thread 1
abort in the progress function [2]. That should work fast enough as long
as his socket timeout / perform loop is typical, since the progress
function is called quite frequently during perform. Then when perform
returns because of that have if msg->msg == CURLMSG_DONE
curl_multi_remove_handle(multi, curl).

In Windows it would look like

Thread 2:

Thread 1 in progress function:
timenow = time(NULL);
/* progress func can be called very frequently so check no more than
    once a second to see if we should abort early */
if(timenow != saved->timelast &&
    WaitForSingleObject(saved->stop, 0) != WAIT_TIMEOUT) {
saved->timelast = timenow;
/* do normal progress stuff */


List admin:
Received on 2016-12-05