Fix HTTP request result processing after slot reuse
Add a way to store the results of an HTTP request when a slot finishes so the results can be processed after the slot has been reused. Signed-off-by: Nick Hengeveld <nickh@reactrix.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nick Hengeveld committed
Jan 31, 2006 at 11:06 UTC
c8568e139ed2149fbfb7ef9a8d819d5b6b7c554f
3 files changed
+29
-7
http-fetch.c
+14
-6
@@ -375,6 +375,7 @@ static int fetch_index(struct alt_base *repo, unsigned char *sha1)
375
376
FILE *indexfile;
377
struct active_request_slot *slot;
378
+ static struct slot_results results;
379
380
if (has_pack_index(sha1))
381
return 0;
@@ -393,6 +394,7 @@ static int fetch_index(struct alt_base *repo, unsigned char *sha1)
394
filename);
395
396
slot = get_active_slot();
397
+ slot->results = &results;
398
curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);
399
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
400
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -414,7 +416,7 @@ static int fetch_index(struct alt_base *repo, unsigned char *sha1)
416
417
if (start_active_slot(slot)) {
418
run_active_slot(slot);
417
- if (slot->curl_result != CURLE_OK) {
419
+ if (results.curl_result != CURLE_OK) {
420
fclose(indexfile);
421
return error("Unable to get pack index %s\n%s", url,
422
curl_errorstr);
@@ -616,6 +618,7 @@ static int fetch_indices(struct alt_base *repo)
618
int i = 0;
619
620
struct active_request_slot *slot;
621
+ static struct slot_results results;
622
623
if (repo->got_indices)
624
return 0;
@@ -632,15 +635,16 @@ static int fetch_indices(struct alt_base *repo)
635
sprintf(url, "%s/objects/info/packs", repo->base);
636
637
slot = get_active_slot();
638
+ slot->results = &results;
639
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
640
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
641
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
642
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
643
if (start_active_slot(slot)) {
644
run_active_slot(slot);
641
- if (slot->curl_result != CURLE_OK) {
642
- if (slot->http_code == 404 ||
643
- slot->curl_result == CURLE_FILE_COULDNT_READ_FILE) {
645
+ if (results.curl_result != CURLE_OK) {
646
+ if (results.http_code == 404 ||
647
+ results.curl_result == CURLE_FILE_COULDNT_READ_FILE) {
648
repo->got_indices = 1;
649
free(buffer.buffer);
650
return 0;
@@ -695,6 +699,7 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
699
struct curl_slist *range_header = NULL;
700
701
struct active_request_slot *slot;
702
+ static struct slot_results results;
703
704
if (fetch_indices(repo))
705
return -1;
@@ -721,6 +726,7 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
726
filename);
727
728
slot = get_active_slot();
729
+ slot->results = &results;
730
curl_easy_setopt(slot->curl, CURLOPT_FILE, packfile);
731
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
732
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -742,7 +748,7 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
748
749
if (start_active_slot(slot)) {
750
run_active_slot(slot);
745
- if (slot->curl_result != CURLE_OK) {
751
+ if (results.curl_result != CURLE_OK) {
752
fclose(packfile);
753
return error("Unable to get pack file %s\n%s", url,
754
curl_errorstr);
@@ -894,6 +900,7 @@ int fetch_ref(char *ref, unsigned char *sha1)
900
struct buffer buffer;
901
char *base = alt->base;
902
struct active_request_slot *slot;
903
+ static struct slot_results results;
904
buffer.size = 41;
905
buffer.posn = 0;
906
buffer.buffer = hex;
@@ -901,13 +908,14 @@ int fetch_ref(char *ref, unsigned char *sha1)
908
909
url = quote_ref_url(base, ref);
910
slot = get_active_slot();
911
+ slot->results = &results;
912
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
913
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
914
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
915
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
916
if (start_active_slot(slot)) {
917
run_active_slot(slot);
910
- if (slot->curl_result != CURLE_OK)
918
+ if (results.curl_result != CURLE_OK)
919
return error("Couldn't get %s for %s\n%s",
920
url, ref, curl_errorstr);
921
} else {
http.c
+8
-1
@@ -335,6 +335,7 @@ struct active_request_slot *get_active_slot(void)
335
active_requests++;
336
slot->in_use = 1;
337
slot->local = NULL;
338
+ slot->results = NULL;
339
slot->callback_data = NULL;
340
slot->callback_func = NULL;
341
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header);
@@ -421,7 +422,13 @@ static void finish_active_slot(struct active_request_slot *slot)
422
active_requests--;
423
slot->in_use = 0;
424
curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code);
424
-
425
+
426
+ /* Store slot results so they can be read after the slot is reused */
427
+ if (slot->results != NULL) {
428
+ slot->results->curl_result = slot->curl_result;
429
+ slot->results->http_code = slot->http_code;
430
+ }
431
+
432
/* Run callback if appropriate */
433
if (slot->callback_func != NULL) {
434
slot->callback_func(slot->callback_data);
http.h
+7
@@ -22,6 +22,12 @@
22
#define NO_CURL_EASY_DUPHANDLE
23
#endif
24
25
+struct slot_results
26
+{
27
+ CURLcode curl_result;
28
+ long http_code;
29
+};
30
+
31
struct active_request_slot
32
{
33
CURL *curl;
@@ -29,6 +35,7 @@ struct active_request_slot
35
int in_use;
36
CURLcode curl_result;
37
long http_code;
38
+ struct slot_results *results;
39
void *callback_data;
40
void (*callback_func)(void *data);
41
struct active_request_slot *next;