{"thread":{"id":"9158","subject":"[PATCH 2/4] Make function to refill http queue a callback","startedAt":"2007-07-22T22:09:22Z","lastAt":"2007-07-22T22:09:22Z","messageCount":1,"participants":["Daniel Barkalow"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"48211","messageId":"Pine.LNX.4.64.0707221808540.29679@iabervon.org","threadId":"9158","inReplyTo":null,"subject":"[PATCH 2/4] Make function to refill http queue a callback","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2007-07-22T22:09:22Z","receivedAt":"2007-07-22T22:09:22Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This eliminates the last function provided by the code using http.h as\na global symbol, so it should be possible to have multiple programs\nusing http.h in the same executable, and it also adds an argument to\nthat callback, so that info can be passed into the callback without\nbeing global.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n http-fetch.c |    6 +++++-\n http-push.c  |    3 ++-\n http.c       |   30 ++++++++++++++++++++++++++++--\n http.h       |    4 +---\n 4 files changed, 36 insertions(+), 7 deletions(-)\n\ndiff --git a/http-fetch.c b/http-fetch.c\nindex e9b9f30..7786110 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -317,7 +317,7 @@ static void release_object_request(struct object_request *obj_req)\n }\n \n #ifdef USE_CURL_MULTI\n-int fill_active_slot(void)\n+static int fill_active_slot(void *unused)\n {\n \tstruct object_request *obj_req;\n \n@@ -1035,6 +1035,10 @@ int main(int argc, const char **argv)\n \talt->packs = NULL;\n \talt->next = NULL;\n \n+#ifdef USE_CURL_MULTI\n+\tadd_fill_function(NULL, fill_active_slot);\n+#endif\n+\n \tif (pull(commits, commit_id, write_ref, url))\n \t\trc = 1;\n \ndiff --git a/http-push.c b/http-push.c\nindex c7471fa..c54230b 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -795,7 +795,7 @@ static void finish_request(struct transfer_request *request)\n }\n \n #ifdef USE_CURL_MULTI\n-int fill_active_slot(void)\n+static int fill_active_slot(void *unused)\n {\n \tstruct transfer_request *request = request_queue_head;\n \n@@ -2496,6 +2496,7 @@ int main(int argc, char **argv)\n \t\t\t\tobjects_to_send);\n #ifdef USE_CURL_MULTI\n \t\tfill_active_slots();\n+\t\tadd_fill_function(NULL, fill_active_slot);\n #endif\n \t\tfinish_all_active_slots();\n \ndiff --git a/http.c b/http.c\nindex 1f305bd..a95483b 100644\n--- a/http.c\n+++ b/http.c\n@@ -391,13 +391,39 @@ int start_active_slot(struct active_request_slot *slot)\n }\n \n #ifdef USE_CURL_MULTI\n+struct fill_chain {\n+\tvoid *data;\n+\tint (*fill)(void *);\n+\tstruct fill_chain *next;\n+};\n+\n+static struct fill_chain *fill_cfg = NULL;\n+\n+void add_fill_function(void *data, int (*fill)(void *))\n+{\n+\tstruct fill_chain *new = malloc(sizeof(*new));\n+\tstruct fill_chain **linkp = &fill_cfg;\n+\tnew->data = data;\n+\tnew->fill = fill;\n+\tnew->next = NULL;\n+\twhile (*linkp)\n+\t\tlinkp = &(*linkp)->next;\n+\t*linkp = new;\n+}\n+\n void fill_active_slots(void)\n {\n \tstruct active_request_slot *slot = active_queue_head;\n \n-\twhile (active_requests < max_requests)\n-\t\tif (!fill_active_slot())\n+\twhile (active_requests < max_requests) {\n+\t\tstruct fill_chain *fill;\n+\t\tfor (fill = fill_cfg; fill; fill = fill->next)\n+\t\t\tif (fill->fill(fill->data))\n+\t\t\t\tbreak;\n+\n+\t\tif (!fill)\n \t\t\tbreak;\n+\t}\n \n \twhile (slot != NULL) {\n \t\tif (!slot->in_use && slot->curl != NULL) {\ndiff --git a/http.h b/http.h\nindex 559105c..72abac2 100644\n--- a/http.h\n+++ b/http.h\n@@ -70,10 +70,8 @@ extern void release_active_slot(struct active_request_slot *slot);\n \n #ifdef USE_CURL_MULTI\n extern void fill_active_slots(void);\n+extern void add_fill_function(void *data, int (*fill)(void *));\n extern void step_active_slots(void);\n-\n-/* Provided by the program using http. */\n-extern int fill_active_slot(void);\n #endif\n \n extern void http_init(void);\n-- \n1.5.3.rc1.818.g84b7\n"}]}