LibCurl request cancellation example

I ask how I can cancel a curl request:

res = curl_easy_perform(curl); 
+4
source share
3 answers

Use the CURLOPT_PROGRESSFUNCTION callback and return a nonzero value to discard when you decide. Perhaps you could use some other more suitable callbacks depending on your requirements.

+9
source

You cannot easily interrupt a running function from C; you will need to use signals. By typing Ctrl + C in your program, you must stop calling cURL, but it also kills your default process. To send a signal programmatically, for this you need separate threads or a process.

Depending on the problem you are trying to solve, you can set CURLOPT_TIMEOUT with curl_easy_setopt .

+1
source

You also have the option to use curl_multi_remove_handle. As stated in the official twist documentation:

"Removing a simple handle when using it will completely and legitimately stop transmission in the process associated with this simple handle. All other simple manipulations and translations remain unaffected."

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

+1
source

Source: https://habr.com/ru/post/1385114/


All Articles