1curl_multi_perform(3)           libcurl Manual           curl_multi_perform(3)
2
3
4

NAME

6       curl_multi_perform - reads/writes available data from each easy handle
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLMcode  curl_multi_perform(CURLM  *multi_handle,  int  *running_han‐
12       dles);
13

DESCRIPTION

15       This function handles transfers on all the added handles that need  at‐
16       tention in an non-blocking fashion.
17
18       When  an  application  has  found  out  there's  data available for the
19       multi_handle or a timeout has elapsed, the application should call this
20       function  to  read/write  whatever  there is to read or write right now
21       etc.  curl_multi_perform(3) returns as soon  as  the  reads/writes  are
22       done.  This  function  does not require that there actually is any data
23       available for reading or that data can be written,  it  can  be  called
24       just  in  case. It will write the number of handles that still transfer
25       data in the second argument's integer-pointer.
26
27       If the amount of running_handles is changed from the previous call  (or
28       is  less than the amount of easy handles you've added to the multi han‐
29       dle), you know that there is one or more transfers less "running".  You
30       can then call curl_multi_info_read(3) to get information about each in‐
31       dividual completed transfer, and that returned info  includes  CURLcode
32       and  more.  If  an  added  handle  fails  very quickly, it may never be
33       counted as a running_handle.  You could use curl_multi_info_read(3)  to
34       track actual status of the added handles in that case.
35
36       When running_handles is set to zero (0) on the return of this function,
37       there is no longer any transfers in progress.
38

EXAMPLE

40       #ifdef _WIN32
41       #define SHORT_SLEEP Sleep(100)
42       #else
43       #define SHORT_SLEEP usleep(100000)
44       #endif
45
46       fd_set fdread;
47       fd_set fdwrite;
48       fd_set fdexcep;
49       int maxfd = -1;
50
51       long curl_timeo;
52
53       curl_multi_timeout(multi_handle, &curl_timeo);
54       if(curl_timeo < 0)
55         curl_timeo = 1000;
56
57       timeout.tv_sec = curl_timeo / 1000;
58       timeout.tv_usec = (curl_timeo % 1000) * 1000;
59
60       FD_ZERO(&fdread);
61       FD_ZERO(&fdwrite);
62       FD_ZERO(&fdexcep);
63
64       /* get file descriptors from the transfers */
65       mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
66
67       if(maxfd == -1) {
68         SHORT_SLEEP;
69         rc = 0;
70       }
71       else
72         rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
73
74       switch(rc) {
75       case -1:
76         /* select error */
77         break;
78       case 0:
79       default:
80         /* timeout or readable/writable sockets */
81         curl_multi_perform(multi_handle, &still_running);
82         break;
83       }
84
85       /* if there are still transfers, loop! */
86

RETURN VALUE

88       CURLMcode type, general libcurl multi interface error code.
89
90       Before version 7.20.0 (released on February 9  2010):  If  you  receive
91       CURLM_CALL_MULTI_PERFORM,  this  basically  means  that you should call
92       curl_multi_perform(3) again, before you select() on more  actions.  You
93       don't have to do it immediately, but the return code means that libcurl
94       may have more data available to return or that there may be  more  data
95       to  send  off  before  it  is "satisfied". Do note that curl_multi_per‐
96       form(3) will return CURLM_CALL_MULTI_PERFORM only when it wants  to  be
97       called again immediately. When things are fine and there is nothing im‐
98       mediate it wants done, it'll return CURLM_OK and you need to  wait  for
99       "action" and then call this function again.
100
101       This  function only returns errors etc regarding the whole multi stack.
102       Problems still might have occurred on individual  transfers  even  when
103       this  function  returns CURLM_OK. Use curl_multi_info_read(3) to figure
104       out how individual transfers did.
105

TYPICAL USAGE

107       Most applications will use curl_multi_fdset(3) to  get  the  multi_han‐
108       dle's  file  descriptors,  and  curl_multi_timeout(3) to get a suitable
109       timeout period, then it'll wait for action on the file descriptors  us‐
110       ing  select(3).  As  soon  as  one  or  more  file descriptor is ready,
111       curl_multi_perform(3) gets called.
112

SEE ALSO

114       curl_multi_cleanup(3),     curl_multi_init(3),      curl_multi_wait(3),
115       curl_multi_fdset(3), curl_multi_info_read(3), libcurl-errors(3)
116
117
118
119libcurl 7.76.1                 November 04, 2020         curl_multi_perform(3)
Impressum