All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Hengeveld <nickh@reactrix.com>
To: git@vger.kernel.org
Subject: [PATCH] Only compile parallel HTTP support with CURL >= 7.9.8
Date: Thu, 6 Oct 2005 17:04:06 -0700	[thread overview]
Message-ID: <20051007000406.GI15593@reactrix.com> (raw)

Only compile parallel HTTP support with CURL >= 7.9.8

Signed-off-by: Nick Hengeveld <nickh@reactrix.com>


---

 http-fetch.c |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 57 insertions(+), 5 deletions(-)

2677e4eab199eb43f5e3a865e4008d3db79708a5
diff --git a/http-fetch.c b/http-fetch.c
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -6,7 +6,10 @@
 #include <curl/curl.h>
 #include <curl/easy.h>
 
+#if LIBCURL_VERSION_NUM >= 0x070908
+#define USE_CURL_MULTI
 #define DEFAULT_MAX_REQUESTS 5
+#endif
 
 #if LIBCURL_VERSION_NUM < 0x070704
 #define curl_global_cleanup() do { /* nothing */ } while(0)
@@ -18,11 +21,13 @@
 #define PREV_BUF_SIZE 4096
 #define RANGE_HEADER_SIZE 30
 
-static int max_requests = DEFAULT_MAX_REQUESTS;
 static int active_requests = 0;
 static int data_received;
 
+#ifdef USE_CURL_MULTI
+static int max_requests = DEFAULT_MAX_REQUESTS;
 static CURLM *curlm;
+#endif
 static CURL *curl_default;
 static struct curl_slist *no_pragma_header;
 static struct curl_slist *no_range_header;
@@ -151,13 +156,17 @@ int relink_or_rename(char *old, char *ne
 	return 0;
 }
 
+#ifdef USE_CURL_MULTI
 void process_curl_messages();
 void process_request_queue();
+#endif
 
 struct active_request_slot *get_active_slot()
 {
 	struct active_request_slot *slot = active_queue_head;
 	struct active_request_slot *newslot;
+
+#ifdef USE_CURL_MULTI
 	int num_transfers;
 
 	/* Wait for a slot to open up if the queue is full */
@@ -167,6 +176,7 @@ struct active_request_slot *get_active_s
 			process_curl_messages();
 		}
 	}
+#endif
 
 	while (slot != NULL && slot->in_use) {
 		slot = slot->next;
@@ -202,6 +212,7 @@ struct active_request_slot *get_active_s
 
 int start_active_slot(struct active_request_slot *slot)
 {
+#ifdef USE_CURL_MULTI
 	CURLMcode curlm_result = curl_multi_add_handle(curlm, slot->curl);
 
 	if (curlm_result != CURLM_OK &&
@@ -210,12 +221,13 @@ int start_active_slot(struct active_requ
 		slot->in_use = 0;
 		return 0;
 	}
-
+#endif
 	return 1;
 }
 
 void run_active_slot(struct active_request_slot *slot)
 {
+#ifdef USE_CURL_MULTI
 	int num_transfers;
 	long last_pos = 0;
 	long current_pos;
@@ -255,6 +267,10 @@ void run_active_slot(struct active_reque
 			       &excfds, &select_timeout);
 		}
 	}
+#else
+	slot->curl_result = curl_easy_perform(slot->curl);
+	active_requests--;
+#endif
 }
 
 void start_request(struct transfer_request *request)
@@ -356,7 +372,7 @@ void start_request(struct transfer_reque
 				 CURLOPT_HTTPHEADER, range_header);
 	}
 
-	/* Try to add to multi handle, abort the request on error */
+	/* Try to get the request started, abort the request on error */
 	if (!start_active_slot(slot)) {
 		request->state = ABORTED;
 		close(request->local);
@@ -413,6 +429,7 @@ void release_request(struct transfer_req
 	free(request);
 }
 
+#ifdef USE_CURL_MULTI
 void process_curl_messages()
 {
 	int num_messages;
@@ -478,6 +495,7 @@ void process_request_queue()
 		request = request->next;
 	}
 }
