views:

443

answers:

3

Is there an easy way to cancel a curl_easy_perform from another thread?

+5  A: 

You have to use the callback functions (write/read/progress) to perform the cancel. The other thread needs to set a flag and the callback function checks the flag and returns the proper value to cancel the operation.

robottobor
A: 

Im using progress callback atm. So if i return !0 in that it will cancel it?

Edit: Works a treat. Thanks!

Lodle
A: 

The above strategy fails in some conditions. On some FTP sites I experience a 60 second delay before the transfer begins. During this time no callbacks are invoked, if my users try to cancel the transfer they get hung on the pthread_join until the transfer starts and the first callback runs.

Is my only options to do a pthread_cancel? Is there any other way to get curl_easy_perform to return?

JLuna