mirror of
https://github.com/curl/curl.git
synced 2026-04-15 05:21:40 +03:00
examples: check more errors, fix cleanups, scope variables
Inspired by Joshua's report on examples. Closes #19055
This commit is contained in:
parent
61dcb56743
commit
64ed2ea196
42 changed files with 874 additions and 785 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue