Refactor http.h USE_CURL_MULTI fill_active_slots().
This removes all of the boilerplate and http-internal stuff from fill_active_slots() and makes it easy to turn into a callback. 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
45c1741235a1fbd54484fa1c67ea68569dcfa23e
4 files changed
+40
-39
http-fetch.c
+7
-16
@@ -317,30 +317,21 @@ static void release_object_request(struct object_request *obj_req)
317
}
318
319
#ifdef USE_CURL_MULTI
320
-void fill_active_slots(void)
320
+int fill_active_slot(void)
321
{
322
- struct object_request *obj_req = object_queue_head;
323
- struct active_request_slot *slot = active_queue_head;
324
- int num_transfers;
322
+ struct object_request *obj_req;
323
326
- while (active_requests < max_requests && obj_req != NULL) {
324
+ for (obj_req = object_queue_head; obj_req; obj_req = obj_req->next) {
325
if (obj_req->state == WAITING) {
326
if (has_sha1_file(obj_req->sha1))
327
obj_req->state = COMPLETE;
330
- else
328
+ else {
329
start_object_request(obj_req);
332
- curl_multi_perform(curlm, &num_transfers);
333
- }
334
- obj_req = obj_req->next;
335
- }
336
-
337
- while (slot != NULL) {
338
- if (!slot->in_use && slot->curl != NULL) {
339
- curl_easy_cleanup(slot->curl);
340
- slot->curl = NULL;
330
+ return 1;
331
+ }
332
}
342
- slot = slot->next;
333
}
334
+ return 0;
335
}
336
#endif
337
http-push.c
+6
-17
@@ -795,38 +795,27 @@ static void finish_request(struct transfer_request *request)
795
}
796
797
#ifdef USE_CURL_MULTI
798
-void fill_active_slots(void)
798
+int fill_active_slot(void)
799
{
800
struct transfer_request *request = request_queue_head;
801
- struct transfer_request *next;
802
- struct active_request_slot *slot = active_queue_head;
803
- int num_transfers;
801
802
if (aborted)
806
- return;
803
+ return 0;
804
808
- while (active_requests < max_requests && request != NULL) {
809
- next = request->next;
805
+ for (request = request_queue_head; request; request = request->next) {
806
if (request->state == NEED_FETCH) {
807
start_fetch_loose(request);
808
+ return 1;
809
} else if (pushing && request->state == NEED_PUSH) {
810
if (remote_dir_exists[request->obj->sha1[0]] == 1) {
811
start_put(request);
812
} else {
813
start_mkcol(request);
814
}
818
- curl_multi_perform(curlm, &num_transfers);
819
- }
820
- request = next;
821
- }
822
-
823
- while (slot != NULL) {
824
- if (!slot->in_use && slot->curl != NULL) {
825
- curl_easy_cleanup(slot->curl);
826
- slot->curl = NULL;
815
+ return 1;
816
}
828
- slot = slot->next;
817
}
818
+ return 0;
819
}
820
#endif
821
http.c
+24
@@ -372,6 +372,7 @@ int start_active_slot(struct active_request_slot *slot)
372
{
373
#ifdef USE_CURL_MULTI
374
CURLMcode curlm_result = curl_multi_add_handle(curlm, slot->curl);
375
+ int num_transfers;
376
377
if (curlm_result != CURLM_OK &&
378
curlm_result != CURLM_CALL_MULTI_PERFORM) {
@@ -379,11 +380,34 @@ int start_active_slot(struct active_request_slot *slot)
380
slot->in_use = 0;
381
return 0;
382
}
383
+
384
+ /*
385
+ * We know there must be something to do, since we just added
386
+ * something.
387
+ */
388
+ curl_multi_perform(curlm, &num_transfers);
389
#endif
390
return 1;
391
}
392
393
#ifdef USE_CURL_MULTI
394
+void fill_active_slots(void)
395
+{
396
+ struct active_request_slot *slot = active_queue_head;
397
+
398
+ while (active_requests < max_requests)
399
+ if (!fill_active_slot())
400
+ break;
401
+
402
+ while (slot != NULL) {
403
+ if (!slot->in_use && slot->curl != NULL) {
404
+ curl_easy_cleanup(slot->curl);
405
+ slot->curl = NULL;
406
+ }
407
+ slot = slot->next;
408
+ }
409
+}
410
+
411
void step_active_slots(void)
412
{
413
int num_transfers;
http.h
+3
-6
@@ -71,6 +71,9 @@ extern void release_active_slot(struct active_request_slot *slot);
71
#ifdef USE_CURL_MULTI
72
extern void fill_active_slots(void);
73
extern void step_active_slots(void);
74
+
75
+/* Provided by the program using http. */
76
+extern int fill_active_slot(void);
77
#endif
78
79
extern void http_init(void);
@@ -79,10 +82,6 @@ extern void http_cleanup(void);
82
extern int data_received;
83
extern int active_requests;
84
82
-#ifdef USE_CURL_MULTI
83
-extern int max_requests;
84
-extern CURLM *curlm;
85
-#endif
85
#ifndef NO_CURL_EASY_DUPHANDLE
86
extern CURL *curl_default;
87
#endif
@@ -103,6 +102,4 @@ extern long curl_low_speed_time;
102
extern struct curl_slist *pragma_header;
103
extern struct curl_slist *no_range_header;
104
106
-extern struct active_request_slot *active_queue_head;
107
-
105
#endif /* HTTP_H */