| 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_wait 3 "12 Jul 2012" "libcurl 7.28.0" "libcurl Manual" |
| 23 |
.SH NAME |
| 24 |
curl_multi_wait - polls on all easy handles in a multi handle |
| 25 |
.SH SYNOPSIS |
| 26 |
.nf |
| 27 |
#include <curl/curl.h> |
| 28 |
|
| 29 |
CURLMcode curl_multi_wait(CURLM *multi_handle, |
| 30 |
struct curl_waitfd extra_fds[], |
| 31 |
unsigned int extra_nfds, |
| 32 |
int timeout_ms, |
| 33 |
int *numfds); |
| 34 |
.ad |
| 35 |
.SH DESCRIPTION |
| 36 |
\fIcurl_multi_wait(3)\fP polls all file descriptors used by the curl easy |
| 37 |
handles contained in the given multi handle set. It will block until activity |
| 38 |
is detected on at least one of the handles or \fItimeout_ms\fP has passed. |
| 39 |
Alternatively, if the multi handle has a pending internal timeout that has a |
| 40 |
shorter expiry time than \fItimeout_ms\fP, that shorter time will be used |
| 41 |
instead to make sure timeout accuracy is reasonably kept. |
| 42 |
|
| 43 |
The calling application may pass additional curl_waitfd structures which are |
| 44 |
similar to \fIpoll(2)\fP's pollfd structure to be waited on in the same call. |
| 45 |
|
| 46 |
On completion, if \fInumfds\fP is non-NULL, it will be populated with the |
| 47 |
total number of file descriptors on which interesting events occurred. This |
| 48 |
number can include both libcurl internal descriptors as well as descriptors |
| 49 |
provided in \fIextra_fds\fP. |
| 50 |
|
| 51 |
If no extra file descriptors are provided and libcurl has no file descriptor |
| 52 |
to offer to wait for, this function will return immediately. (Try |
| 53 |
\fIcurl_multi_poll(3)\fP instead if you rather avoid this behavior.) |
| 54 |
|
| 55 |
This function is encouraged to be used instead of select(3) when using the |
| 56 |
multi interface to allow applications to easier circumvent the common problem |
| 57 |
with 1024 maximum file descriptors. |
| 58 |
.SH curl_waitfd |
| 59 |
.nf |
| 60 |
struct curl_waitfd { |
| 61 |
curl_socket_t fd; |
| 62 |
short events; |
| 63 |
short revents; |
| 64 |
}; |
| 65 |
.fi |
| 66 |
.IP CURL_WAIT_POLLIN |
| 67 |
Bit flag to curl_waitfd.events indicating the socket should poll on read |
| 68 |
events such as new data received. |
| 69 |
.IP CURL_WAIT_POLLPRI |
| 70 |
Bit flag to curl_waitfd.events indicating the socket should poll on high |
| 71 |
priority read events such as out of band data. |
| 72 |
.IP CURL_WAIT_POLLOUT |
| 73 |
Bit flag to curl_waitfd.events indicating the socket should poll on write |
| 74 |
events such as the socket being clear to write without blocking. |
| 75 |
.SH EXAMPLE |
| 76 |
.nf |
| 77 |
CURL *easy_handle; |
| 78 |
CURLM *multi_handle; |
| 79 |
|
| 80 |
/* add the individual easy handle */ |
| 81 |
curl_multi_add_handle(multi_handle, easy_handle); |
| 82 |
|
| 83 |
do { |
| 84 |
CURLMcode mc; |
| 85 |
int numfds; |
| 86 |
|
| 87 |
mc = curl_multi_perform(multi_handle, &still_running); |
| 88 |
|
| 89 |
if(mc == CURLM_OK ) { |
| 90 |
/* wait for activity, timeout or "nothing" */ |
| 91 |
mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds); |
| 92 |
} |
| 93 |
|
| 94 |
if(mc != CURLM_OK) { |
| 95 |
fprintf(stderr, "curl_multi failed, code %d.\\n", mc); |
| 96 |
break; |
| 97 |
} |
| 98 |
|
| 99 |
/* 'numfds' being zero means either a timeout or no file descriptors to |
| 100 |
wait for. Try timeout on first occurrence, then assume no file |
| 101 |
descriptors and no file descriptors to wait for means wait for 100 |
| 102 |
milliseconds. */ |
| 103 |
|
| 104 |
if(!numfds) { |
| 105 |
repeats++; /* count number of repeated zero numfds */ |
| 106 |
if(repeats > 1) { |
| 107 |
WAITMS(100); /* sleep 100 milliseconds */ |
| 108 |
} |
| 109 |
} |
| 110 |
else |
| 111 |
repeats = 0; |
| 112 |
|
| 113 |
} while(still_running); |
| 114 |
|
| 115 |
curl_multi_remove_handle(multi_handle, easy_handle); |
| 116 |
.fi |
| 117 |
.SH RETURN VALUE |
| 118 |
CURLMcode type, general libcurl multi interface error code. See |
| 119 |
\fIlibcurl-errors(3)\fP |
| 120 |
.SH AVAILABILITY |
| 121 |
This function was added in libcurl 7.28.0. |
| 122 |
.SH "SEE ALSO" |
| 123 |
.BR curl_multi_fdset "(3), " curl_multi_perform "(3)", curl_multi_poll "(3) ", |