git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] http.c: Use timeout suggested by curl instead of fixed 50ms timeout

From
Mika Fischer <mika.fischer@zoopnet.de>
Date
Nov 2, 2011, 20:21 UTC
Message-ID
<1320265288-12647-3-git-send-email-mika.fischer@zoopnet.de>
In-Reply-To
<1320265288-12647-1-git-send-email-mika.fischer@zoopnet.de>
Recent versions of curl can suggest a period of time the library user
should sleep and try again, when curl is blocked on reading or writing
(or connecting). Use this timeout instead of always sleeping for 50ms.
---
 http.c |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/http.c b/http.c
index ae92318..e91a2ab 100644
--- a/http.c
+++ b/http.c
@@ -649,6 +649,9 @@ void run_active_slot(struct active_request_slot *slot)
 	fd_set excfds;
 	int max_fd;
 	struct timeval select_timeout;
+#if LIBCURL_VERSION_NUM >= 0x070f04
+	long curl_timeout;
+#endif
 	int finished = 0;
 
 	slot->finished = &finished;
@@ -664,13 +667,28 @@ void run_active_slot(struct active_request_slot *slot)
 		}
 
 		if (slot->in_use && !data_received) {
+#if LIBCURL_VERSION_NUM >= 0x070f04
+			curl_multi_timeout(curlm, &curl_timeout);
+			if (curl_timeout == 0) {
+				continue;
+			} else if (curl_timeout == -1) {
+				select_timeout.tv_sec  = 0;
+				select_timeout.tv_usec = 50000;
+			} else {
+				select_timeout.tv_sec  =  curl_timeout / 1000;
+				select_timeout.tv_usec = (curl_timeout % 1000) * 1000;
+			}
+#else
+			select_timeout.tv_sec  = 0;
+			select_timeout.tv_usec = 50000;
+#endif
+
 			max_fd = -1;
 			FD_ZERO(&readfds);
 			FD_ZERO(&writefds);
 			FD_ZERO(&excfds);
 			curl_multi_fdset(curlm, &readfds, &writefds, &excfds, &max_fd);
-			select_timeout.tv_sec = 0;
-			select_timeout.tv_usec = 50000;
+
 			select(max_fd+1, &readfds, &writefds, &excfds, &select_timeout);
 		}
 	}
-- 
1.7.8.rc0.33.g09c6f.dirty
Previous: Daniel StenbergNext: Junio C Hamano
Message 8 of 19 in “[PATCHv2] Improve use of select in http backend”
  1. Mika FischerNov 2, 2011
  2. 1/2 http.c: Use curl_multi_fdset to select on curl fds instead of just sleepingMika Fischer, Nov 2, 2011
  3. Jeff KingNov 2, 2011
  4. Jeff KingNov 2, 2011
  5. Junio C HamanoNov 2, 2011
  6. Mika FischerNov 2, 2011
  7. Daniel StenbergNov 2, 2011
  8. 2/2 http.c: Use timeout suggested by curl instead of fixed 50ms timeoutMika Fischer, Nov 2, 2011
  9. Junio C HamanoNov 3, 2011
  10. 0/3 Improve use of select in http backendMika Fischer, Nov 4, 2011
  11. 1/3 http.c: Use curl_multi_fdset to select on curl fds instead of just sleepingMika Fischer, Nov 4, 2011
  12. 2/3 http.c: Use timeout suggested by curl instead of fixed 50ms timeoutMika Fischer, Nov 4, 2011
  13. Junio C HamanoNov 4, 2011
  14. Mika FischerNov 4, 2011
  15. Jeff KingNov 4, 2011
  16. Mika FischerNov 4, 2011
  17. Junio C HamanoNov 4, 2011
  18. 3/3 http.c: Rely on select instead of tracking whether data was receivedMika Fischer, Nov 4, 2011
  19. Jeff KingNov 4, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.