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>
This commit is contained in:
parent
077d6f72c7
commit
45c1741235
21
http-fetch.c
21
http-fetch.c
@ -317,30 +317,21 @@ static void release_object_request(struct object_request *obj_req)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_CURL_MULTI
|
#ifdef USE_CURL_MULTI
|
||||||
void fill_active_slots(void)
|
int fill_active_slot(void)
|
||||||
{
|
{
|
||||||
struct object_request *obj_req = object_queue_head;
|
struct object_request *obj_req;
|
||||||
struct active_request_slot *slot = active_queue_head;
|
|
||||||
int num_transfers;
|
|
||||||
|
|
||||||
while (active_requests < max_requests && obj_req != NULL) {
|
for (obj_req = object_queue_head; obj_req; obj_req = obj_req->next) {
|
||||||
if (obj_req->state == WAITING) {
|
if (obj_req->state == WAITING) {
|
||||||
if (has_sha1_file(obj_req->sha1))
|
if (has_sha1_file(obj_req->sha1))
|
||||||
obj_req->state = COMPLETE;
|
obj_req->state = COMPLETE;
|
||||||
else
|
else {
|
||||||
start_object_request(obj_req);
|
start_object_request(obj_req);
|
||||||
curl_multi_perform(curlm, &num_transfers);
|
return 1;
|
||||||
}
|
}
|
||||||
obj_req = obj_req->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (slot != NULL) {
|
|
||||||
if (!slot->in_use && slot->curl != NULL) {
|
|
||||||
curl_easy_cleanup(slot->curl);
|
|
||||||
slot->curl = NULL;
|
|
||||||
}
|
|
||||||
slot = slot->next;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
23
http-push.c
23
http-push.c
@ -795,38 +795,27 @@ static void finish_request(struct transfer_request *request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_CURL_MULTI
|
#ifdef USE_CURL_MULTI
|
||||||
void fill_active_slots(void)
|
int fill_active_slot(void)
|
||||||
{
|
{
|
||||||
struct transfer_request *request = request_queue_head;
|
struct transfer_request *request = request_queue_head;
|
||||||
struct transfer_request *next;
|
|
||||||
struct active_request_slot *slot = active_queue_head;
|
|
||||||
int num_transfers;
|
|
||||||
|
|
||||||
if (aborted)
|
if (aborted)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
while (active_requests < max_requests && request != NULL) {
|
for (request = request_queue_head; request; request = request->next) {
|
||||||
next = request->next;
|
|
||||||
if (request->state == NEED_FETCH) {
|
if (request->state == NEED_FETCH) {
|
||||||
start_fetch_loose(request);
|
start_fetch_loose(request);
|
||||||
|
return 1;
|
||||||
} else if (pushing && request->state == NEED_PUSH) {
|
} else if (pushing && request->state == NEED_PUSH) {
|
||||||
if (remote_dir_exists[request->obj->sha1[0]] == 1) {
|
if (remote_dir_exists[request->obj->sha1[0]] == 1) {
|
||||||
start_put(request);
|
start_put(request);
|
||||||
} else {
|
} else {
|
||||||
start_mkcol(request);
|
start_mkcol(request);
|
||||||
}
|
}
|
||||||
curl_multi_perform(curlm, &num_transfers);
|
return 1;
|
||||||
}
|
}
|
||||||
request = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (slot != NULL) {
|
|
||||||
if (!slot->in_use && slot->curl != NULL) {
|
|
||||||
curl_easy_cleanup(slot->curl);
|
|
||||||
slot->curl = NULL;
|
|
||||||
}
|
|
||||||
slot = slot->next;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
24
http.c
24
http.c
@ -372,6 +372,7 @@ int start_active_slot(struct active_request_slot *slot)
|
|||||||
{
|
{
|
||||||
#ifdef USE_CURL_MULTI
|
#ifdef USE_CURL_MULTI
|
||||||
CURLMcode curlm_result = curl_multi_add_handle(curlm, slot->curl);
|
CURLMcode curlm_result = curl_multi_add_handle(curlm, slot->curl);
|
||||||
|
int num_transfers;
|
||||||
|
|
||||||
if (curlm_result != CURLM_OK &&
|
if (curlm_result != CURLM_OK &&
|
||||||
curlm_result != CURLM_CALL_MULTI_PERFORM) {
|
curlm_result != CURLM_CALL_MULTI_PERFORM) {
|
||||||
@ -379,11 +380,34 @@ int start_active_slot(struct active_request_slot *slot)
|
|||||||
slot->in_use = 0;
|
slot->in_use = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We know there must be something to do, since we just added
|
||||||
|
* something.
|
||||||
|
*/
|
||||||
|
curl_multi_perform(curlm, &num_transfers);
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_CURL_MULTI
|
#ifdef USE_CURL_MULTI
|
||||||
|
void fill_active_slots(void)
|
||||||
|
{
|
||||||
|
struct active_request_slot *slot = active_queue_head;
|
||||||
|
|
||||||
|
while (active_requests < max_requests)
|
||||||
|
if (!fill_active_slot())
|
||||||
|
break;
|
||||||
|
|
||||||
|
while (slot != NULL) {
|
||||||
|
if (!slot->in_use && slot->curl != NULL) {
|
||||||
|
curl_easy_cleanup(slot->curl);
|
||||||
|
slot->curl = NULL;
|
||||||
|
}
|
||||||
|
slot = slot->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void step_active_slots(void)
|
void step_active_slots(void)
|
||||||
{
|
{
|
||||||
int num_transfers;
|
int num_transfers;
|
||||||
|
9
http.h
9
http.h
@ -71,6 +71,9 @@ extern void release_active_slot(struct active_request_slot *slot);
|
|||||||
#ifdef USE_CURL_MULTI
|
#ifdef USE_CURL_MULTI
|
||||||
extern void fill_active_slots(void);
|
extern void fill_active_slots(void);
|
||||||
extern void step_active_slots(void);
|
extern void step_active_slots(void);
|
||||||
|
|
||||||
|
/* Provided by the program using http. */
|
||||||
|
extern int fill_active_slot(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void http_init(void);
|
extern void http_init(void);
|
||||||
@ -79,10 +82,6 @@ extern void http_cleanup(void);
|
|||||||
extern int data_received;
|
extern int data_received;
|
||||||
extern int active_requests;
|
extern int active_requests;
|
||||||
|
|
||||||
#ifdef USE_CURL_MULTI
|
|
||||||
extern int max_requests;
|
|
||||||
extern CURLM *curlm;
|
|
||||||
#endif
|
|
||||||
#ifndef NO_CURL_EASY_DUPHANDLE
|
#ifndef NO_CURL_EASY_DUPHANDLE
|
||||||
extern CURL *curl_default;
|
extern CURL *curl_default;
|
||||||
#endif
|
#endif
|
||||||
@ -103,6 +102,4 @@ extern long curl_low_speed_time;
|
|||||||
extern struct curl_slist *pragma_header;
|
extern struct curl_slist *pragma_header;
|
||||||
extern struct curl_slist *no_range_header;
|
extern struct curl_slist *no_range_header;
|
||||||
|
|
||||||
extern struct active_request_slot *active_queue_head;
|
|
||||||
|
|
||||||
#endif /* HTTP_H */
|
#endif /* HTTP_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user