Imported Upstream version 7.50.2
[platform/upstream/curl.git] / docs / libcurl / curl_multi_perform.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2  "http://www.w3.org/TR/html4/loose.dtd">
3 <html><head>
4 <title>curl_multi_perform man page</title>
5 <meta name="generator" content="roffit">
6 <STYLE type="text/css">
7 pre {
8   overflow: auto;
9   margin: 0;
10 }
11
12 P.level0, pre.level0 {
13  padding-left: 2em;
14 }
15
16 P.level1, pre.level1 {
17  padding-left: 4em;
18 }
19
20 P.level2, pre.level2 {
21  padding-left: 6em;
22 }
23
24 span.emphasis {
25  font-style: italic;
26 }
27
28 span.bold {
29  font-weight: bold;
30 }
31
32 span.manpage {
33  font-weight: bold;
34 }
35
36 h2.nroffsh {
37  background-color: #e0e0e0;
38 }
39
40 span.nroffip {
41  font-weight: bold;
42  font-size: 120%;
43  font-family: monospace;
44 }
45
46 p.roffit {
47  text-align: center;
48  font-size: 80%;
49 }
50 </STYLE>
51 </head><body>
52
53 <p class="level0"><a name="NAME"></a><h2 class="nroffsh">NAME</h2>
54 <p class="level0">curl_multi_perform - reads/writes available data from each easy handle <a name="SYNOPSIS"></a><h2 class="nroffsh">SYNOPSIS</h2>
55 <p class="level0">&#35;include &lt;curl/curl.h&gt; 
56 <p class="level0">CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles); 
57 <p class="level0"><a name="DESCRIPTION"></a><h2 class="nroffsh">DESCRIPTION</h2>
58 <p class="level0">This function handles transfers on all the added handles that need attention in an non-blocking fashion. 
59 <p class="level0">When an application has found out there's data available for the multi_handle or a timeout has elapsed, the application should call this function to read/write whatever there is to read or write right now etc. <a Class="emphasis" href="./curl_multi_perform.html">curl_multi_perform</a> returns as soon as the reads/writes are done. This function does not require that there actually is any data available for reading or that data can be written, it can be called just in case. It will write the number of handles that still transfer data in the second argument's integer-pointer. 
60 <p class="level0">If the amount of <span Class="emphasis">running_handles</span> is changed from the previous call (or is less than the amount of easy handles you've added to the multi handle), you know that there is one or more transfers less "running". You can then call <a Class="emphasis" href="./curl_multi_info_read.html">curl_multi_info_read</a> to get information about each individual completed transfer, and that returned info includes CURLcode and more. If an added handle fails very quickly, it may never be counted as a running_handle. 
61 <p class="level0">When <span Class="emphasis">running_handles</span> is set to zero (0) on the return of this function, there is no longer any transfers in progress. <a name="EXAMPLE"></a><h2 class="nroffsh">EXAMPLE</h2>
62 <p class="level0"><pre class="level0">
63 &#35;ifdef _WIN32
64 &#35;define SHORT_SLEEP Sleep(100)
65 &#35;else
66 &#35;define SHORT_SLEEP usleep(100000)
67 &#35;endif
68 &nbsp;
69 fd_set fdread;
70 fd_set fdwrite;
71 fd_set fdexcep;
72 int maxfd = -1;
73 &nbsp;
74 long curl_timeo;
75 &nbsp;
76 curl_multi_timeout(multi_handle, &curl_timeo);
77 if(curl_timeo &lt; 0)
78 &nbsp; curl_timeo = 1000;
79 &nbsp;
80 timeout.tv_sec = curl_timeo / 1000;
81 timeout.tv_usec = (curl_timeo % 1000) * 1000;
82 &nbsp;
83 FD_ZERO(&fdread);
84 FD_ZERO(&fdwrite);
85 FD_ZERO(&fdexcep);
86 &nbsp;
87 /* get file descriptors from the transfers */
88 mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
89 &nbsp;
90 if(maxfd == -1) {
91 &nbsp; SHORT_SLEEP;
92 &nbsp; rc = 0;
93 }
94 else
95 &nbsp; rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
96 &nbsp;
97 switch(rc) {
98 case -1:
99 &nbsp; /* select error */
100 &nbsp; break;
101 case 0:
102 default:
103 &nbsp; /* timeout or readable/writable sockets */
104 &nbsp; curl_multi_perform(multi_handle, &still_running);
105 &nbsp; break;
106 }
107 &nbsp;
108 /* if there are still transfers, loop! */
109 </pre>
110
111 <p class="level0"><a name="RETURN"></a><h2 class="nroffsh">RETURN VALUE</h2>
112 <p class="level0">CURLMcode type, general libcurl multi interface error code. 
113 <p class="level0">Before version 7.20.0: If you receive <span Class="emphasis">CURLM_CALL_MULTI_PERFORM</span>, this basically means that you should call <a Class="emphasis" href="./curl_multi_perform.html">curl_multi_perform</a> again, before you select() on more actions. You don't have to do it immediately, but the return code means that libcurl may have more data available to return or that there may be more data to send off before it is "satisfied". Do note that <a Class="emphasis" href="./curl_multi_perform.html">curl_multi_perform</a> will return <span Class="emphasis">CURLM_CALL_MULTI_PERFORM</span> only when it wants to be called again <span Class="bold">immediately</span>. When things are fine and there is nothing immediate it wants done, it'll return <span Class="emphasis">CURLM_OK</span> and you need to wait for "action" and then call this function again. 
114 <p class="level0">This function only returns errors etc regarding the whole multi stack. Problems still might have occurred on individual transfers even when this function returns <span Class="emphasis">CURLM_OK</span>. Use <a Class="emphasis" href="./curl_multi_info_read.html">curl_multi_info_read</a> to figure out how individual transfers did. <a name="TYPICAL"></a><h2 class="nroffsh">TYPICAL USAGE</h2>
115 <p class="level0">Most applications will use <a Class="emphasis" href="./curl_multi_fdset.html">curl_multi_fdset</a> to get the multi_handle's file descriptors, and <a Class="emphasis" href="./curl_multi_timeout.html">curl_multi_timeout</a> to get a suitable timeout period, then it'll wait for action on the file descriptors using <span Class="bold">select(3)</span>. As soon as one or more file descriptor is ready, <a Class="emphasis" href="./curl_multi_perform.html">curl_multi_perform</a> gets called. <a name="SEE"></a><h2 class="nroffsh">SEE ALSO</h2>
116 <p class="level0"><a Class="manpage" href="./curl_multi_cleanup.html">curl_multi_cleanup</a>, <a Class="manpage" href="./curl_multi_init.html">curl_multi_init</a>, <a Class="manpage" href="./curl_multi_wait.html">curl_multi_wait</a>, <a Class="manpage" href="./curl_multi_fdset.html">curl_multi_fdset</a>, <a Class="manpage" href="./curl_multi_info_read.html">curl_multi_info_read</a>, <a Class="manpage" href="./libcurl-errors.html">libcurl-errors</a><p class="roffit">
117  This HTML page was made with <a href="http://daniel.haxx.se/projects/roffit/">roffit</a>.
118 </body></html>