| 
26 | 26 |  * </DESC>  | 
27 | 27 |  */  | 
28 | 28 | 
 
  | 
 | 29 | +#include <curl/curl.h>  | 
29 | 30 | #include <stdlib.h>  | 
30 | 31 | #include <string.h>  | 
31 |  | -#include <curl/curl.h>  | 
32 | 32 | 
 
  | 
33 | 33 | static const char *urls[] = {  | 
34 |  | -  "https://www.microsoft.com",  | 
35 |  | -  "https://opensource.org",  | 
36 |  | -  "https://www.google.com",  | 
37 |  | -  "https://www.yahoo.com",  | 
38 |  | -  "https://www.ibm.com",  | 
39 |  | -  "https://www.mysql.com",  | 
40 |  | -  "https://www.oracle.com",  | 
41 |  | -  "https://www.ripe.net",  | 
42 |  | -  "https://www.iana.org",  | 
43 |  | -  "https://www.amazon.com",  | 
44 |  | -  "https://www.netcraft.com",  | 
45 |  | -  "https://www.heise.de",  | 
46 |  | -  "https://www.chip.de",  | 
47 |  | -  "https://www.ca.com",  | 
48 |  | -  "https://www.cnet.com",  | 
49 |  | -  "https://www.mozilla.org",  | 
50 |  | -  "https://www.cnn.com",  | 
51 |  | -  "https://www.wikipedia.org",  | 
52 |  | -  "https://www.dell.com",  | 
53 |  | -  "https://www.hp.com",  | 
54 |  | -  "https://www.cert.org",  | 
55 |  | -  "https://www.mit.edu",  | 
56 |  | -  "https://www.nist.gov",  | 
57 |  | -  "https://www.ebay.com",  | 
58 |  | -  "https://www.playstation.com",  | 
59 |  | -  "https://www.uefa.com",  | 
60 |  | -  "https://www.ieee.org",  | 
61 |  | -  "https://www.apple.com",  | 
62 |  | -  "https://www.symantec.com",  | 
63 |  | -  "https://www.zdnet.com",  | 
64 |  | -  "https://www.fujitsu.com/global/",  | 
65 |  | -  "https://www.supermicro.com",  | 
66 |  | -  "https://www.hotmail.com",  | 
67 |  | -  "https://www.ietf.org",  | 
68 |  | -  "https://www.bbc.co.uk",  | 
69 |  | -  "https://news.google.com",  | 
70 |  | -  "https://www.foxnews.com",  | 
71 |  | -  "https://www.msn.com",  | 
72 |  | -  "https://www.wired.com",  | 
73 |  | -  "https://www.sky.com",  | 
74 |  | -  "https://www.usatoday.com",  | 
75 |  | -  "https://www.cbs.com",  | 
76 |  | -  "https://www.nbc.com/",  | 
77 |  | -  "https://slashdot.org",  | 
78 |  | -  "https://www.informationweek.com",  | 
79 |  | -  "https://apache.org",  | 
80 |  | -  "https://www.un.org",  | 
 | 34 | +    "https://www.microsoft.com",  | 
 | 35 | +    "https://opensource.org",  | 
 | 36 | +    "https://www.google.com",  | 
 | 37 | +    "https://www.yahoo.com",  | 
 | 38 | +    "https://www.ibm.com",  | 
 | 39 | +    "https://www.mysql.com",  | 
 | 40 | +    "https://www.oracle.com",  | 
 | 41 | +    "https://www.ripe.net",  | 
 | 42 | +    "https://www.iana.org",  | 
 | 43 | +    "https://www.amazon.com",  | 
 | 44 | +    "https://www.netcraft.com",  | 
 | 45 | +    "https://www.heise.de",  | 
 | 46 | +    "https://www.chip.de",  | 
 | 47 | +    "https://www.ca.com",  | 
 | 48 | +    "https://www.cnet.com",  | 
 | 49 | +    "https://www.mozilla.org",  | 
 | 50 | +    "https://www.cnn.com",  | 
 | 51 | +    "https://www.wikipedia.org",  | 
 | 52 | +    "https://www.dell.com",  | 
 | 53 | +    "https://www.hp.com",  | 
 | 54 | +    "https://www.cert.org",  | 
 | 55 | +    "https://www.mit.edu",  | 
 | 56 | +    "https://www.nist.gov",  | 
 | 57 | +    "https://www.ebay.com",  | 
 | 58 | +    "https://www.playstation.com",  | 
 | 59 | +    "https://www.uefa.com",  | 
 | 60 | +    "https://www.ieee.org",  | 
 | 61 | +    "https://www.apple.com",  | 
 | 62 | +    "https://www.symantec.com",  | 
 | 63 | +    "https://www.zdnet.com",  | 
 | 64 | +    "https://www.fujitsu.com/global/",  | 
 | 65 | +    "https://www.supermicro.com",  | 
 | 66 | +    "https://www.hotmail.com",  | 
 | 67 | +    "https://www.ietf.org",  | 
 | 68 | +    "https://www.bbc.co.uk",  | 
 | 69 | +    "https://news.google.com",  | 
 | 70 | +    "https://www.foxnews.com",  | 
 | 71 | +    "https://www.msn.com",  | 
 | 72 | +    "https://www.wired.com",  | 
 | 73 | +    "https://www.sky.com",  | 
 | 74 | +    "https://www.usatoday.com",  | 
 | 75 | +    "https://www.cbs.com",  | 
 | 76 | +    "https://www.nbc.com/",  | 
 | 77 | +    "https://slashdot.org",  | 
 | 78 | +    "https://www.informationweek.com",  | 
 | 79 | +    "https://apache.org",  | 
 | 80 | +    "https://www.un.org",  | 
81 | 81 | };  | 
82 | 82 | 
 
  | 
