123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #define USE_OPENSSL
- #include <stdio.h>
- #include <pthread.h>
- #include <curl/curl.h>
- #define NUMT 4
- static const char * const urls[]= {
- "https://www.example.com/",
- "https://www2.example.com/",
- "https://www3.example.com/",
- "https://www4.example.com/",
- };
- static void *pull_one_url(void *url)
- {
- CURL *curl;
- curl = curl_easy_init();
- curl_easy_setopt(curl, CURLOPT_URL, url);
-
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
- curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
- curl_easy_perform(curl);
- curl_easy_cleanup(curl);
- return NULL;
- }
- int main(int argc, char **argv)
- {
- pthread_t tid[NUMT];
- int i;
- (void)argc;
- (void)argv;
-
- curl_global_init(CURL_GLOBAL_ALL);
- for(i = 0; i < NUMT; i++) {
- int error = pthread_create(&tid[i],
- NULL,
- pull_one_url,
- (void *)urls[i]);
- if(0 != error)
- fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
- else
- fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]);
- }
-
- for(i = 0; i < NUMT; i++) {
- pthread_join(tid[i], NULL);
- fprintf(stderr, "Thread %d terminated\n", i);
- }
- return 0;
- }
|