+#endif
 
 void prefetch(unsigned char *sha1)
 {
@@ -505,8 +523,10 @@ void prefetch(unsigned char *sha1)
 		}
 		tail->next = newreq;
 	}
+#ifdef USE_CURL_MULTI
 	process_request_queue();
 	process_curl_messages();
+#endif
 }
 
 static int got_alternates = 0;
@@ -864,13 +884,14 @@ static int fetch_object(struct alt_base 
 	char *hex = sha1_to_hex(sha1);
 	int ret;
 	struct transfer_request *request = request_queue_head;
-	int num_transfers;
 
 	while (request != NULL && memcmp(request->sha1, sha1, 20))
 		request = request->next;
 	if (request == NULL)
 		return error("Couldn't find request for %s in the queue", hex);
 
+#ifdef USE_CURL_MULTI
+	int num_transfers;
 	while (request->state == WAITING) {
 		curl_multi_perform(curlm, &num_transfers);
 		if (num_transfers < active_requests) {
@@ -878,9 +899,30 @@ static int fetch_object(struct alt_base 
 			process_request_queue();
 		}
 	}
+#else
+	start_request(request);
+#endif
 
-	if (request->state == ACTIVE)
+	while (request->state == ACTIVE) {
 		run_active_slot(request->slot);
+#ifndef USE_CURL_MULTI
+		request->curl_result = request->slot->curl_result;
+		curl_easy_getinfo(request->slot->curl,
+				  CURLINFO_HTTP_CODE,
+				  &request->http_code);
+		request->slot = NULL;
+
+		/* Use alternates if necessary */
+		if (request->http_code == 404 &&
+		    request->repo->next != NULL) {
+			request->repo = request->repo->next;
+			start_request(request);
+		} else {
+			finish_request(request);
+			request->state = COMPLETE;
+		}
+#endif
+	}
 
 	if (request->state == ABORTED) {
 		release_request(request);
@@ -992,16 +1034,22 @@ int main(int argc, char **argv)
 			arg++;
 		} else if (!strcmp(argv[arg], "--recover")) {
 			get_recover = 1;
+#ifdef USE_CURL_MULTI
 		} else if (argv[arg][1] == 'r') {
 			max_requests = atoi(argv[arg + 1]);
 			if (max_requests < 1)
 				max_requests = DEFAULT_MAX_REQUESTS;
 			arg++;
+#endif
 		}
 		arg++;
 	}
 	if (argc < arg + 2) {
+#ifdef USE_CURL_MULTI
+		usage("git-http-fetch [-c] [-t] [-a] [-d] [-v] [-r concurrent-request-limit] [--recover] [-w ref] commit-id url");
+#else
 		usage("git-http-fetch [-c] [-t] [-a] [-d] [-v] [--recover] [-w ref] commit-id url");
+#endif
 		return 1;
 	}
 	commit_id = argv[arg];
@@ -1009,11 +1057,13 @@ int main(int argc, char **argv)
 
 	curl_global_init(CURL_GLOBAL_ALL);
 
+#ifdef USE_CURL_MULTI
 	curlm = curl_multi_init();
 	if (curlm == NULL) {
 		fprintf(stderr, "Error creating curl multi handle.\n");
 		return 1;
 	}
+#endif
 	no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
 	no_range_header = curl_slist_append(no_range_header, "Range:");
 
@@ -1061,7 +1111,9 @@ int main(int argc, char **argv)
 		curl_easy_cleanup(slot->curl);
 		slot = slot->next;
 	}
+#ifdef USE_CURL_MULTI
 	curl_multi_cleanup(curlm);
+#endif
 	curl_global_cleanup();
 	return 0;
 }

                 reply	other threads:[~2005-10-07  0:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051007000406.GI15593@reactrix.com \
    --to=nickh@reactrix.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.