2024-01-17 18:32:44 +08:00
|
|
|
---
|
2024-02-28 18:28:10 +08:00
|
|
|
c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2024-01-17 18:32:44 +08:00
|
|
|
SPDX-License-Identifier: curl
|
|
|
|
Title: curl_multi_poll
|
|
|
|
Section: 3
|
|
|
|
Source: libcurl
|
|
|
|
See-also:
|
|
|
|
- curl_multi_fdset (3)
|
|
|
|
- curl_multi_perform (3)
|
|
|
|
- curl_multi_wait (3)
|
|
|
|
- curl_multi_wakeup (3)
|
2024-03-21 18:50:20 +08:00
|
|
|
Protocol:
|
2024-03-23 06:48:54 +08:00
|
|
|
- All
|
2024-01-17 18:32:44 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
# NAME
|
|
|
|
|
2019-07-29 19:41:00 +08:00
|
|
|
curl_multi_poll - polls on all easy handles in a multi handle
|
2024-01-17 18:32:44 +08:00
|
|
|
|
|
|
|
# SYNOPSIS
|
|
|
|
|
|
|
|
~~~c
|
2019-07-29 19:41:00 +08:00
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
CURLMcode curl_multi_poll(CURLM *multi_handle,
|
|
|
|
struct curl_waitfd extra_fds[],
|
|
|
|
unsigned int extra_nfds,
|
|
|
|
int timeout_ms,
|
|
|
|
int *numfds);
|
2024-01-17 18:32:44 +08:00
|
|
|
~~~
|
|
|
|
|
|
|
|
# DESCRIPTION
|
|
|
|
|
|
|
|
curl_multi_poll(3) polls all file descriptors used by the curl easy
|
2023-08-22 23:40:39 +08:00
|
|
|
handles contained in the given multi handle set. It blocks until activity is
|
2024-01-17 18:32:44 +08:00
|
|
|
detected on at least one of the handles or *timeout_ms* has passed.
|
2019-07-29 19:41:00 +08:00
|
|
|
Alternatively, if the multi handle has a pending internal timeout that has a
|
2024-01-17 18:32:44 +08:00
|
|
|
shorter expiry time than *timeout_ms*, that shorter time is used instead
|
2023-08-22 23:40:39 +08:00
|
|
|
to make sure timeout accuracy is reasonably kept.
|
2019-07-29 19:41:00 +08:00
|
|
|
|
|
|
|
The calling application may pass additional curl_waitfd structures which are
|
2024-01-17 18:32:44 +08:00
|
|
|
similar to *poll(2)*'s *pollfd* structure to be waited on in the same
|
2022-09-21 05:30:19 +08:00
|
|
|
call.
|
2019-07-29 19:41:00 +08:00
|
|
|
|
2024-01-17 18:32:44 +08:00
|
|
|
On completion, if *numfds* is non-NULL, it gets populated with the total
|
2023-08-22 23:40:39 +08:00
|
|
|
number of file descriptors on which interesting events occurred. This number
|
|
|
|
can include both libcurl internal descriptors as well as descriptors provided
|
2024-01-17 18:32:44 +08:00
|
|
|
in *extra_fds*.
|
2019-07-29 19:41:00 +08:00
|
|
|
|
2024-01-17 18:32:44 +08:00
|
|
|
The curl_multi_wakeup(3) function can be used from another thread to
|
2019-11-17 22:12:15 +08:00
|
|
|
wake up this function and return faster. This is one of the details
|
2024-01-17 18:32:44 +08:00
|
|
|
that makes this function different than curl_multi_wait(3) which cannot
|
2019-11-17 22:12:15 +08:00
|
|
|
be woken up this way.
|
|
|
|
|
2019-07-29 19:41:00 +08:00
|
|
|
If no extra file descriptors are provided and libcurl has no file descriptor
|
2024-01-17 18:32:44 +08:00
|
|
|
to offer to wait for, this function instead waits during *timeout_ms*
|
2023-08-22 23:40:39 +08:00
|
|
|
milliseconds (or shorter if an internal timer indicates so). This is the other
|
2024-01-17 18:32:44 +08:00
|
|
|
detail that makes this function different than curl_multi_wait(3).
|
2019-07-29 19:41:00 +08:00
|
|
|
|
|
|
|
This function is encouraged to be used instead of select(3) when using the
|
|
|
|
multi interface to allow applications to easier circumvent the common problem
|
|
|
|
with 1024 maximum file descriptors.
|
2024-01-17 18:32:44 +08:00
|
|
|
|
|
|
|
# curl_waitfd
|
|
|
|
|
|
|
|
~~~c
|
2019-07-29 19:41:00 +08:00
|
|
|
struct curl_waitfd {
|
|
|
|
curl_socket_t fd;
|
|
|
|
short events;
|
|
|
|
short revents;
|
|
|
|
};
|
2024-01-17 18:32:44 +08:00
|
|
|
~~~
|
|
|
|
|
|
|
|
## CURL_WAIT_POLLIN
|
|
|
|
|
2019-07-29 19:41:00 +08:00
|
|
|
Bit flag to curl_waitfd.events indicating the socket should poll on read
|
|
|
|
events such as new data received.
|
2024-01-17 18:32:44 +08:00
|
|
|
|
|
|
|
## CURL_WAIT_POLLPRI
|
|
|
|
|
2019-07-29 19:41:00 +08:00
|
|
|
Bit flag to curl_waitfd.events indicating the socket should poll on high
|
|
|
|
priority read events such as out of band data.
|
2024-01-17 18:32:44 +08:00
|
|
|
|
|
|
|
## CURL_WAIT_POLLOUT
|
|
|
|
|
2019-07-29 19:41:00 +08:00
|
|
|
Bit flag to curl_waitfd.events indicating the socket should poll on write
|
|
|
|
events such as the socket being clear to write without blocking.
|
2024-01-17 18:32:44 +08:00
|
|
|
|
|
|
|
# EXAMPLE
|
|
|
|
|
|
|
|
~~~c
|
2023-12-04 17:50:42 +08:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
CURL *easy_handle;
|
|
|
|
CURLM *multi_handle;
|
|
|
|
int still_running = 0;
|
2019-07-29 19:41:00 +08:00
|
|
|
|
2023-12-04 17:50:42 +08:00
|
|
|
/* add the individual easy handle */
|
|
|
|
curl_multi_add_handle(multi_handle, easy_handle);
|
2019-07-29 19:41:00 +08:00
|
|
|
|
2023-12-04 17:50:42 +08:00
|
|
|
do {
|
|
|
|
CURLMcode mc;
|
|
|
|
int numfds;
|
2019-07-29 19:41:00 +08:00
|
|
|
|
2023-12-04 17:50:42 +08:00
|
|
|
mc = curl_multi_perform(multi_handle, &still_running);
|
2019-07-29 19:41:00 +08:00
|
|
|
|
2023-12-04 17:50:42 +08:00
|
|
|
if(mc == CURLM_OK) {
|
|
|
|
/* wait for activity or timeout */
|
|
|
|
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, &numfds);
|
|
|
|
}
|
2019-07-29 19:41:00 +08:00
|
|
|
|
2023-12-04 17:50:42 +08:00
|
|
|
if(mc != CURLM_OK) {
|
2024-01-17 18:32:44 +08:00
|
|
|
fprintf(stderr, "curl_multi failed, code %d.\n", mc);
|
2023-12-04 17:50:42 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-07-29 19:41:00 +08:00
|
|
|
|
2023-12-04 17:50:42 +08:00
|
|
|
} while(still_running);
|
2019-07-29 19:41:00 +08:00
|
|
|
|
2023-12-04 17:50:42 +08:00
|
|
|
curl_multi_remove_handle(multi_handle, easy_handle);
|
|
|
|
}
|
2024-01-17 18:32:44 +08:00
|
|
|
~~~
|
|
|
|
|
|
|
|
# AVAILABILITY
|
|
|
|
|
2021-10-25 17:45:09 +08:00
|
|
|
Added in 7.66.0.
|
2024-01-17 18:32:44 +08:00
|
|
|
|
|
|
|
# RETURN VALUE
|
|
|
|
|
2019-07-29 19:41:00 +08:00
|
|
|
CURLMcode type, general libcurl multi interface error code. See
|
2024-01-17 18:32:44 +08:00
|
|
|
libcurl-errors(3)
|