mirror of
https://github.com/curl/curl.git
synced 2026-07-24 00:57:16 +03:00
docs/examples: use curl_multi_poll() in multi examples
The API is soon two years old and deserves being shown as the primary way to drive multi code as it makes it much easier to write code. multi-poll: removed multi-legacy: add to show how we did multi API use before curl_multi_wait/poll. Closes #7352
This commit is contained in:
parent
738fb63e61
commit
ae8e11ed5f
15 changed files with 282 additions and 966 deletions
|
|
@ -5,7 +5,7 @@
|
|||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
|
|
@ -50,9 +50,7 @@ int main(void)
|
|||
{
|
||||
CURL *http_handle;
|
||||
CURLM *multi_handle;
|
||||
|
||||
int still_running = 0; /* keep number of running handles */
|
||||
int repeats = 0;
|
||||
int still_running = 1; /* keep number of running handles */
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
|
|
@ -67,37 +65,18 @@ int main(void)
|
|||
/* add the individual transfers */
|
||||
curl_multi_add_handle(multi_handle, http_handle);
|
||||
|
||||
/* we start some action by calling perform right away */
|
||||
curl_multi_perform(multi_handle, &still_running);
|
||||
|
||||
while(still_running) {
|
||||
CURLMcode mc; /* curl_multi_wait() return code */
|
||||
int numfds;
|
||||
do {
|
||||
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
|
||||
|
||||
/* wait for activity, timeout or "nothing" */
|
||||
mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
|
||||
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
|
||||
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi_wait() failed, code %d.\n", mc);
|
||||
break;
|
||||
}
|
||||
|
||||
/* 'numfds' being zero means either a timeout or no file descriptors to
|
||||
wait for. Try timeout on first occurrence, then assume no file
|
||||
descriptors and no file descriptors to wait for means wait for 100
|
||||
milliseconds. */
|
||||
|
||||
if(!numfds) {
|
||||
repeats++; /* count number of repeated zero numfds */
|
||||
if(repeats > 1) {
|
||||
WAITMS(100); /* sleep 100 milliseconds */
|
||||
}
|
||||
}
|
||||
else
|
||||
repeats = 0;
|
||||
|
||||
curl_multi_perform(multi_handle, &still_running);
|
||||
}
|
||||
} while(still_running);
|
||||
|
||||
curl_multi_remove_handle(multi_handle, http_handle);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue