Imported Upstream version 7.44.0
[platform/upstream/curl.git] / docs / libcurl / curl_multi_perform.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
9 .\" *
10 .\" * This software is licensed as described in the file COPYING, which
11 .\" * you should have received as part of this distribution. The terms
12 .\" * are also available at http://curl.haxx.se/docs/copyright.html.
13 .\" *
14 .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 .\" * copies of the Software, and permit persons to whom the Software is
16 .\" * furnished to do so, under the terms of the COPYING file.
17 .\" *
18 .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 .\" * KIND, either express or implied.
20 .\" *
21 .\" **************************************************************************
22 .TH curl_multi_perform 3 "1 March 2002" "libcurl 7.9.5" "libcurl Manual"
23 .SH NAME
24 curl_multi_perform - reads/writes available data from each easy handle
25 .SH SYNOPSIS
26 #include <curl/curl.h>
27
28 CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles);
29 .ad
30 .SH DESCRIPTION
31 This function handles transfers on all the added handles that need attention
32 in an non-blocking fashion.
33
34 When an application has found out there's data available for the multi_handle
35 or a timeout has elapsed, the application should call this function to
36 read/write whatever there is to read or write right now etc.
37 \fIcurl_multi_perform(3)\fP returns as soon as the reads/writes are done. This
38 function does not require that there actually is any data available for
39 reading or that data can be written, it can be called just in case. It will
40 write the number of handles that still transfer data in the second argument's
41 integer-pointer.
42
43 If the amount of \fIrunning_handles\fP is changed from the previous call (or
44 is less than the amount of easy handles you've added to the multi handle), you
45 know that there is one or more transfers less "running". You can then call
46 \fIcurl_multi_info_read(3)\fP to get information about each individual
47 completed transfer, and that returned info includes CURLcode and more. If an
48 added handle fails very quickly, it may never be counted as a running_handle.
49
50 When \fIrunning_handles\fP is set to zero (0) on the return of this function,
51 there is no longer any transfers in progress.
52 .SH EXAMPLE
53 .nf
54 #ifdef _WIN32
55 #define SHORT_SLEEP Sleep(100)
56 #else
57 #define SHORT_SLEEP usleep(100000)
58 #endif
59
60 fd_set fdread;
61 fd_set fdwrite;
62 fd_set fdexcep;
63 int maxfd = -1;
64
65 long curl_timeo;
66
67 curl_multi_timeout(multi_handle, &curl_timeo);
68 if(curl_timeo < 0)
69   curl_timeo = 1000;
70
71 timeout.tv_sec = curl_timeo / 1000;
72 timeout.tv_usec = (curl_timeo % 1000) * 1000;
73
74 FD_ZERO(&fdread);
75 FD_ZERO(&fdwrite);
76 FD_ZERO(&fdexcep);
77
78 /* get file descriptors from the transfers */
79 mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
80
81 if(maxfd == -1) {
82   SHORT_SLEEP;
83   rc = 0;
84 }
85 else
86   rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
87
88 switch(rc) {
89 case -1:
90   /* select error */
91   break;
92 case 0:
93 default:
94   /* timeout or readable/writable sockets */
95   curl_multi_perform(multi_handle, &still_running);
96   break;
97 }
98
99 /* if there are still transfers, loop! */
100 .fi
101 .SH "RETURN VALUE"
102 CURLMcode type, general libcurl multi interface error code.
103
104 Before version 7.20.0: If you receive \fICURLM_CALL_MULTI_PERFORM\fP, this
105 basically means that you should call \fIcurl_multi_perform(3)\fP again, before
106 you select() on more actions. You don't have to do it immediately, but the
107 return code means that libcurl may have more data available to return or that
108 there may be more data to send off before it is "satisfied". Do note that
109 \fIcurl_multi_perform(3)\fP will return \fICURLM_CALL_MULTI_PERFORM\fP only
110 when it wants to be called again \fBimmediately\fP. When things are fine and
111 there is nothing immediate it wants done, it'll return \fICURLM_OK\fP and you
112 need to wait for \&"action" and then call this function again.
113
114 This function only returns errors etc regarding the whole multi stack.
115 Problems still might have occurred on individual transfers even when this
116 function returns \fICURLM_OK\fP. Use \fIcurl_multi_info_read(3)\fP to figure
117 out how individual transfers did.
118 .SH "TYPICAL USAGE"
119 Most applications will use \fIcurl_multi_fdset(3)\fP to get the multi_handle's
120 file descriptors, and \fIcurl_multi_timeout(3)\fP to get a suitable timeout
121 period, then it'll wait for action on the file descriptors using
122 \fBselect(3)\fP. As soon as one or more file descriptor is ready,
123 \fIcurl_multi_perform(3)\fP gets called.
124 .SH "SEE ALSO"
125 .BR curl_multi_cleanup "(3), " curl_multi_init "(3), "
126 .BR curl_multi_wait "(3), "
127 .BR curl_multi_fdset "(3), " curl_multi_info_read "(3), "
128 .BR libcurl-errors "(3)"