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
31 total 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
36 descriptor to offer to wait for, this function will return immediately.
37
38 This function is encouraged to be used instead of select(3) when using
39 the multi interface to allow applications to easier circumvent the com‐
40 mon problem with 1024 maximum file descriptors.
41
43 struct curl_waitfd {
44 curl_socket_t fd;
45 short events;
46 short revents;
47 };
48
49 CURL_WAIT_POLLIN
50 Bit flag to curl_waitfd.events indicating the socket should poll
51 on read events such as new data received.
52
53 CURL_WAIT_POLLPRI
54 Bit flag to curl_waitfd.events indicating the socket should poll
55 on high priority read events such as out of band data.
56
57 CURL_WAIT_POLLOUT
58 Bit flag to curl_waitfd.events indicating the socket should poll
59 on write events such as the socket being clear to write without
60 blocking.
61
63 CURL *easy_handle;
64 CURLM *multi_handle;
65
66 /* add the individual easy handle */
67 curl_multi_add_handle(multi_handle, easy_handle);
68
69 do {
70 CURLMcode mc;
71 int numfds;
72
73 mc = curl_multi_perform(multi_handle, &still_running);
74
75 if(mc == CURLM_OK ) {
76 /* wait for activity, timeout or "nothing" */
77 mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
78 }
79
80 if(mc != CURLM_OK) {
81 fprintf(stderr, "curl_multi failed, code %d.0, mc);
82 break;
83 }
84
85 /* 'numfds' being zero means either a timeout or no file descriptors to
86 wait for. Try timeout on first occurrence, then assume no file
87 descriptors and no file descriptors to wait for means wait for 100
88 milliseconds. */
89
90 if(!numfds) {
91 repeats++; /* count number of repeated zero numfds */
92 if(repeats > 1) {
93 WAITMS(100); /* sleep 100 milliseconds */
94 }
95 }
96 else
97 repeats = 0;
98
99 } while(still_running);
100
101 curl_multi_remove_handle(multi_handle, easy_handle);
102
104 CURLMcode type, general libcurl multi interface error code. See
105 libcurl-errors(3)
106
108 This function was added in libcurl 7.28.0.
109
111 curl_multi_fdset(3), curl_multi_perform(3)
112
113
114
115libcurl 7.64.0 March 09, 2016 curl_multi_wait(3)