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 a HTTP file.
25 int main(int argc, char **argv)
30 int still_running; /* keep number of running handles */
32 http_handle = curl_easy_init();
34 /* set the options (I left out a few, you'll get the point anyway) */
35 curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.example.com/");
37 /* init a multi stack */
38 multi_handle = curl_multi_init();
40 /* add the individual transfers */
41 curl_multi_add_handle(multi_handle, http_handle);
43 /* we start some action by calling perform right away */
44 curl_multi_perform(multi_handle, &still_running);
46 while(still_running) {
47 struct timeval timeout;
48 int rc; /* select() return code */
61 /* set a suitable timeout to play around with */
65 curl_multi_timeout(multi_handle, &curl_timeo);
67 timeout.tv_sec = curl_timeo / 1000;
68 if(timeout.tv_sec > 1)
71 timeout.tv_usec = (curl_timeo % 1000) * 1000;
74 /* get file descriptors from the transfers */
75 curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
77 /* In a real-world program you OF COURSE check the return code of the
78 function calls. On success, the value of maxfd is guaranteed to be
79 greater or equal than -1. We call select(maxfd + 1, ...), specially in
80 case of (maxfd == -1), we call select(0, ...), which is basically equal
83 rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
89 printf("select() returns error, this is badness\n");
93 /* timeout or readable/writable sockets */
94 curl_multi_perform(multi_handle, &still_running);
99 curl_multi_cleanup(multi_handle);
101 curl_easy_cleanup(http_handle);