aboutsummaryrefslogtreecommitdiff
path: root/docs/libcurl/curl_multi_wait.3
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2016-03-09 08:35:17 +0100
committerDaniel Stenberg <daniel@haxx.se>2016-03-09 08:35:17 +0100
commitb7f3fe125a53fdf20ba20276626a8d26b5941742 (patch)
tree96d57b324a7a543b3227df81e7a007f0b91cc9e0 /docs/libcurl/curl_multi_wait.3
parenta5aec58726beae3926bcbe2fed83953ea3cd636e (diff)
curl_multi_wait.3: add example
Diffstat (limited to 'docs/libcurl/curl_multi_wait.3')
-rw-r--r--docs/libcurl/curl_multi_wait.344
1 files changed, 43 insertions, 1 deletions
diff --git a/docs/libcurl/curl_multi_wait.3 b/docs/libcurl/curl_multi_wait.3
index 593e4b371..9f15c5f89 100644
--- a/docs/libcurl/curl_multi_wait.3
+++ b/docs/libcurl/curl_multi_wait.3
@@ -5,7 +5,7 @@
.\" * | (__| |_| | _ <| |___
.\" * \___|\___/|_| \_\_____|
.\" *
-.\" * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2016, 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
@@ -71,6 +71,48 @@ priority read events such as out of band data.
.IP CURL_WAIT_POLLOUT
Bit flag to curl_waitfd.events indicating the socket should poll on write
events such as the socket being clear to write without blocking.
+.SH EXAMPLE
+.nf
+CURL *easy_handle;
+CURLM *multi_handle;
+
+/* add the individual easy handle */
+curl_multi_add_handle(multi_handle, easy_handle);
+
+do {
+ CURLMcode mc;
+ int numfds;
+
+ mc = curl_multi_perform(multi_handle, &still_running);
+
+ if(mc == CURLM_OK ) {
+ /* wait for activity, timeout or "nothing" */
+ mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
+ }
+
+ if(mc != CURLM_OK) {
+ fprintf(stderr, "curl_multi failed, code %d.\n", mc);
+ break;
+ }
+
+ /* 'numfds' being zero means either a timeout or no file descriptors to
+ wait for. Try timeout on first occurrence, then assume no file
+ descriptors and no file descriptors to wait for means wait for 100
+ milliseconds. */
+
+ if(!numfds) {
+ repeats++; /* count number of repeated zero numfds */
+ if(repeats > 1) {
+ WAITMS(100); /* sleep 100 milliseconds */
+ }
+ }
+ else
+ repeats = 0;
+
+} while(still_running);
+
+curl_multi_remove_handle(multi_handle, easy_handle);
+.fi
.SH RETURN VALUE
CURLMcode type, general libcurl multi interface error code. See
\fIlibcurl-errors(3)\fP