1--- 2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al. 3SPDX-License-Identifier: curl 4Title: curl_multi_poll 5Section: 3 6Source: libcurl 7See-also: 8 - curl_multi_fdset (3) 9 - curl_multi_perform (3) 10 - curl_multi_wait (3) 11 - curl_multi_wakeup (3) 12--- 13 14# NAME 15 16curl_multi_poll - polls on all easy handles in a multi handle 17 18# SYNOPSIS 19 20~~~c 21#include <curl/curl.h> 22 23CURLMcode curl_multi_poll(CURLM *multi_handle, 24 struct curl_waitfd extra_fds[], 25 unsigned int extra_nfds, 26 int timeout_ms, 27 int *numfds); 28~~~ 29 30# DESCRIPTION 31 32curl_multi_poll(3) polls all file descriptors used by the curl easy 33handles contained in the given multi handle set. It blocks until activity is 34detected on at least one of the handles or *timeout_ms* has passed. 35Alternatively, if the multi handle has a pending internal timeout that has a 36shorter expiry time than *timeout_ms*, that shorter time is used instead 37to make sure timeout accuracy is reasonably kept. 38 39The calling application may pass additional curl_waitfd structures which are 40similar to *poll(2)*'s *pollfd* structure to be waited on in the same 41call. 42 43On completion, if *numfds* is non-NULL, it gets populated with the total 44number of file descriptors on which interesting events occurred. This number 45can include both libcurl internal descriptors as well as descriptors provided 46in *extra_fds*. 47 48The curl_multi_wakeup(3) function can be used from another thread to 49wake up this function and return faster. This is one of the details 50that makes this function different than curl_multi_wait(3) which cannot 51be woken up this way. 52 53If no extra file descriptors are provided and libcurl has no file descriptor 54to offer to wait for, this function instead waits during *timeout_ms* 55milliseconds (or shorter if an internal timer indicates so). This is the other 56detail that makes this function different than curl_multi_wait(3). 57 58This function is encouraged to be used instead of select(3) when using the 59multi interface to allow applications to easier circumvent the common problem 60with 1024 maximum file descriptors. 61 62# curl_waitfd 63 64~~~c 65struct curl_waitfd { 66 curl_socket_t fd; 67 short events; 68 short revents; 69}; 70~~~ 71 72## CURL_WAIT_POLLIN 73 74Bit flag to curl_waitfd.events indicating the socket should poll on read 75events such as new data received. 76 77## CURL_WAIT_POLLPRI 78 79Bit flag to curl_waitfd.events indicating the socket should poll on high 80priority read events such as out of band data. 81 82## CURL_WAIT_POLLOUT 83 84Bit flag to curl_waitfd.events indicating the socket should poll on write 85events such as the socket being clear to write without blocking. 86 87# EXAMPLE 88 89~~~c 90int main(void) 91{ 92 CURL *easy_handle; 93 CURLM *multi_handle; 94 int still_running = 0; 95 96 /* add the individual easy handle */ 97 curl_multi_add_handle(multi_handle, easy_handle); 98 99 do { 100 CURLMcode mc; 101 int numfds; 102 103 mc = curl_multi_perform(multi_handle, &still_running); 104 105 if(mc == CURLM_OK) { 106 /* wait for activity or timeout */ 107 mc = curl_multi_poll(multi_handle, NULL, 0, 1000, &numfds); 108 } 109 110 if(mc != CURLM_OK) { 111 fprintf(stderr, "curl_multi failed, code %d.\n", mc); 112 break; 113 } 114 115 } while(still_running); 116 117 curl_multi_remove_handle(multi_handle, easy_handle); 118} 119~~~ 120 121# AVAILABILITY 122 123Added in 7.66.0. 124 125# RETURN VALUE 126 127CURLMcode type, general libcurl multi interface error code. See 128libcurl-errors(3) 129