83 | 83 | #define MAX_PARALLEL 10 /* number of simultaneous transfers */  | 
84 |  | -#define NUM_URLS sizeof(urls)/sizeof(char *)  | 
 | 84 | +#define NUM_URLS sizeof(urls) / sizeof(char *)  | 
85 | 85 | 
 
  | 
86 |  | -static size_t write_cb(char *data, size_t n, size_t l, void *userp)  | 
87 |  | -{  | 
88 |  | -  /* take care of the data here, ignored in this example */  | 
89 |  | -  (void)data;  | 
90 |  | -  (void)userp;  | 
91 |  | -  return n*l;  | 
 | 86 | +static size_t write_cb(char *data, size_t n, size_t l, void *userp) {  | 
 | 87 | +    /* take care of the data here, ignored in this example */  | 
 | 88 | +    (void)data;  | 
 | 89 | +    (void)userp;  | 
 | 90 | +    return n * l;  | 
92 | 91 | }  | 
93 | 92 | 
 
  | 
94 |  | -static void add_transfer(CURLM *cm, unsigned int i, int *left)  | 
95 |  | -{  | 
96 |  | -  CURL *eh = curl_easy_init();  | 
97 |  | -  curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, write_cb);  | 
98 |  | -  curl_easy_setopt(eh, CURLOPT_URL, urls[i]);  | 
99 |  | -  curl_easy_setopt(eh, CURLOPT_PRIVATE, urls[i]);  | 
100 |  | -  curl_multi_add_handle(cm, eh);  | 
101 |  | -  (*left)++;  | 
 | 93 | +static void add_transfer(CURLM *cm, unsigned int i, int *left) {  | 
 | 94 | +    CURL *eh = curl_easy_init();  | 
 | 95 | +    curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, write_cb);  | 
 | 96 | +    curl_easy_setopt(eh, CURLOPT_URL, urls[i]);  | 
 | 97 | +    curl_easy_setopt(eh, CURLOPT_PRIVATE, urls[i]);  | 
 | 98 | +    curl_multi_add_handle(cm, eh);  | 
 | 99 | +    (*left)++;  | 
102 | 100 | }  | 
103 | 101 | 
 
  | 
104 |  | -int main(void)  | 
105 |  | -{  | 
106 |  | -  CURLM *cm;  | 
107 |  | -  CURLMsg *msg;  | 
108 |  | -  unsigned int transfers = 0;  | 
109 |  | -  int msgs_left = -1;  | 
110 |  | -  int left = 0;  | 
 | 102 | +int main(void) {  | 
 | 103 | +    CURLM *cm;  | 
 | 104 | +    CURLMsg *msg;  | 
 | 105 | +    unsigned int transfers = 0;  | 
 | 106 | +    int msgs_left = -1;  | 
 | 107 | +    int left = 0;  | 
111 | 108 | 
 
  | 
112 |  | -  curl_global_init(CURL_GLOBAL_ALL);  | 
113 |  | -  cm = curl_multi_init();  | 
 | 109 | +    curl_global_init(CURL_GLOBAL_ALL);  | 
 | 110 | +    cm = curl_multi_init();  | 
114 | 111 | 
 
  | 
115 |  | -  /* Limit the amount of simultaneous connections curl should allow: */  | 
116 |  | -  curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, (long)MAX_PARALLEL);  | 
 | 112 | +    /* Limit the amount of simultaneous connections curl should allow: */  | 
 | 113 | +    curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, (long)MAX_PARALLEL);  | 
