1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
10 /* A multi-threaded example that uses pthreads extensively to fetch
11 * X remote files at once */
15 #include <curl/curl.h>
20 List of URLs to fetch.
22 If you intend to use a SSL-based protocol here you MUST setup the OpenSSL
23 callback functions as described here:
25 http://www.openssl.org/docs/crypto/threads.html#DESCRIPTION
28 const char * const urls[NUMT]= {
29 "http://curl.haxx.se/",
30 "ftp://cool.haxx.se/",
31 "http://www.contactor.se/",
35 static void *pull_one_url(void *url)
39 curl = curl_easy_init();
40 curl_easy_setopt(curl, CURLOPT_URL, url);
41 curl_easy_perform(curl); /* ignores error */
42 curl_easy_cleanup(curl);
49 int pthread_create(pthread_t *new_thread_ID,
50 const pthread_attr_t *attr,
51 void * (*start_func)(void *), void *arg);
54 int main(int argc, char **argv)
60 /* Must initialize libcurl before any threads are started */
61 curl_global_init(CURL_GLOBAL_ALL);
63 for(i=0; i< NUMT; i++) {
64 error = pthread_create(&tid[i],
65 NULL, /* default attributes please */
69 fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
71 fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]);
74 /* now wait for all threads to terminate */
75 for(i=0; i< NUMT; i++) {
76 error = pthread_join(tid[i], NULL);
77 fprintf(stderr, "Thread %d terminated\n", i);