1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: multi-single.c,v 1.3 2003/01/09 11:42:07 bagder Exp $
10 * This is a very simple example using the multi interface.
16 /* somewhat unix-specific */
21 #include <curl/curl.h>
24 * Simply download a HTTP file.
26 int main(int argc, char **argv)
31 int still_running; /* keep number of running handles */
33 http_handle = curl_easy_init();
35 /* set the options (I left out a few, you'll get the point anyway) */
36 curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.haxx.se/");
38 /* init a multi stack */
39 multi_handle = curl_multi_init();
41 /* add the individual transfers */
42 curl_multi_add_handle(multi_handle, http_handle);
44 /* we start some action by calling perform right away */
45 while(CURLM_CALL_MULTI_PERFORM ==
46 curl_multi_perform(multi_handle, &still_running));
48 while(still_running) {
49 struct timeval timeout;
50 int rc; /* select() return code */
61 /* set a suitable timeout to play around with */
65 /* get file descriptors from the transfers */
66 curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
68 rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
76 /* timeout or readable/writable sockets */
77 while(CURLM_CALL_MULTI_PERFORM ==
78 curl_multi_perform(multi_handle, &still_running));
83 curl_multi_cleanup(multi_handle);
85 curl_easy_cleanup(http_handle);