| 1 |
.\" ************************************************************************** |
| 2 |
.\" * _ _ ____ _ |
| 3 |
.\" * Project ___| | | | _ \| | |
| 4 |
.\" * / __| | | | |_) | | |
| 5 |
.\" * | (__| |_| | _ <| |___ |
| 6 |
.\" * \___|\___/|_| \_\_____| |
| 7 |
.\" * |
| 8 |
.\" * Copyright (C) 1998 - 2019, Daniel Stenberg, <[email protected]>, 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 "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 |
You could use \fIcurl_multi_info_read(3)\fP to track actual status of the |
| 50 |
added handles in that case. |
| 51 |
|
| 52 |
When \fIrunning_handles\fP is set to zero (0) on the return of this function, |
| 53 |
there is no longer any transfers in progress. |
| 54 |
.SH EXAMPLE |
| 55 |
.nf |
| 56 |
#ifdef _WIN32 |
| 57 |
#define SHORT_SLEEP Sleep(100) |
| 58 |
#else |
| 59 |
#define SHORT_SLEEP usleep(100000) |
| 60 |
#endif |
| 61 |
|
| 62 |
fd_set fdread; |
| 63 |
fd_set fdwrite; |
| 64 |
fd_set fdexcep; |
| 65 |
int maxfd = -1; |
| 66 |
|
| 67 |
long curl_timeo; |
| 68 |
|
| 69 |
curl_multi_timeout(multi_handle, &curl_timeo); |
| 70 |
if(curl_timeo < 0) |
| 71 |
curl_timeo = 1000; |
| 72 |
|
| 73 |
timeout.tv_sec = curl_timeo / 1000; |
| 74 |
timeout.tv_usec = (curl_timeo % 1000) * 1000; |
| 75 |
|
| 76 |
FD_ZERO(&fdread); |
| 77 |
FD_ZERO(&fdwrite); |
| 78 |
FD_ZERO(&fdexcep); |
| 79 |
|
| 80 |
/* get file descriptors from the transfers */ |
| 81 |
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); |
| 82 |
|
| 83 |
if(maxfd == -1) { |
| 84 |
SHORT_SLEEP; |
| 85 |
rc = 0; |
| 86 |
} |
| 87 |
else |
| 88 |
rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); |
| 89 |
|
| 90 |
switch(rc) { |
| 91 |
case -1: |
| 92 |
/* select error */ |
| 93 |
break; |
| 94 |
case 0: |
| 95 |
default: |
| 96 |
/* timeout or readable/writable sockets */ |
| 97 |
curl_multi_perform(multi_handle, &still_running); |
| 98 |
break; |
| 99 |
} |
| 100 |
|
| 101 |
/* if there are still transfers, loop! */ |
| 102 |
.fi |
| 103 |
.SH "RETURN VALUE" |
| 104 |
CURLMcode type, general libcurl multi interface error code. |
| 105 |
|
| 106 |
Before version 7.20.0: If you receive \fICURLM_CALL_MULTI_PERFORM\fP, this |
| 107 |
basically means that you should call \fIcurl_multi_perform(3)\fP again, before |
| 108 |
you select() on more actions. You don't have to do it immediately, but the |
| 109 |
return code means that libcurl may have more data available to return or that |
| 110 |
there may be more data to send off before it is "satisfied". Do note that |
| 111 |
\fIcurl_multi_perform(3)\fP will return \fICURLM_CALL_MULTI_PERFORM\fP only |
| 112 |
when it wants to be called again \fBimmediately\fP. When things are fine and |
| 113 |
there is nothing immediate it wants done, it'll return \fICURLM_OK\fP and you |
| 114 |
need to wait for \&"action" and then call this function again. |
| 115 |
|
| 116 |
This function only returns errors etc regarding the whole multi stack. |
| 117 |
Problems still might have occurred on individual transfers even when this |
| 118 |
function returns \fICURLM_OK\fP. Use \fIcurl_multi_info_read(3)\fP to figure |
| 119 |
out how individual transfers did. |
| 120 |
.SH "TYPICAL USAGE" |
| 121 |
Most applications will use \fIcurl_multi_fdset(3)\fP to get the multi_handle's |
| 122 |
file descriptors, and \fIcurl_multi_timeout(3)\fP to get a suitable timeout |
| 123 |
period, then it'll wait for action on the file descriptors using |
| 124 |
\fBselect(3)\fP. As soon as one or more file descriptor is ready, |
| 125 |
\fIcurl_multi_perform(3)\fP gets called. |
| 126 |
.SH "SEE ALSO" |
| 127 |
.BR curl_multi_cleanup "(3), " curl_multi_init "(3), " |
| 128 |
.BR curl_multi_wait "(3), " |
| 129 |
.BR curl_multi_fdset "(3), " curl_multi_info_read "(3), " |
| 130 |
.BR libcurl-errors "(3)" |