Annotation of embedaddon/curl/docs/examples/multi-poll.c, revision 1.1.1.1
1.1 misho 1: /***************************************************************************
2: * _ _ ____ _
3: * Project ___| | | | _ \| |
4: * / __| | | | |_) | |
5: * | (__| |_| | _ <| |___
6: * \___|\___/|_| \_\_____|
7: *
8: * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
9: *
10: * This software is licensed as described in the file COPYING, which
11: * you should have received as part of this distribution. The terms
12: * are also available at https://curl.haxx.se/docs/copyright.html.
13: *
14: * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15: * copies of the Software, and permit persons to whom the Software is
16: * furnished to do so, under the terms of the COPYING file.
17: *
18: * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19: * KIND, either express or implied.
20: *
21: ***************************************************************************/
22: /* <DESC>
23: * single download with the multi interface's curl_multi_poll
24: * </DESC>
25: */
26:
27: #include <stdio.h>
28: #include <string.h>
29:
30: /* somewhat unix-specific */
31: #include <sys/time.h>
32: #include <unistd.h>
33:
34: /* curl stuff */
35: #include <curl/curl.h>
36:
37: int main(void)
38: {
39: CURL *http_handle;
40: CURLM *multi_handle;
41: int still_running = 1; /* keep number of running handles */
42:
43: curl_global_init(CURL_GLOBAL_DEFAULT);
44:
45: http_handle = curl_easy_init();
46:
47: curl_easy_setopt(http_handle, CURLOPT_URL, "https://www.example.com/");
48:
49: multi_handle = curl_multi_init();
50:
51: curl_multi_add_handle(multi_handle, http_handle);
52:
53: while(still_running) {
54: CURLMcode mc; /* curl_multi_poll() return code */
55: int numfds;
56:
57: /* we start some action by calling perform right away */
58: mc = curl_multi_perform(multi_handle, &still_running);
59:
60: if(still_running)
61: /* wait for activity, timeout or "nothing" */
62: mc = curl_multi_poll(multi_handle, NULL, 0, 1000, &numfds);
63:
64: if(mc != CURLM_OK) {
65: fprintf(stderr, "curl_multi_wait() failed, code %d.\n", mc);
66: break;
67: }
68: }
69:
70: curl_multi_remove_handle(multi_handle, http_handle);
71: curl_easy_cleanup(http_handle);
72: curl_multi_cleanup(multi_handle);
73: curl_global_cleanup();
74:
75: return 0;
76: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>