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

@ -83,10 +83,9 @@ static void dump(const char *text, FILE *stream, unsigned char *ptr,
fflush(stream);
}
static
int my_trace(CURL *handle, curl_infotype type,
unsigned char *data, size_t size,
void *userp)
static int my_trace(CURL *handle, curl_infotype type,
unsigned char *data, size_t size,
void *userp)
{
const char *text;
@ -123,43 +122,48 @@ int my_trace(CURL *handle, curl_infotype type,
int main(void)
{
CURL *http_handle;
CURLM *multi_handle;
int still_running = 0; /* 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;
curl_easy_setopt(http_handle, CURLOPT_DEBUGFUNCTION, my_trace);
curl_easy_setopt(http_handle, CURLOPT_VERBOSE, 1L);
/* set the options (I left out a few, you get the point anyway) */
curl_easy_setopt(http_handle, CURLOPT_URL, "https://www.example.com/");
/* init a multi stack */
multi_handle = curl_multi_init();
curl_easy_setopt(http_handle, CURLOPT_DEBUGFUNCTION, my_trace);
curl_easy_setopt(http_handle, CURLOPT_VERBOSE, 1L);
/* 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);
int still_running = 0; /* keep number of running handles */
if(still_running)
/* wait for activity, timeout or "nothing" */
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
/* add the individual transfers */
curl_multi_add_handle(multi_handle, http_handle);
if(mc)
break;
do {
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
} while(still_running);
if(still_running)
/* wait for activity, timeout or "nothing" */
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
curl_multi_cleanup(multi_handle);
if(mc)
break;
curl_easy_cleanup(http_handle);
} while(still_running);
curl_multi_cleanup(multi_handle);
}
curl_easy_cleanup(http_handle);
}
curl_global_cleanup();