]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl_multi_poll.md: expand the example with an custom file descriptor
authorDaniel Stenberg <daniel@haxx.se>
Fri, 31 May 2024 12:42:45 +0000 (14:42 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 31 May 2024 22:24:55 +0000 (00:24 +0200)
Closes #13842

docs/libcurl/curl_multi_poll.md

index 360e14d8e8c92dd96265b359e3781ec0e1d46ce9..aea2baaad9b3a19ab3898edc42867e1199488ad6 100644 (file)
@@ -94,6 +94,7 @@ int main(void)
   CURL *easy_handle;
   CURLM *multi_handle;
   int still_running = 0;
+  int myfd; /* this is our own file descriptor */
 
   /* add the individual easy handle */
   curl_multi_add_handle(multi_handle, easy_handle);
@@ -105,8 +106,19 @@ int main(void)
     mc = curl_multi_perform(multi_handle, &still_running);
 
     if(mc == CURLM_OK) {
-      /* wait for activity or timeout */
-      mc = curl_multi_poll(multi_handle, NULL, 0, 1000, &numfds);
+      struct curl_waitfd myown;
+      myown.fd = myfd;
+      myown.events = CURL_WAIT_POLLIN; /* wait for input */
+      myown.revents = 0; /* clear it */
+
+      /* wait for activity on curl's descriptors or on our own,
+         or timeout */
+      mc = curl_multi_poll(multi_handle, &myown, 1, 1000, &numfds);
+
+      if(myown.revents) {
+        /* did our descriptor receive an event? */
+        handle_fd(myfd);
+      }
     }
 
     if(mc != CURLM_OK) {