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