1--- 2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al. 3SPDX-License-Identifier: curl 4Title: curl_multi_perform 5Section: 3 6Source: libcurl 7See-also: 8 - curl_multi_add_handle (3) 9 - curl_multi_cleanup (3) 10 - curl_multi_fdset (3) 11 - curl_multi_info_read (3) 12 - curl_multi_init (3) 13 - curl_multi_wait (3) 14 - libcurl-errors (3) 15--- 16 17# NAME 18 19curl_multi_perform - reads/writes available data from easy handles 20 21# SYNOPSIS 22 23~~~c 24#include <curl/curl.h> 25 26CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles); 27~~~ 28 29# DESCRIPTION 30 31This function performs transfers on all the added handles that need attention 32in a non-blocking fashion. The easy handles have previously been added to the 33multi handle with curl_multi_add_handle(3). 34 35When an application has found out there is data available for the multi_handle 36or a timeout has elapsed, the application should call this function to 37read/write whatever there is to read or write right now etc. 38curl_multi_perform(3) returns as soon as the reads/writes are done. This 39function does not require that there actually is any data available for 40reading or that data can be written, it can be called just in case. It stores 41the number of handles that still transfer data in the second argument's 42integer-pointer. 43 44If the amount of *running_handles* is changed from the previous call (or 45is less than the amount of easy handles you have added to the multi handle), 46you know that there is one or more transfers less "running". You can then call 47curl_multi_info_read(3) to get information about each individual 48completed transfer, and that returned info includes CURLcode and more. If an 49added handle fails quickly, it may never be counted as a running_handle. You 50could use curl_multi_info_read(3) to track actual status of the added 51handles in that case. 52 53When *running_handles* is set to zero (0) on the return of this function, 54there is no longer any transfers in progress. 55 56When this function returns error, the state of all transfers are uncertain and 57they cannot be continued. curl_multi_perform(3) should not be called 58again on the same multi handle after an error has been returned, unless first 59removing all the handles and adding new ones. 60 61# EXAMPLE 62 63~~~c 64int main(void) 65{ 66 int still_running; 67 CURL *multi = curl_multi_init(); 68 CURL *curl = curl_easy_init(); 69 if(curl) { 70 curl_multi_add_handle(multi, curl); 71 do { 72 CURLMcode mc = curl_multi_perform(multi, &still_running); 73 74 if(!mc && still_running) 75 /* wait for activity, timeout or "nothing" */ 76 mc = curl_multi_poll(multi, NULL, 0, 1000, NULL); 77 78 if(mc) { 79 fprintf(stderr, "curl_multi_poll() failed, code %d.\n", (int)mc); 80 break; 81 } 82 83 /* if there are still transfers, loop! */ 84 } while(still_running); 85 } 86} 87~~~ 88 89# AVAILABILITY 90 91Added in 7.9.6 92 93# RETURN VALUE 94 95CURLMcode type, general libcurl multi interface error code. 96 97This function returns errors regarding the whole multi stack. Problems on 98individual transfers may have occurred even when this function returns 99*CURLM_OK*. Use curl_multi_info_read(3) to figure out how individual 100transfers did. 101 102# TYPICAL USAGE 103 104Most applications use curl_multi_poll(3) to make libcurl wait for 105activity on any of the ongoing transfers. As soon as one or more file 106descriptor has activity or the function times out, the application calls 107curl_multi_perform(3). 108