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

@ -40,9 +40,6 @@ int main(void)
{
CURL *curl;
CURLM *multi_handle;
int still_running = 0;
struct curl_httppost *formpost = NULL;
struct curl_httppost *lastptr = NULL;
struct curl_slist *headerlist = NULL;
@ -76,50 +73,59 @@ int main(void)
CURLFORM_END);
)
curl = curl_easy_init();
multi_handle = curl_multi_init();
/* initialize custom header list (stating that Expect: 100-continue is not
wanted */
headerlist = curl_slist_append(headerlist, buf);
if(curl && multi_handle) {
/* what URL that receives this POST */
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/upload.cgi");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl = curl_easy_init();
if(curl) {
CURLM *multi_handle;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
CURL_IGNORE_DEPRECATION(
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
)
multi_handle = curl_multi_init();
if(multi_handle) {
curl_multi_add_handle(multi_handle, curl);
int still_running = 0;
do {
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
/* what URL that receives this POST */
curl_easy_setopt(curl, CURLOPT_URL,
"https://www.example.com/upload.cgi");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
if(still_running)
/* wait for activity, timeout or "nothing" */
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
CURL_IGNORE_DEPRECATION(
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
)
if(mc)
break;
curl_multi_add_handle(multi_handle, curl);
} while(still_running);
do {
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
curl_multi_cleanup(multi_handle);
if(still_running)
/* wait for activity, timeout or "nothing" */
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
if(mc)
break;
} while(still_running);
curl_multi_cleanup(multi_handle);
}
/* always cleanup */
curl_easy_cleanup(curl);
CURL_IGNORE_DEPRECATION(
/* then cleanup the formpost chain */
curl_formfree(formpost);
)
/* free slist */
curl_slist_free_all(headerlist);
}
CURL_IGNORE_DEPRECATION(
/* then cleanup the formpost chain */
curl_formfree(formpost);
)
/* free slist */
curl_slist_free_all(headerlist);
curl_global_cleanup();
return 0;
}