1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
9 * This is a very simple example using the multi interface.
15 /* somewhat unix-specific */
20 #include <curl/curl.h>
23 * Simply download two HTTP files!
25 int main(int argc, char **argv)
31 int still_running; /* keep number of running handles */
33 http_handle = curl_easy_init();
34 http_handle2 = curl_easy_init();
37 curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.example.com/");
40 curl_easy_setopt(http_handle2, CURLOPT_URL, "http://localhost/");
42 /* init a multi stack */
43 multi_handle = curl_multi_init();
45 /* add the individual transfers */
46 curl_multi_add_handle(multi_handle, http_handle);
47 curl_multi_add_handle(multi_handle, http_handle2);
49 /* we start some action by calling perform right away */
50 curl_multi_perform(multi_handle, &still_running);
52 while(still_running) {
53 struct timeval timeout;
54 int rc; /* select() return code */
67 /* set a suitable timeout to play around with */
71 curl_multi_timeout(multi_handle, &curl_timeo);
73 timeout.tv_sec = curl_timeo / 1000;
74 if(timeout.tv_sec > 1)
77 timeout.tv_usec = (curl_timeo % 1000) * 1000;
80 /* get file descriptors from the transfers */
81 curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
83 /* In a real-world program you OF COURSE check the return code of the
84 function calls. On success, the value of maxfd is guaranteed to be
85 greater or equal than -1. We call select(maxfd + 1, ...), specially in
86 case of (maxfd == -1), we call select(0, ...), which is basically equal
89 rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
97 /* timeout or readable/writable sockets */
98 curl_multi_perform(multi_handle, &still_running);
103 curl_multi_cleanup(multi_handle);
105 curl_easy_cleanup(http_handle);
106 curl_easy_cleanup(http_handle2);