From b7d3338df2843a064747d8928b0a9e8a2200e38d Mon Sep 17 00:00:00 2001
From: Waldek Kozba <100assc@gmail.com>
Date: Tue, 7 Oct 2014 09:59:59 +0200
Subject: [PATCH] multi-uv.c: call curl_multi_info_read() better

Improves it for low-latency cases (like the communication with
localhost)
---
 docs/examples/multi-uv.c | 45 +++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/docs/examples/multi-uv.c b/docs/examples/multi-uv.c
index 57d712fcfa..f91eb01c94 100644
--- a/docs/examples/multi-uv.c
+++ b/docs/examples/multi-uv.c
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2014, 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
@@ -95,6 +95,31 @@ void add_download(const char *url, int num)
   fprintf(stderr, "Added download %s -> %s\n", url, filename);
 }
 
+static void check_multi_info(void)
+{
+  int running_handles;
+  char *done_url;
+  CURLMsg *message;
+  int pending;
+
+  while ((message = curl_multi_info_read(curl_handle, &pending))) {
+    switch (message->msg) {
+    case CURLMSG_DONE:
+      curl_easy_getinfo(message->easy_handle, CURLINFO_EFFECTIVE_URL,
+                        &done_url);
+      printf("%s DONE\n", done_url);
+
+      curl_multi_remove_handle(curl_handle, message->easy_handle);
+      curl_easy_cleanup(message->easy_handle);
+      break;
+
+    default:
+      fprintf(stderr, "CURLMSG default\n");
+      break;
+    }
+  }
+}
+
 void curl_perform(uv_poll_t *req, int status, int events)
 {
   int running_handles;
@@ -116,22 +141,7 @@ void curl_perform(uv_poll_t *req, int status, int events)
   curl_multi_socket_action(curl_handle, context->sockfd, flags,
                            &running_handles);
 
-  while ((message = curl_multi_info_read(curl_handle, &pending))) {
-    switch (message->msg) {
-    case CURLMSG_DONE:
-      curl_easy_getinfo(message->easy_handle, CURLINFO_EFFECTIVE_URL,
-                        &done_url);
-      printf("%s DONE\n", done_url);
-
-      curl_multi_remove_handle(curl_handle, message->easy_handle);
-      curl_easy_cleanup(message->easy_handle);
-
-      break;
-    default:
-      fprintf(stderr, "CURLMSG default\n");
-      abort();
-    }
-  }
+  check_multi_info();
 }
 
 void on_timeout(uv_timer_t *req, int status)
@@ -139,6 +149,7 @@ void on_timeout(uv_timer_t *req, int status)
   int running_handles;
   curl_multi_socket_action(curl_handle, CURL_SOCKET_TIMEOUT, 0,
                            &running_handles);
+  check_multi_info();
 }
 
 void start_timeout(CURLM *multi, long timeout_ms, void *userp)
-- 
GitLab