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
16       attention 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
31       individual 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.
34
35       When running_handles is set to zero (0) on the return of this function,
36       there is no longer any transfers in progress.
37

EXAMPLE

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

RETURN VALUE

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

TYPICAL USAGE

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

SEE ALSO

113       curl_multi_cleanup(3),      curl_multi_init(3),     curl_multi_wait(3),
114       curl_multi_fdset(3), curl_multi_info_read(3), libcurl-errors(3)
115
116
117
118libcurl 7.61.1                 February 03, 2016         curl_multi_perform(3)
Impressum