117 | 114 | 
 
  | 
118 |  | -  for(transfers = 0; transfers < MAX_PARALLEL && transfers < NUM_URLS;  | 
119 |  | -      transfers++)  | 
120 |  | -    add_transfer(cm, transfers, &left);  | 
 | 115 | +    for (transfers = 0; transfers < MAX_PARALLEL && transfers < NUM_URLS; transfers++)  | 
 | 116 | +        add_transfer(cm, transfers, &left);  | 
121 | 117 | 
 
  | 
122 |  | -  do {  | 
123 |  | -    int still_alive = 1;  | 
124 |  | -    curl_multi_perform(cm, &still_alive);  | 
 | 118 | +    do {  | 
 | 119 | +        int still_alive = 1;  | 
 | 120 | +        curl_multi_perform(cm, &still_alive);  | 
125 | 121 | 
 
  | 
126 |  | -    /* !checksrc! disable EQUALSNULL 1 */  | 
127 |  | -    while((msg = curl_multi_info_read(cm, &msgs_left)) != NULL) {  | 
128 |  | -      if(msg->msg == CURLMSG_DONE) {  | 
129 |  | -        char *url;  | 
130 |  | -        CURL *e = msg->easy_handle;  | 
131 |  | -        curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &url);  | 
132 |  | -        fprintf(stderr, "R: %d - %s <%s>\n",  | 
133 |  | -                msg->data.result, curl_easy_strerror(msg->data.result), url);  | 
134 |  | -        curl_multi_remove_handle(cm, e);  | 
135 |  | -        curl_easy_cleanup(e);  | 
136 |  | -        left--;  | 
137 |  | -      }  | 
138 |  | -      else {  | 
139 |  | -        fprintf(stderr, "E: CURLMsg (%d)\n", msg->msg);  | 
140 |  | -      }  | 
141 |  | -      if(transfers < NUM_URLS)  | 
142 |  | -        add_transfer(cm, transfers++, &left);  | 
143 |  | -    }  | 
144 |  | -    if(left)  | 
145 |  | -      curl_multi_wait(cm, NULL, 0, 1000, NULL);  | 
 | 122 | +        /* !checksrc! disable EQUALSNULL 1 */  | 
 | 123 | +        while ((msg = curl_multi_info_read(cm, &msgs_left)) != NULL) {  | 
 | 124 | +            if (msg->msg == CURLMSG_DONE) {  | 
 | 125 | +                char *url;  | 
 | 126 | +                CURL *e = msg->easy_handle;  | 
 | 127 | +                curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &url);  | 
 | 128 | +                fprintf(stderr, "R: %d - %s <%s>\n", msg->data.result,  | 
 | 129 | +                        curl_easy_strerror(msg->data.result), url);  | 
 | 130 | +                curl_multi_remove_handle(cm, e);  | 
 | 131 | +                curl_easy_cleanup(e);  | 
 | 132 | +                left--;  | 
 | 133 | +            } else {  | 
 | 134 | +                fprintf(stderr, "E: CURLMsg (%d)\n", msg->msg);  | 
 | 135 | +            }  | 
 | 136 | +            if (transfers < NUM_URLS) add_transfer(cm, transfers++, &left);  | 
 | 137 | +        }  | 
 | 138 | +        if (left) curl_multi_wait(cm, NULL, 0, 1000, NULL);  | 
146 | 139 | 
 
  | 
147 |  | -  } while(left);  | 
 | 140 | +    } while (left);  | 
148 | 141 | 
 
  | 
149 |  | -  curl_multi_cleanup(cm);  | 
150 |  | -  curl_global_cleanup();  | 
 | 142 | +    curl_multi_cleanup(cm);  | 
 | 143 | +    curl_global_cleanup();  | 
151 | 144 | 
 
  | 
152 |  | -  return EXIT_SUCCESS;  | 
 | 145 | +    return EXIT_SUCCESS;  | 
153 | 146 | }  | 
0 commit comments