Make function to refill http queue a callback
This eliminates the last function provided by the code using http.h as a global symbol, so it should be possible to have multiple programs using http.h in the same executable, and it also adds an argument to that callback, so that info can be passed into the callback without being global. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Daniel Barkalow committed
Sep 10, 2007 at 23:02 UTC
fc57b6aaa5bc59ecbe0c052b98196a93b35760a5
4 files changed
+36
-7
http-fetch.c
+5
-1
@@ -317,7 +317,7 @@ static void release_object_request(struct object_request *obj_req)
317
}
318
319
#ifdef USE_CURL_MULTI
320
-int fill_active_slot(void)
320
+static int fill_active_slot(void *unused)
321
{
322
struct object_request *obj_req;
323
@@ -1035,6 +1035,10 @@ int main(int argc, const char **argv)
1035
alt->packs = NULL;
1036
alt->next = NULL;
1037
1038
+#ifdef USE_CURL_MULTI
1039
+ add_fill_function(NULL, fill_active_slot);
1040
+#endif
1041
+
1042
if (pull(commits, commit_id, write_ref, url))
1043
rc = 1;
1044
http-push.c
+2
-1
@@ -795,7 +795,7 @@ static void finish_request(struct transfer_request *request)
795
}
796
797
#ifdef USE_CURL_MULTI
798
-int fill_active_slot(void)
798
+static int fill_active_slot(void *unused)
799
{
800
struct transfer_request *request = request_queue_head;
801
@@ -2496,6 +2496,7 @@ int main(int argc, char **argv)
2496
objects_to_send);
2497
#ifdef USE_CURL_MULTI
2498
fill_active_slots();
2499
+ add_fill_function(NULL, fill_active_slot);
2500
#endif
2501
finish_all_active_slots();
2502
http.c
+28
-2
@@ -391,13 +391,39 @@ int start_active_slot(struct active_request_slot *slot)
391
}
392
393
#ifdef USE_CURL_MULTI
394
+struct fill_chain {
395
+ void *data;
396
+ int (*fill)(void *);
397
+ struct fill_chain *next;
398
+};
399
+
400
+static struct fill_chain *fill_cfg = NULL;
401
+
402
+void add_fill_function(void *data, int (*fill)(void *))
403
+{
404
+ struct fill_chain *new = malloc(sizeof(*new));
405
+ struct fill_chain **linkp = &fill_cfg;
406
+ new->data = data;
407
+ new->fill = fill;
408
+ new->next = NULL;
409
+ while (*linkp)
410
+ linkp = &(*linkp)->next;
411
+ *linkp = new;
412
+}
413
+
414
void fill_active_slots(void)
415
{
416
struct active_request_slot *slot = active_queue_head;
417
398
- while (active_requests < max_requests)
399
- if (!fill_active_slot())
418
+ while (active_requests < max_requests) {
419
+ struct fill_chain *fill;
420
+ for (fill = fill_cfg; fill; fill = fill->next)
421
+ if (fill->fill(fill->data))
422
+ break;
423
+
424
+ if (!fill)
425
break;
426
+ }
427
428
while (slot != NULL) {
429
if (!slot->in_use && slot->curl != NULL) {
http.h
+1
-3
@@ -70,10 +70,8 @@ extern void release_active_slot(struct active_request_slot *slot);
70
71
#ifdef USE_CURL_MULTI
72
extern void fill_active_slots(void);
73
+extern void add_fill_function(void *data, int (*fill)(void *));
74
extern void step_active_slots(void);
74
-
75
-/* Provided by the program using http. */
76
-extern int fill_active_slot(void);
75
#endif
76
77
extern void http_init(void);