examples: check more errors, fix cleanups, scope variables

Inspired by Joshua's report on examples.

Closes #19055
This commit is contained in:
Viktor Szakats 2025-10-13 22:57:01 +02:00
parent 61dcb56743
commit 64ed2ea196
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
42 changed files with 874 additions and 785 deletions

View file

@ -38,43 +38,48 @@
int main(void)
{
CURL *http_handle;
CURLM *multi_handle;
int still_running = 1; /* keep number of running handles */
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
if(res)
return (int)res;
http_handle = curl_easy_init();
if(http_handle) {
/* set the options (I left out a few, you get the point anyway) */
curl_easy_setopt(http_handle, CURLOPT_URL, "https://www.example.com/");
CURLM *multi_handle;
int still_running = 1; /* keep number of running handles */
/* init a multi stack */
multi_handle = curl_multi_init();
/* set the options (I left out a few, you get the point anyway) */
curl_easy_setopt(http_handle, CURLOPT_URL, "https://www.example.com/");
/* add the individual transfers */
curl_multi_add_handle(multi_handle, http_handle);
/* init a multi stack */
multi_handle = curl_multi_init();
if(multi_handle) {
do {
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
/* add the individual transfers */
curl_multi_add_handle(multi_handle, http_handle);
if(!mc)
/* wait for activity, timeout or "nothing" */
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
do {
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
if(mc) {
fprintf(stderr, "curl_multi_poll() failed, code %d.\n", (int)mc);
break;
if(!mc)
/* wait for activity, timeout or "nothing" */
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
if(mc) {
fprintf(stderr, "curl_multi_poll() failed, code %d.\n", (int)mc);
break;
}
} while(still_running);
curl_multi_remove_handle(multi_handle, http_handle);
curl_multi_cleanup(multi_handle);
}
} while(still_running);
curl_multi_remove_handle(multi_handle, http_handle);
curl_easy_cleanup(http_handle);
curl_multi_cleanup(multi_handle);
curl_easy_cleanup(http_handle);
}
curl_global_cleanup();