mirror of
https://github.com/curl/curl.git
synced 2026-07-26 13:37:21 +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
|
|
@ -191,67 +191,70 @@ int main(void)
|
|||
signal(SIGINT, sighandler);
|
||||
LIBXML_TEST_VERSION
|
||||
multi_handle = curl_multi_init();
|
||||
curl_multi_setopt(multi_handle, CURLMOPT_MAX_TOTAL_CONNECTIONS, max_con);
|
||||
curl_multi_setopt(multi_handle, CURLMOPT_MAX_HOST_CONNECTIONS, 6L);
|
||||
if(multi_handle) {
|
||||
curl_multi_setopt(multi_handle, CURLMOPT_MAX_TOTAL_CONNECTIONS, max_con);
|
||||
curl_multi_setopt(multi_handle, CURLMOPT_MAX_HOST_CONNECTIONS, 6L);
|
||||
|
||||
/* enables http/2 if available */
|
||||
/* enables http/2 if available */
|
||||
#ifdef CURLPIPE_MULTIPLEX
|
||||
curl_multi_setopt(multi_handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
|
||||
curl_multi_setopt(multi_handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
|
||||
#endif
|
||||
|
||||
/* sets html start page */
|
||||
curl_multi_add_handle(multi_handle, make_handle(start_page));
|
||||
/* sets html start page */
|
||||
curl_multi_add_handle(multi_handle, make_handle(start_page));
|
||||
|
||||
pending = 0;
|
||||
complete = 0;
|
||||
still_running = 1;
|
||||
while(still_running && !pending_interrupt) {
|
||||
int numfds;
|
||||
CURLMsg *m;
|
||||
pending = 0;
|
||||
complete = 0;
|
||||
still_running = 1;
|
||||
while(still_running && !pending_interrupt) {
|
||||
int numfds;
|
||||
CURLMsg *m;
|
||||
|
||||
curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
|
||||
curl_multi_perform(multi_handle, &still_running);
|
||||
curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
|
||||
curl_multi_perform(multi_handle, &still_running);
|
||||
|
||||
/* See how the transfers went */
|
||||
m = NULL;
|
||||
while((m = curl_multi_info_read(multi_handle, &msgs_left))) {
|
||||
if(m->msg == CURLMSG_DONE) {
|
||||
CURL *handle = m->easy_handle;
|
||||
char *url;
|
||||
struct memory *mem;
|
||||
curl_easy_getinfo(handle, CURLINFO_PRIVATE, &mem);
|
||||
curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
|
||||
if(m->data.result == CURLE_OK) {
|
||||
long res_status;
|
||||
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &res_status);
|
||||
if(res_status == 200) {
|
||||
char *ctype;
|
||||
curl_easy_getinfo(handle, CURLINFO_CONTENT_TYPE, &ctype);
|
||||
printf("[%d] HTTP 200 (%s): %s\n", complete, ctype, url);
|
||||
if(is_html(ctype) && mem->size > 100) {
|
||||
if(pending < max_requests && (complete + pending) < max_total) {
|
||||
pending += follow_links(multi_handle, mem, url);
|
||||
still_running = 1;
|
||||
/* See how the transfers went */
|
||||
m = NULL;
|
||||
while((m = curl_multi_info_read(multi_handle, &msgs_left))) {
|
||||
if(m->msg == CURLMSG_DONE) {
|
||||
CURL *handle = m->easy_handle;
|
||||
char *url;
|
||||
struct memory *mem;
|
||||
curl_easy_getinfo(handle, CURLINFO_PRIVATE, &mem);
|
||||
curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
|
||||
if(m->data.result == CURLE_OK) {
|
||||
long res_status;
|
||||
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &res_status);
|
||||
if(res_status == 200) {
|
||||
char *ctype;
|
||||
curl_easy_getinfo(handle, CURLINFO_CONTENT_TYPE, &ctype);
|
||||
printf("[%d] HTTP 200 (%s): %s\n", complete, ctype, url);
|
||||
if(is_html(ctype) && mem->size > 100) {
|
||||
if(pending < max_requests &&
|
||||
(complete + pending) < max_total) {
|
||||
pending += follow_links(multi_handle, mem, url);
|
||||
still_running = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("[%d] HTTP %d: %s\n", complete, (int) res_status, url);
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("[%d] HTTP %d: %s\n", complete, (int) res_status, url);
|
||||
printf("[%d] Connection failure: %s\n", complete, url);
|
||||
}
|
||||
curl_multi_remove_handle(multi_handle, handle);
|
||||
curl_easy_cleanup(handle);
|
||||
free(mem->buf);
|
||||
free(mem);
|
||||
complete++;
|
||||
pending--;
|
||||
}
|
||||
else {
|
||||
printf("[%d] Connection failure: %s\n", complete, url);
|
||||
}
|
||||
curl_multi_remove_handle(multi_handle, handle);
|
||||
curl_easy_cleanup(handle);
|
||||
free(mem->buf);
|
||||
free(mem);
|
||||
complete++;
|
||||
pending--;
|
||||
}
|
||||
}
|
||||
curl_multi_cleanup(multi_handle);
|
||||
}
|
||||
curl_multi_cleanup(multi_handle);
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue