user469350
user469350

Reputation: 151

Example how to cancel a libCurl request

I ask me, how I can cancel an curl request:

res = curl_easy_perform(curl);

Upvotes: 9

Views: 16071

Answers (4)

Tchakabam
Tchakabam

Reputation: 505

curl_easy_cleanup is your friend here I guess.

Upvotes: -4

François L.
François L.

Reputation: 71

You also have the option to use curl_multi_remove_handle. As stated in the offical curl documentation:

"Removing an easy handle while being used is perfectly legal and will effectively halt the transfer in progress involving that easy handle. All other easy handles and transfers will remain unaffected."

c.f. https://curl.haxx.se/libcurl/c/curl_multi_remove_handle.html

Upvotes: 7

kan
kan

Reputation: 28961

Use CURLOPT_PROGRESSFUNCTION callback and return non-zero to abort when you decide to. Maybe you could use some other more appropriate callbacks depending on your requirements.

Upvotes: 10

Fred Foo
Fred Foo

Reputation: 363627

You can't easily interrupt a running function from within C; you'll need to use signals. Typing Ctrl+C at your program should terminate the cURL call, but also kills your process by default. To send a signal programmatically, you'll need a separate threads or process to do so.

Depending on what problem you're trying to solve, you may want to set CURLOPT_TIMEOUT with curl_easy_setopt.

Upvotes: 1

Related Questions