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

Re: [PATCH 1/2] http.c: Use curl_multi_fdset to select on curl fds instead of just sleeping

From
Jeff King <peff@peff.net>
Date
Nov 2, 2011, 20:32 UTC
Message-ID
<20111102203221.GB5628@sigill.intra.peff.net>
In-Reply-To
<1320265288-12647-2-git-send-email-mika.fischer@zoopnet.de>
On Wed, Nov 02, 2011 at 09:21:27PM +0100, Mika Fischer wrote:
Show 29 quoted lines
> Instead of sleeping unconditionally for a 50ms, when no data can be read
> from the http connection(s), use curl_multi_fdset to obtain the actual
> file descriptors of the open connections and use them in the select call.
> This way, the 50ms sleep is interrupted when new data arrives.
> ---
>  http.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/http.c b/http.c
> index a4bc770..ae92318 100644
> --- a/http.c
> +++ b/http.c
> @@ -664,14 +664,14 @@ void run_active_slot(struct active_request_slot *slot)
>  		}
>  
>  		if (slot->in_use && !data_received) {
> -			max_fd = 0;
> +			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, &readfds, &writefds,
> -			       &excfds, &select_timeout);
> +			select(max_fd+1, &readfds, &writefds, &excfds, &select_timeout);
>  		}
>  	}
Do we still need to care about data_received?
My understanding was that the code was originally trying to do:
  1. Call curl, maybe get some data.
  2. If we got data, then ask curl against immediately for some data.
  3. Otherwise, sleep 50ms and then ask curl again.

But now that we are actually selecting on the proper descriptors, it should now be safe to just do:

  1. Call curl, maybe get some data.
  2. Call select, which will wake immediately if curl is going to get
     data.

At least that's my reading. I am working on unrelated patches that clean up the handling of data_received, but if it could go away altogether, that would be even simpler.

-Peff
Previous: Mika FischerNext: Jeff King
Message 3 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.