1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: multi-single.c,v 1.1.1.1 2008-09-23 16:32:05 hoffman 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 /* In a real-world program you OF COURSE check the return code of the
69 function calls, *and* you make sure that maxfd is bigger than -1 so
70 that the call to select() below makes sense! */
72 rc
= select(maxfd
+1, &fdread
, &fdwrite
, &fdexcep
, &timeout
);
78 printf("select() returns error, this is badness\n");
82 /* timeout or readable/writable sockets */
83 while(CURLM_CALL_MULTI_PERFORM
==
84 curl_multi_perform(multi_handle
, &still_running
));
89 curl_multi_cleanup(multi_handle
);
91 curl_easy_cleanup(http_handle
);