Imported Upstream version 7.59.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 https://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 "February 03, 2016" "libcurl 7.59.0" "libcurl Manual"
23
24 .SH NAME
25 curl_multi_perform - reads/writes available data from each easy handle
26 .SH SYNOPSIS
27 #include <curl/curl.h>
28
29 CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles);
30 .ad
31 .SH DESCRIPTION
32 This function handles transfers on all the added handles that need attention
33 in an non-blocking fashion.
34
35 When an application has found out there's data available for the multi_handle
36 or a timeout has elapsed, the application should call this function to
37 read/write whatever there is to read or write right now etc.
38 \fIcurl_multi_perform(3)\fP returns as soon as the reads/writes are done. This
39 function does not require that there actually is any data available for
40 reading or that data can be written, it can be called just in case. It will
41 write the number of handles that still transfer data in the second argument's
42 integer-pointer.
43
44 If the amount of \fIrunning_handles\fP is changed from the previous call (or
45 is less than the amount of easy handles you've added to the multi handle), you
46 know that there is one or more transfers less "running". You can then call
47 \fIcurl_multi_info_read(3)\fP to get information about each individual
48 completed transfer, and that returned info includes CURLcode and more. If an
49 added handle fails very quickly, it may never be counted as a running_handle.
50
51 When \fIrunning_handles\fP is set to zero (0) on the return of this function,
52 there is no longer any transfers in progress.
53 .SH EXAMPLE
54 .nf
55 #ifdef _WIN32
56 #define SHORT_SLEEP Sleep(100)
57 #else
58 #define SHORT_SLEEP usleep(100000)
59 #endif
60
61 fd_set fdread;
62 fd_set fdwrite;
63 fd_set fdexcep;
64 int maxfd = -1;
65
66 long curl_timeo;
67
68 curl_multi_timeout(multi_handle, &curl_timeo);
69 if(curl_timeo < 0)
70   curl_timeo = 1000;
71
72 timeout.tv_sec = curl_timeo / 1000;
73 timeout.tv_usec = (curl_timeo % 1000) * 1000;
74
75 FD_ZERO(&fdread);
76 FD_ZERO(&fdwrite);
77 FD_ZERO(&fdexcep);
78
79 /* get file descriptors from the transfers */
80 mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
81
82 if(maxfd == -1) {
83   SHORT_SLEEP;
84   rc = 0;
85 }
86 else
87   rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
88
89 switch(rc) {
90 case -1:
91   /* select error */
92   break;
93 case 0:
94 default:
95   /* timeout or readable/writable sockets */
96   curl_multi_perform(multi_handle, &still_running);
97   break;
98 }
99
100 /* if there are still transfers, loop! */
101 .fi
102 .SH "RETURN VALUE"
103 CURLMcode type, general libcurl multi interface error code.
104
105 Before version 7.20.0: If you receive \fICURLM_CALL_MULTI_PERFORM\fP, this
106 basically means that you should call \fIcurl_multi_perform(3)\fP again, before
107 you select() on more actions. You don't have to do it immediately, but the
108 return code means that libcurl may have more data available to return or that
109 there may be more data to send off before it is "satisfied". Do note that
110 \fIcurl_multi_perform(3)\fP will return \fICURLM_CALL_MULTI_PERFORM\fP only
111 when it wants to be called again \fBimmediately\fP. When things are fine and
112 there is nothing immediate it wants done, it'll return \fICURLM_OK\fP and you
113 need to wait for \&"action" and then call this function again.
114
115 This function only returns errors etc regarding the whole multi stack.
116 Problems still might have occurred on individual transfers even when this
117 function returns \fICURLM_OK\fP. Use \fIcurl_multi_info_read(3)\fP to figure
118 out how individual transfers did.
119 .SH "TYPICAL USAGE"
120 Most applications will use \fIcurl_multi_fdset(3)\fP to get the multi_handle's
121 file descriptors, and \fIcurl_multi_timeout(3)\fP to get a suitable timeout
122 period, then it'll wait for action on the file descriptors using
123 \fBselect(3)\fP. As soon as one or more file descriptor is ready,
124 \fIcurl_multi_perform(3)\fP gets called.
125 .SH "SEE ALSO"
126 .BR curl_multi_cleanup "(3), " curl_multi_init "(3), "
127 .BR curl_multi_wait "(3), "
128 .BR curl_multi_fdset "(3), " curl_multi_info_read "(3), "
129 .BR libcurl-errors "(3)"