1curl_multi_poll(3) libcurl Manual curl_multi_poll(3)
2
3
4
6 curl_multi_poll - polls on all easy handles in a multi handle
7
9 #include <curl/curl.h>
10
11 CURLMcode curl_multi_poll(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_poll(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 instead wait during
37 timeout_ms milliseconds (or shorter if an internal timer indicates so).
38 This is the detail that makes this function different than
39 curl_multi_wait(3).
40
41 This function is encouraged to be used instead of select(3) when using
42 the multi interface to allow applications to easier circumvent the com‐
43 mon problem with 1024 maximum file descriptors.
44
46 struct curl_waitfd {
47 curl_socket_t fd;
48 short events;
49 short revents;
50 };
51
52 CURL_WAIT_POLLIN
53 Bit flag to curl_waitfd.events indicating the socket should poll
54 on read events such as new data received.
55
56 CURL_WAIT_POLLPRI
57 Bit flag to curl_waitfd.events indicating the socket should poll
58 on high priority read events such as out of band data.
59
60 CURL_WAIT_POLLOUT
61 Bit flag to curl_waitfd.events indicating the socket should poll
62 on write events such as the socket being clear to write without
63 blocking.
64
66 CURL *easy_handle;
67 CURLM *multi_handle;
68
69 /* add the individual easy handle */
70 curl_multi_add_handle(multi_handle, easy_handle);
71
72 do {
73 CURLMcode mc;
74 int numfds;
75
76 mc = curl_multi_perform(multi_handle, &still_running);
77
78 if(mc == CURLM_OK) {
79 /* wait for activity or timeout */
80 mc = curl_multi_poll(multi_handle, NULL, 0, 1000, &numfds);
81 }
82
83 if(mc != CURLM_OK) {
84 fprintf(stderr, "curl_multi failed, code %d.\n", mc);
85 break;
86 }
87
88 } while(still_running);
89
90 curl_multi_remove_handle(multi_handle, easy_handle);
91
93 CURLMcode type, general libcurl multi interface error code. See
94 libcurl-errors(3)
95
97 This function was added in libcurl 7.66.0.
98
100 curl_multi_fdset(3), curl_multi_perform(3), curl_multi_wait(3)
101
102
103
104libcurl 7.66.0 July 29, 2019 curl_multi_poll(3)