1curl_multi_wait(3) libcurl Manual curl_multi_wait(3)
2
3
4
6 curl_multi_wait - polls on all easy handles in a multi handle
7
9 #include <curl/curl.h>
10
11 CURLMcode curl_multi_wait(CURLM *multi_handle,
12 struct curl_waitfd extra_fds[],
13 unsigned int extra_nfds,
14 int timeout_ms,
15 int *numfds);
16
18 curl_multi_wait(3) polls all file descriptors used by the curl easy
19 handles contained in the given multi handle set. It will block until
20 activity is detected on at least one of the handles or timeout_ms has
21 passed. Alternatively, if the multi handle has a pending internal
22 timeout that has a shorter expiry time than timeout_ms, that shorter
23 time will be used instead to make sure timeout accuracy is reasonably
24 kept.
25
26 The calling application may pass additional curl_waitfd structures
27 which are similar to poll(2)'s pollfd structure to be waited on in the
28 same call.
29
30 On completion, if numfds is non-NULL, it will be populated with the to‐
31 tal number of file descriptors on which interesting events occurred.
32 This number can include both libcurl internal descriptors as well as
33 descriptors provided in extra_fds.
34
35 If no extra file descriptors are provided and libcurl has no file de‐
36 scriptor to offer to wait for, this function will return immediately.
37 (Try curl_multi_poll(3) instead if you rather avoid this behavior.)
38
39 This function is encouraged to be used instead of select(3) when using
40 the multi interface to allow applications to easier circumvent the com‐
41 mon problem with 1024 maximum file descriptors.
42
44 struct curl_waitfd {
45 curl_socket_t fd;
46 short events;
47 short revents;
48 };
49
50 CURL_WAIT_POLLIN
51 Bit flag to curl_waitfd.events indicating the socket should poll
52 on read events such as new data received.
53
54 CURL_WAIT_POLLPRI
55 Bit flag to curl_waitfd.events indicating the socket should poll
56 on high priority read events such as out of band data.
57
58 CURL_WAIT_POLLOUT
59 Bit flag to curl_waitfd.events indicating the socket should poll
60 on write events such as the socket being clear to write without
61 blocking.
62
64 CURL *easy_handle;
65 CURLM *multi_handle;
66
67 /* add the individual easy handle */
68 curl_multi_add_handle(multi_handle, easy_handle);
69
70 do {
71 CURLMcode mc;
72 int numfds;
73
74 mc = curl_multi_perform(multi_handle, &still_running);
75
76 if(mc == CURLM_OK ) {
77 /* wait for activity, timeout or "nothing" */
78 mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
79 }
80
81 if(mc != CURLM_OK) {
82 fprintf(stderr, "curl_multi failed, code %d.\n", mc);
83 break;
84 }
85
86 /* 'numfds' being zero means either a timeout or no file descriptors to
87 wait for. Try timeout on first occurrence, then assume no file
88 descriptors and no file descriptors to wait for means wait for 100
89 milliseconds. */
90
91 if(!numfds) {
92 repeats++; /* count number of repeated zero numfds */
93 if(repeats > 1) {
94 WAITMS(100); /* sleep 100 milliseconds */
95 }
96 }
97 else
98 repeats = 0;
99
100 } while(still_running);
101
102 curl_multi_remove_handle(multi_handle, easy_handle);
103
105 This function was added in libcurl 7.28.0.
106
108 CURLMcode type, general libcurl multi interface error code. See
109 libcurl-errors(3)
110
112 curl_multi_fdset(3), curl_multi_perform(3),curl_multi_poll[1m(3) ,
113
114
115
116libcurl 8.0.1 January 02, 2023 curl_multi_wait(3)