curl_multi_perform.3: polish wording

- simplify the example by using curl_multi_poll

 - mention curl_multi_add_handle in the text

 - cut out the description of pre-7.20.0 return code behavior - that version
   is now more than eleven years old and is basically no longer out there

 - adjust the "typical usage" to mention curl_multi_poll

Closes #7883
This commit is contained in:
Daniel Stenberg 2021-10-20 08:49:17 +02:00
parent 671bf7991a
commit 47c4f7b255
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -5,7 +5,7 @@
.\" * | (__| |_| | _ <| |___
.\" * \___|\___/|_| \_\_____|
.\" *
.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
.\" *
.\" * This software is licensed as described in the file COPYING, which
.\" * you should have received as part of this distribution. The terms
@ -28,8 +28,9 @@ curl_multi_perform - reads/writes available data from each easy handle
CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles);
.ad
.SH DESCRIPTION
This function handles transfers on all the added handles that need attention
in an non-blocking fashion.
This function performs transfers on all the added handles that need attention
in an non-blocking fashion. The easy handles have previously been added to the
multi handle with \fIcurl_multi_add_handle(3)\fP.
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
@ -37,7 +38,7 @@ read/write whatever there is to read or write right now etc.
\fIcurl_multi_perform(3)\fP 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
store the number of handles that still transfer data in the second argument's
integer-pointer.
If the amount of \fIrunning_handles\fP is changed from the previous call (or
@ -53,78 +54,36 @@ When \fIrunning_handles\fP is set to zero (0) on the return of this function,
there is no longer any transfers in progress.
.SH EXAMPLE
.nf
#ifdef _WIN32
#define SHORT_SLEEP Sleep(100)
#else
#define SHORT_SLEEP usleep(100000)
#endif
int still_running;
do {
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd = -1;
if(!mc && still_running)
/* wait for activity, timeout or "nothing" */
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
long curl_timeo;
curl_multi_timeout(multi_handle, &curl_timeo);
if(curl_timeo < 0)
curl_timeo = 1000;
timeout.tv_sec = curl_timeo / 1000;
timeout.tv_usec = (curl_timeo % 1000) * 1000;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
/* get file descriptors from the transfers */
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if(maxfd == -1) {
SHORT_SLEEP;
rc = 0;
}
else
rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
switch(rc) {
case -1:
/* select error */
break;
case 0:
default:
/* timeout or readable/writable sockets */
curl_multi_perform(multi_handle, &still_running);
break;
}
if(mc) {
fprintf(stderr, "curl_multi_poll() failed, code %d.\n", (int)mc);
break;
}
/* if there are still transfers, loop! */
} while(still_running);
.fi
.SH "RETURN VALUE"
CURLMcode type, general libcurl multi interface error code.
Before version 7.20.0 (released on February 9 2010): If you receive \fICURLM_CALL_MULTI_PERFORM\fP, this
basically means that you should call \fIcurl_multi_perform(3)\fP 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
\fIcurl_multi_perform(3)\fP will return \fICURLM_CALL_MULTI_PERFORM\fP only
when it wants to be called again \fBimmediately\fP. When things are fine and
there is nothing immediate it wants done, it'll return \fICURLM_OK\fP and you
need to wait for \&"action" and then call this function again.
This function only returns errors etc regarding the whole multi stack.
Problems still might have occurred on individual transfers even when this
function returns \fICURLM_OK\fP. Use \fIcurl_multi_info_read(3)\fP to figure
out how individual transfers did.
This function returns errors regarding the whole multi stack. Problems on
individual transfers may have occurred even when this function returns
\fICURLM_OK\fP. Use \fIcurl_multi_info_read(3)\fP to figure out how individual
transfers did.
.SH "TYPICAL USAGE"
Most applications will use \fIcurl_multi_fdset(3)\fP to get the multi_handle's
file descriptors, and \fIcurl_multi_timeout(3)\fP to get a suitable timeout
period, then it'll wait for action on the file descriptors using
\fBselect(3)\fP. As soon as one or more file descriptor is ready,
\fIcurl_multi_perform(3)\fP gets called.
Most applications will use \fIcurl_multi_poll(3)\fP to make libcurl wait for
activity on any of the ongoing transfers. As soon as one or more file
descriptor has activity or the function times out, the application calls
\fIcurl_multi_perform(3)\fP.
.SH "SEE ALSO"
.BR curl_multi_cleanup "(3), " curl_multi_init "(3), "
.BR curl_multi_wait "(3), "
.BR curl_multi_wait "(3), " curl_multi_add_handle "(3), "
.BR curl_multi_fdset "(3), " curl_multi_info_read "(3), "
.BR libcurl-errors "(3)"